]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa-cp: Fix various issues in update_specialized_profile (PR 107925)
authorMartin Jambor <mjambor@suse.cz>
Wed, 22 Mar 2023 15:59:45 +0000 (16:59 +0100)
committerMartin Jambor <mjambor@suse.cz>
Wed, 22 Mar 2023 16:03:49 +0000 (17:03 +0100)
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.

gcc/ChangeLog:

2023-02-17  Martin Jambor  <mjambor@suse.cz>

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.

(cherry picked from commit 68ba253bda74d6c6e77726d98184a6faee5e7337)

gcc/ipa-cp.cc

index dc3f0e94b1789a3e42d4b8a82e3a7d3e3fc7c58c..e3afd8a40472c0d273d81affb13875b74177721a 100644 (file)
@@ -4882,22 +4882,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);