]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Enable ipa-cp cloning for cold wrappers of hot functions
authorJan Hubicka <hubicka@ucw.cz>
Thu, 3 Jul 2025 08:25:39 +0000 (10:25 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Thu, 3 Jul 2025 08:25:39 +0000 (10:25 +0200)
ipa-cp cloning disables itself for all functions not passing opt_for_fn
(node->decl, optimize_size) which disables it for cold wrappers of hot
functions where we want to propagate.  Since we later want to time saved
to be considered hot, we do not need to make this early test.

The patch also fixes few other places where AFDO 0 disables ipa-cp.

gcc/ChangeLog:

* ipa-cp.cc (cs_interesting_for_ipcp_p): Handle
correctly GLOBAL0 afdo counts.
(ipcp_cloning_candidate_p): Do not rule out nodes
!node->optimize_for_size_p ().
(good_cloning_opportunity_p): Handle afdo counts
as non-zero.

gcc/ipa-cp.cc

index 75ea94f2ad85e51a2fc91b13c4ae7bb76d09cbd4..901d4a5616e9d425028d624281b8d20a15d84810 100644 (file)
@@ -554,6 +554,7 @@ cs_interesting_for_ipcp_p (cgraph_edge *e)
   /* If we have zero IPA profile, still consider edge for cloning
      in case we do partial training.  */
   if (e->count.ipa ().initialized_p ()
+      && e->count.ipa ().quality () != AFDO
       && !opt_for_fn (e->callee->decl,flag_profile_partial_training))
     return false;
   return true;
@@ -617,7 +618,9 @@ ipcp_cloning_candidate_p (struct cgraph_node *node)
       return false;
     }
 
-  if (node->optimize_for_size_p ())
+  /* Do not use profile here since cold wrapper wrap
+     hot function.  */
+  if (opt_for_fn (node->decl, optimize_size))
     {
       if (dump_file)
        fprintf (dump_file, "Not considering %s for cloning; "
@@ -3391,9 +3394,10 @@ good_cloning_opportunity_p (struct cgraph_node *node, sreal time_benefit,
                            int size_cost, bool called_without_ipa_profile)
 {
   gcc_assert (count_sum.ipa () == count_sum);
+  if (count_sum.quality () == AFDO)
+    count_sum = count_sum.force_nonzero ();
   if (time_benefit == 0
       || !opt_for_fn (node->decl, flag_ipa_cp_clone)
-      || node->optimize_for_size_p ()
       /* If there is no call which was executed in profiling or where
         profile is missing, we do not want to clone.  */
       || (!called_without_ipa_profile && !count_sum.nonzero_p ()))