From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1611) id 5F790385842E; Tue, 14 Mar 2023 17:57:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F790385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678816637; bh=QskxSnwaorX+DAkDxdVDHv41ZK0ZMMvwa1WrKLRBD3I=; h=From:To:Subject:Date:From; b=NjPWLAP9RqhsHf0CgnTHwZRaosJx7PoU4aft1MRTVSqvkwWIrjWNG9y2jSjXgXSeE KjCa8QcYCZm0Hya4fA0i4Vz9rtZPCNB6XxTguQLyCSz0kQGa2pvfUqEyjdO9mPfglL P805dZr1pF2KAbn4EtzEbu8ewcOm7woI/Vp5QC6M= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Jambor To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6667] ipa-cp: Improve updating behavior when profile counts have gone bad X-Act-Checkin: gcc X-Git-Author: Martin Jambor X-Git-Refname: refs/heads/master X-Git-Oldrev: 68ba253bda74d6c6e77726d98184a6faee5e7337 X-Git-Newrev: 1526ecd739fc6a13329abdcbdbf7c2df57c22177 Message-Id: <20230314175717.5F790385842E@sourceware.org> Date: Tue, 14 Mar 2023 17:57:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1526ecd739fc6a13329abdcbdbf7c2df57c22177 commit r13-6667-g1526ecd739fc6a13329abdcbdbf7c2df57c22177 Author: Martin Jambor Date: Tue Mar 14 18:53:16 2023 +0100 ipa-cp: Improve updating behavior when profile counts have gone bad 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 :-) 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. Diff: --- 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) {