https://gcc.gnu.org/g:22f1f765db056527076a3b7e785b068f3ea28cf0

commit r16-1246-g22f1f765db056527076a3b7e785b068f3ea28cf0
Author: Jan Hubicka <hubi...@ucw.cz>
Date:   Fri Jun 6 10:43:38 2025 +0200

    More of autofdo 0 issues
    
    This patch fixes ICE seen when building spec2k17 with autofdo and enable
    checking compiler.  Bause we special case 0 of autofdo to be kind of 1 in 
IPA
    scalling, we can now end up with function heving global0 profile but 
producing
    inline clone with nonzero profile.
    
    I think correct way is to extend auto-profile generation to merge static 
profile
    with afdo in places afdo profile is missing and drop the autofdo 0 hacks, 
but
    I think we need to run benchmarks first before making broader changes here.
    
            * profile-count.cc (profile_count::to_sreal_scale): Special case 0 
of autofdo.
            (profile_count::combine_with_ipa_count): If outer function has 
GLOBAL0 profile
            but innter counter has non-zero profile, force it to be 0.

Diff:
---
 gcc/profile-count.cc | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/profile-count.cc b/gcc/profile-count.cc
index 2d9c778b3758..22c109ab528c 100644
--- a/gcc/profile-count.cc
+++ b/gcc/profile-count.cc
@@ -344,6 +344,10 @@ profile_count::to_sreal_scale (profile_count in, bool 
*known) const
     return 1;
   if (!in.m_val)
     return m_val * 4;
+  /* Auto-FDO 0 really just means that we have no samples.
+     Treat it as small non-zero frequency.  */
+  if (!m_val && quality () == AFDO)
+    return (sreal)1 / (sreal)in.m_val;
   return (sreal)m_val / (sreal)in.m_val;
 }
 
@@ -398,7 +402,7 @@ profile_count::combine_with_ipa_count (profile_count ipa)
   return this->global0adjusted ();
 }
 
-/* Sae as profile_count::combine_with_ipa_count but within function with count
+/* Same as profile_count::combine_with_ipa_count but within function with count
    IPA2.  */
 profile_count
 profile_count::combine_with_ipa_count_within (profile_count ipa,
@@ -410,7 +414,16 @@ profile_count::combine_with_ipa_count_within 
(profile_count ipa,
   if (ipa2.ipa () == ipa2 && ipa.initialized_p ())
     ret = ipa;
   else
-    ret = combine_with_ipa_count (ipa);
+    {
+      /* For inconsistent profiles we may end up having ipa2 of GLOBAL0
+        while ipa is non-zero (i.e. non-zero IPA counters within function
+        executed 0 times).  Be sure we produce GLOBAL0 as well
+        so counters remain compatible.  */
+      if (ipa.nonzero_p ()
+         && ipa2.ipa ().initialized_p ())
+       ipa = ipa2.ipa ();
+      ret = combine_with_ipa_count (ipa);
+    }
   gcc_checking_assert (ret.compatible_p (ipa2));
   return ret;
 }

Reply via email to