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: 60116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp45771wrd; Tue, 21 Feb 2023 06:43:36 -0800 (PST) X-Google-Smtp-Source: AK7set+X9FNK+4qY5lb4dyQY5vz4+aqC8c5POvs/iKQGRCh03XZu9kNRi5C3cftdA806fgN97qnv X-Received: by 2002:a17:906:d8cf:b0:8b2:5262:562c with SMTP id re15-20020a170906d8cf00b008b25262562cmr13302090ejb.34.1676990615982; Tue, 21 Feb 2023 06:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676990615; cv=none; d=google.com; s=arc-20160816; b=OXkIKGXElGlV0M2/NErcNOwCCTsfAuB//kbNEPQ2uO4L1RjLa8c69+6lYCXA/cpmZd LhTf2iebR/D4hKMnCjPFW0FMSW5W0zra9KW1iB/N21ucVoM5QFVgAor2KIO1VDjsZwGR GsjDC2HxkueeTEij5gKtLqI/1abYNuj8icEYrXl+N9TefUg0xTWq14RdhE1aaBSVcSNh nVz48aJoOdCNbCLN3pmxgkvbnKLjLrb0GMzBTLSIc42jUPBKxLLTtiWs+a4x4Yp6RQbp 4+Q3qjWXO5a6m+dDEHxcOP8KNxgc29wBJwZZcSq0K/oFv+WigppwfDbAQ+7stHoiW7L+ wp6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=mVfrJJWjsuCVRggm6DJcICECDf53bOVFA81nC1rU+1s=; b=0T9amS1dOoSAM1gGLvxMggcIl9uFR0WEpFRWIlgcFaRSjy36H5lZtgJ4/UiDrPTe+w qzkH7U4YPFUaA3cSa3SkgrG25+82lLCCZIEfoAGy+JLqqgyvT5LtIIZ++t0bWcWYB7UF BvncooyxCPBvhAw2ktsySAB2kVspt5JIRZyjQ+1pDuInp87qhPbtGz3O9FTM/OcWAprq VY+CA+2wscARnG23ZXiZISmmgPnbYhaFinrEbZ9A2rFdJt/bCrEoT0FUyvxEsy75WI7f 8xepg7xoHn/2fibKx7j19/OJ85uD4XvDrURb0y6p1vrBdAhp4EoDcYMQG7hjXjuT6y3t 8E5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=OxJ7jH1O; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 12-20020a17090600cc00b008dcebb5a0fasi3813019eji.944.2023.02.21.06.43.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 06:43:35 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=OxJ7jH1O; dkim=neutral (no key) header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE5A0385735E for ; Tue, 21 Feb 2023 14:43:11 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758452111722227339?= X-GMAIL-MSGID: =?utf-8?q?1758452111722227339?= 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) {