]> gcc.gnu.org Git - gcc.git/commitdiff
middle-end/114579 - speed up add_scope_conflicts
authorRichard Biener <rguenther@suse.de>
Thu, 4 Apr 2024 12:00:10 +0000 (14:00 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 2 May 2024 06:31:54 +0000 (08:31 +0200)
The following speeds up stack variable conflict detection by recognizing
that the all-to-all conflict recording is only necessary for CFG merges
as it's the unioning of the live variable sets that doesn't come with
explicit mentions we record conflicts for.

If we employ this optimization we have to make sure to perform the
all-to-all conflict recording for all CFG merges even those into
empty blocks where we might previously have skipped this.

I have reworded the comment before the all-to-all conflict recording
since it seemed to be confusing and missing the point - but maybe I
am also missing something here.

Nevertheless for the testcase in the PR the compile-time spend in
add_scope_conflicts at -O1 drops from previously 67s (39%) to 10s (9%).

PR middle-end/114579
* cfgexpand.cc (add_scope_conflicts_1): Record all-to-all
conflicts only when there's a CFG merge but for all CFG merges.

gcc/cfgexpand.cc

index cfc5291aa0cdd3095a299a80ea06f8fd3c9ff453..afee064aa154fd5c97c6e85152b6aa61a3c87eb3 100644 (file)
@@ -640,21 +640,26 @@ add_scope_conflicts_1 (basic_block bb, bitmap work, bool for_conflict)
        {
          if (for_conflict && visit == visit_op)
            {
-             /* If this is the first real instruction in this BB we need
-                to add conflicts for everything live at this point now.
-                Unlike classical liveness for named objects we can't
-                rely on seeing a def/use of the names we're interested in.
-                There might merely be indirect loads/stores.  We'd not add any
-                conflicts for such partitions.  */
+             /* When we are inheriting live variables from our predecessors
+                through a CFG merge we might not see an actual mention of
+                the variables to record the approprate conflict as defs/uses
+                might be through indirect stores/loads.  For this reason
+                we have to make sure each live variable conflicts with
+                each other.  When there's just a single predecessor the
+                set of conflicts is already up-to-date.
+                We perform this delayed at the first real instruction to
+                allow clobbers starting this block to remove variables from
+                the set of live variables.  */
              bitmap_iterator bi;
              unsigned i;
-             EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
-               {
-                 class stack_var *a = &stack_vars[i];
-                 if (!a->conflicts)
-                   a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
-                 bitmap_ior_into (a->conflicts, work);
-               }
+             if (EDGE_COUNT (bb->preds) > 1)
+               EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
+                 {
+                   class stack_var *a = &stack_vars[i];
+                   if (!a->conflicts)
+                     a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
+                   bitmap_ior_into (a->conflicts, work);
+                 }
              visit = visit_conflict;
            }
          walk_stmt_load_store_addr_ops (stmt, work, visit, visit, visit);
@@ -662,6 +667,21 @@ add_scope_conflicts_1 (basic_block bb, bitmap work, bool for_conflict)
            add_scope_conflicts_2 (USE_FROM_PTR (use_p), work, visit);
        }
     }
+
+  /* When there was no real instruction but there's a CFG merge we need
+     to add the conflicts now.  */
+  if (for_conflict && visit == visit_op && EDGE_COUNT (bb->preds) > 1)
+    {
+      bitmap_iterator bi;
+      unsigned i;
+      EXECUTE_IF_SET_IN_BITMAP (work, 0, i, bi)
+       {
+         class stack_var *a = &stack_vars[i];
+         if (!a->conflicts)
+           a->conflicts = BITMAP_ALLOC (&stack_var_bitmap_obstack);
+         bitmap_ior_into (a->conflicts, work);
+       }
+    }
 }
 
 /* Generate stack partition conflicts between all partitions that are
This page took 0.071924 seconds and 5 git commands to generate.