From patchwork Tue Feb 21 14:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1745693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=WqkJ/P46; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=hiLcazTt; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PLhpt5yFfz245n for ; Wed, 22 Feb 2023 01:42:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D894F385B537 for ; Tue, 21 Feb 2023 14:42:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D68263858D32 for ; Tue, 21 Feb 2023 14:42:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D68263858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9719634B3E; Tue, 21 Feb 2023 14:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676990561; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=COAVFI5z46w9Zf0Ei1imKNs0l0Zx3X9EFd2ksjghEyU=; b=WqkJ/P46vNPEgWJWjXDCO+eWJZfydUNDq8QRNrXvkjXP8pSE2ax9Y345BPO0Zbr7gWrnCT /WLjx7a1ETu5ARhKn79ocHK9OlLDodNFvEECGyIn2P/utjjGHU/itdU5T1deFRvbqTqAGo iX3dYgdrvRIgxPSNBxr5qFOsYtz6mKM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676990561; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=COAVFI5z46w9Zf0Ei1imKNs0l0Zx3X9EFd2ksjghEyU=; b=hiLcazTtCyglqI8DcxBkaQy+jsXSzZVlEPHxLAxvYNn43ZA0PfxD61o3VWtsOCIUNDbfJA oou/UNe4l3iYJ2DQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8A64E13223; Tue, 21 Feb 2023 14:42:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fm6+IWHY9GP7WQAAMHmgww (envelope-from ); Tue, 21 Feb 2023 14:42:41 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 1/2] ipa-cp: Fix various issues in update_specialized_profile (PR 107925) User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Tue, 21 Feb 2023 15:42:41 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, the patch below fixes various issues in function update_specialized_profile. The main is removal of the assert which is bogus in the case of recursive cloning. The division of unexplained counts is guesswork, which then leads to updates of counts of recursive edges, which then can be redirected to the new clone and their count subtracted from the count and there simply may not be enough left in the count of the original node - especially when we clone a lot because of using --param ipa-cp-eval-threshold=1. The other issue was omission to drop the count of the original node to ipa count. And when calculating the remainder, we should use lenient_count_portion_handling to account for partial train runs. Finally, the patch adds dumping of the original count which I think is useful. Profiled-LTO-bootstrapped on its own and also normally bootstrapped and tested together with the subsequent patch on an x86_64-linux. OK for master and the 12 branch - assuming it is also affected? Thanks, Martin gcc/ChangeLog: 2023-02-17 Martin Jambor PR ipa/107925 * ipa-cp.cc (update_specialized_profile): Drop orig_node_count to ipa count, remove assert, lenient_count_portion_handling, dump also orig_node_count. --- gcc/ipa-cp.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 4b8dedc0c51..5a6b41cf2d6 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -5093,22 +5093,24 @@ update_specialized_profile (struct cgraph_node *new_node, profile_count redirected_sum) { struct cgraph_edge *cs; - profile_count new_node_count, orig_node_count = orig_node->count; + profile_count new_node_count, orig_node_count = orig_node->count.ipa (); if (dump_file) { fprintf (dump_file, " the sum of counts of redirected edges is "); redirected_sum.dump (dump_file); + fprintf (dump_file, "\n old ipa count of the original node is "); + orig_node_count.dump (dump_file); fprintf (dump_file, "\n"); } if (!(orig_node_count > profile_count::zero ())) return; - gcc_assert (orig_node_count >= redirected_sum); - new_node_count = new_node->count; new_node->count += redirected_sum; - orig_node->count -= redirected_sum; + orig_node->count + = lenient_count_portion_handling (orig_node->count - redirected_sum, + orig_node); for (cs = new_node->callees; cs; cs = cs->next_callee) cs->count += cs->count.apply_scale (redirected_sum, new_node_count); From patchwork Tue Feb 21 14:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1745692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=OxJ7jH1O; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=R8qmgLPE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PLhps6PKdz23yV for ; Wed, 22 Feb 2023 01:43:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33EA83850401 for ; Tue, 21 Feb 2023 14:42:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 6D1723858D3C for ; Tue, 21 Feb 2023 14:42:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D1723858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9EF6334B3F; Tue, 21 Feb 2023 14:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676990563; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=mVfrJJWjsuCVRggm6DJcICECDf53bOVFA81nC1rU+1s=; b=OxJ7jH1OzFrXW/NpHzmrFI7eGnMYifplEFDWrYtesLHdegvQo74harXHWwznbd8JO//W2T 1P4BXcvrZpI2gywJDnRq+Ek4FMi79FixM5UUcMgV93Eq6GlUsSb7uFg3PN6kEoqnfg9lGZ Ckr1MlXaQww0bmjM7w8DvUcCVzVxlLc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676990563; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=mVfrJJWjsuCVRggm6DJcICECDf53bOVFA81nC1rU+1s=; b=R8qmgLPEYtjT5OKsVEGSQyPeYDn8rfj/tDh45AeOEDrpHuQx2WMDhh2fWdUPxhP92ReHSY oNrpis6yhRHjrpAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9358613223; Tue, 21 Feb 2023 14:42:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fnTbI2PY9GP+WQAAMHmgww (envelope-from ); Tue, 21 Feb 2023 14:42:43 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH 2/2] ipa-cp: Improve updating behavior when profile counts have gone bad User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Tue, 21 Feb 2023 15:42:43 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, Looking into the behavior of profile count updating in PR 107925, I noticed that an option not considered possible was actually happening, and - with the guesswork in place to distribute unexplained counts - it simply can happen. Currently it is handled by dropping the counts to local estimated zero, whereas it is probably better to leave the count as they are but drop the category to GUESSED_GLOBAL0 - which is what profile_count::combine_with_ipa_count in a similar case (or so I hope :-) Profiled-LTO-bootstrapped and normally bootstrapped and tested on an x86_64-linux. OK for master once stage1 opens up? Or perhaps even now? Thanks, Martin gcc/ChangeLog: 2023-02-20 Martin Jambor PR ipa/107925 * ipa-cp.cc (update_profiling_info): Drop counts of orig_node to global0 instead of zeroing when it does not have as many counts as it should. --- gcc/ipa-cp.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 5a6b41cf2d6..6477bb840e5 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -4969,10 +4969,20 @@ update_profiling_info (struct cgraph_node *orig_node, false); new_sum = stats.count_sum; + bool orig_edges_processed = false; if (new_sum > orig_node_count) { - /* TODO: Perhaps this should be gcc_unreachable ()? */ - remainder = profile_count::zero ().guessed_local (); + /* TODO: Profile has alreay gone astray, keep what we have but lower it + to global0 category. */ + remainder = orig_node->count.global0 (); + + for (cgraph_edge *cs = orig_node->callees; cs; cs = cs->next_callee) + cs->count = cs->count.global0 (); + for (cgraph_edge *cs = orig_node->indirect_calls; + cs; + cs = cs->next_callee) + cs->count = cs->count.global0 (); + orig_edges_processed = true; } else if (stats.rec_count_sum.nonzero_p ()) { @@ -5070,11 +5080,16 @@ update_profiling_info (struct cgraph_node *orig_node, for (cgraph_edge *cs = new_node->indirect_calls; cs; cs = cs->next_callee) cs->count = cs->count.apply_scale (new_sum, orig_new_node_count); - profile_count::adjust_for_ipa_scaling (&remainder, &orig_node_count); - for (cgraph_edge *cs = orig_node->callees; cs; cs = cs->next_callee) - cs->count = cs->count.apply_scale (remainder, orig_node_count); - for (cgraph_edge *cs = orig_node->indirect_calls; cs; cs = cs->next_callee) - cs->count = cs->count.apply_scale (remainder, orig_node_count); + if (!orig_edges_processed) + { + profile_count::adjust_for_ipa_scaling (&remainder, &orig_node_count); + for (cgraph_edge *cs = orig_node->callees; cs; cs = cs->next_callee) + cs->count = cs->count.apply_scale (remainder, orig_node_count); + for (cgraph_edge *cs = orig_node->indirect_calls; + cs; + cs = cs->next_callee) + cs->count = cs->count.apply_scale (remainder, orig_node_count); + } if (dump_file) {