]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/118569 - LC SSA broken after unrolling
authorRichard Biener <rguenther@suse.de>
Tue, 21 Jan 2025 08:45:41 +0000 (09:45 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 21 Jan 2025 12:53:13 +0000 (13:53 +0100)
The following amends the previous fix to mark all of the loop BBs
as need to be scanned for new LC PHI uses when its nesting parents
changed, noticing one caller of fix_loop_placement was already
doing that.  So the following moves this code into fix_loop_placement,
covering both callers now.

PR tree-optimization/118569
* cfgloopmanip.cc (fix_loop_placement): When the loops
nesting parents changed, mark all blocks to be scanned
for LC PHI uses.
(fix_bb_placements): Remove code moved into fix_loop_placement.

* gcc.dg/torture/pr118569.c: New testcase.

gcc/cfgloopmanip.cc
gcc/testsuite/gcc.dg/torture/pr118569.c [new file with mode: 0644]

index 573146b2e28497071757ca9c715c497eb7004d94..2c28437b34d99171bc189b7795ff8de076fa82f2 100644 (file)
@@ -154,10 +154,17 @@ fix_loop_placement (class loop *loop, bool *irred_invalidated,
          if (e->flags & EDGE_IRREDUCIBLE_LOOP)
            *irred_invalidated = true;
          rescan_loop_exit (e, false, false);
-         /* Any LC SSA PHIs on e->dest might now be on the wrong edge
-            if their defs were in a former outer loop.  */
-         if (loop_closed_ssa_invalidated)
-           bitmap_set_bit (loop_closed_ssa_invalidated, e->src->index);
+       }
+      /* Any LC SSA PHIs on e->dest might now be on the wrong edge
+        if their defs were in a former outer loop.  Also all uses
+        in the original inner loop of defs in the outer loop(s) now
+        require LC PHI nodes.  */
+      if (loop_closed_ssa_invalidated)
+       {
+         basic_block *bbs = get_loop_body (loop);
+         for (unsigned i = 0; i < loop->num_nodes; ++i)
+           bitmap_set_bit (loop_closed_ssa_invalidated, bbs[i]->index);
+         free (bbs);
        }
 
       ret = true;
@@ -233,13 +240,6 @@ fix_bb_placements (basic_block from,
                                   loop_closed_ssa_invalidated))
            continue;
          target_loop = loop_outer (from->loop_father);
-         if (loop_closed_ssa_invalidated)
-           {
-             basic_block *bbs = get_loop_body (from->loop_father);
-             for (unsigned i = 0; i < from->loop_father->num_nodes; ++i)
-               bitmap_set_bit (loop_closed_ssa_invalidated, bbs[i]->index);
-             free (bbs);
-           }
        }
       else
        {
diff --git a/gcc/testsuite/gcc.dg/torture/pr118569.c b/gcc/testsuite/gcc.dg/torture/pr118569.c
new file mode 100644 (file)
index 0000000..c5b404a
--- /dev/null
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-ch -fno-tree-ccp -fno-tree-fre" } */
+
+volatile int a;
+int b, c, d, e, f, g;
+int main() {
+  int i = 2, j = 1;
+k:
+  if (!e)
+    ;
+  else {
+    short l = 1;
+    if (0)
+    m:
+      d = g;
+    f = 0;
+    for (; f < 2; f++) {
+      if (f)
+        for (; j < 2; j++)
+          if (i)
+            goto m;
+      a;
+      if (l)
+        continue;
+      i = 0;
+      while (c)
+        l++;
+    }
+    g = 0;
+  }
+  if (b) {
+    i = 1;
+    goto k;
+  }
+  return 0;
+}