https://gcc.gnu.org/g:c24eb5e01da5ce07f6b616aff1129d4acbff69e6

commit r16-1641-gc24eb5e01da5ce07f6b616aff1129d4acbff69e6
Author: Jan Hubicka <hubi...@ucw.cz>
Date:   Tue Jun 24 05:00:01 2025 +0200

    Fix AFDO zero profile handling
    
    This patch fixes roms autofdo regression I introduced yesterday.  What 
happens
    is that loop vectorization is disabled, because we get loop header count 0.
    I.e.
    
    loop_header:  <count 0>
      if (i < n)
        goto exit;
    loop_body:    <count large>
      ... vectorizable computation ...
    
    The reason is that "if (i < 0)" statement actually has 0 profile in AFDO
    feedback.  This seems common and I believe it is an issue with debug info in
    loop vecotrizer.  Because loop is vectorized during train run, the 
conditoinal
    is replaced by vectorized loop conditional but the statement remains in the
    loop epilogue which is not executed at runtime.
    
    This is something we can fix and introduce debug statement in the 
vectorized loop
    body so user can breakpoint on it. I will try to produce testcase for that.
    
    However this patch fixes bug where I intended to only trust 0 counts from 
AFDO if they
    are also 0 in static profile and reversed the conditinal.
    
    autoprofile-bootstrapped/regtested x86_64-linux, comitted.
    
            * auto-profile.cc (afdo_set_bb_count): Dump also 0 count stmts.
            (afdo_annotate_cfg): Fix conditional for block having non-zero 
static
            profile.

Diff:
---
 gcc/auto-profile.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 9b5be665f58a..8a1d9f878c65 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1315,7 +1315,7 @@ afdo_set_bb_count (basic_block bb, hash_set <basic_block> 
&zero_bbs)
        {
          if (info.count > max_count)
            max_count = info.count;
-         if (dump_file && info.count)
+         if (dump_file)
            {
              fprintf (dump_file, "  count %" PRIu64 " in stmt: ",
                       (int64_t)info.count);
@@ -2108,7 +2108,7 @@ afdo_annotate_cfg (void)
      afdo samples, but if even static profile agrees with 0,
      consider it final so propagation works better.  */
   for (basic_block bb : zero_bbs)
-    if (bb->count.nonzero_p ())
+    if (!bb->count.nonzero_p ())
       {
        update_count_by_afdo_count (&bb->count, 0);
        set_bb_annotated (bb, &annotated_bb);

Reply via email to