]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
More of autofdo 0 issues
authorJan Hubicka <hubicka@ucw.cz>
Fri, 6 Jun 2025 08:43:38 +0000 (10:43 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Fri, 6 Jun 2025 08:44:25 +0000 (10:44 +0200)
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.

gcc/profile-count.cc

index 2d9c778b3758b27bd62c03e475c3d6dc93cd2160..22c109ab528c0bcce094d484042346e5100a340b 100644 (file)
@@ -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;
 }