]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Re-add logic to mitigate some afdo profile inconsistencies
authorJan Hubicka <hubicka@ucw.cz>
Mon, 30 Jun 2025 07:14:46 +0000 (09:14 +0200)
committerJan Hubicka <hubicka@ucw.cz>
Mon, 30 Jun 2025 07:15:14 +0000 (09:15 +0200)
This patch re-adds logic to increase counts of annotated basic blocks if otherwise
the Kirhoff law can not be solved.  This is done only in easy cases where total
count of in or out edges is smaller than the count of BB or when BB has single
exit which is annotated by small count.

This helps to solve problems seen i.e. in parest where header of loops gets too
low count because vectorizer replaced the IV condiitonal and did not preserved
debug info.  We should solve the debug info issues as well, and simiar problems
can now be tracked by in afdo debug dumps.

gcc/ChangeLog:

* auto-profile.cc (autofdo_source_profile::offline_external_functions):
Add missing newline in dump.
(afdo_propagate_edge): If annotated BB or edge has too small count
bump it up to mitigate profile imprecisions caused by vectorizer.
(afdo_propagate): Increase number of iteraitons and fix dump

gcc/auto-profile.cc

index 44e7faa8fee69bd7779b5987b809236e37155d05..d78f2cb42b5c1859461177a32751e7a2721846dd 100644 (file)
@@ -1308,7 +1308,7 @@ autofdo_source_profile::offline_external_functions ()
              if (dump_file)
                fprintf (dump_file,
                         "string table in auto-profile contains"
-                        " duplicated name %s", n1);
+                        " duplicated name %s\n", n1);
              to_symbol_name.put (i, index);
            }
          continue;
@@ -2491,6 +2491,21 @@ afdo_propagate_edge (bool is_succ, bb_set *annotated_bb)
        set_bb_annotated (bb, annotated_bb);
        changed = true;
       }
+    else if (is_bb_annotated (bb, *annotated_bb)
+            && bb->count < total_known_count)
+      {
+       if (dump_file)
+         {
+           fprintf (dump_file, "  Increasing bb %i count from ",
+                    bb->index);
+           bb->count.dump (dump_file);
+           fprintf (dump_file, " to ");
+           total_known_count.dump (dump_file);
+           fprintf (dump_file, " hoping to mitigate afdo inconsistency\n");
+         }
+       bb->count = total_known_count;
+       changed = true;
+      }
     else if (num_unknown_edges == 1 && is_bb_annotated (bb, *annotated_bb))
       {
        if (bb->count > total_known_count)
@@ -2533,6 +2548,27 @@ afdo_propagate_edge (bool is_succ, bb_set *annotated_bb)
              }
          }
       }
+    else if (num_unknown_edges == 0
+            && is_bb_annotated (bb, *annotated_bb)
+            && (is_succ ? single_succ_p (bb) : single_pred_p (bb)))
+      {
+       edge e = is_succ ? single_succ_edge (bb) : single_pred_edge (bb);
+       if (AFDO_EINFO (e)->is_annotated ()
+           && AFDO_EINFO (e)->get_count () < bb->count)
+         {
+           if (dump_file)
+             {
+               fprintf (dump_file, "  Increasing edge %i->%i count from ",
+                        e->src->index, e->dest->index);
+               AFDO_EINFO (e)->get_count ().dump (dump_file);
+               fprintf (dump_file, " to ");
+               bb->count.dump (dump_file);
+               fprintf (dump_file, " hoping to mitigate afdo inconsistency\n");
+             }
+           AFDO_EINFO (e)->set_count (bb->count);
+           changed = true;
+         }
+      }
   }
   return changed;
 }
@@ -2662,10 +2698,11 @@ afdo_propagate (bb_set *annotated_bb)
                     ((basic_block)bb->aux)->index,
                     bb->index);
            bb->count.dump (dump_file);
+           fprintf (dump_file, "\n");
          }
       }
 
-  while (changed && i++ < 10)
+  while (changed && i++ < 100)
     {
       changed = false;
 
@@ -2676,7 +2713,7 @@ afdo_propagate (bb_set *annotated_bb)
       afdo_propagate_circuit (*annotated_bb);
     }
   if (dump_file)
-    fprintf (dump_file, "Propated in %i iterations %s\n",
+    fprintf (dump_file, "Propagation took %i iterations %s\n",
             i, changed ? "; iteration limit reached\n" : "");
 }