]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/110298 - CFG cleanup and stale nb_iterations
authorRichard Biener <rguenther@suse.de>
Mon, 19 Jun 2023 07:52:45 +0000 (09:52 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 15 Dec 2023 12:17:33 +0000 (13:17 +0100)
When unrolling we eventually kill nb_iterations info since it may
refer to removed SSA names.  But we do this only after cleaning
up the CFG which in turn can end up accessing it.  Fixed by
swapping the two.

PR tree-optimization/110298
* tree-ssa-loop-ivcanon.c (tree_unroll_loops_completely):
Clear number of iterations info before cleaning up the CFG.

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

(cherry picked from commit 916add3bf6e46467e4391e358b11ecfbc4daa275)

gcc/testsuite/gcc.dg/torture/pr110298.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivcanon.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr110298.c b/gcc/testsuite/gcc.dg/torture/pr110298.c
new file mode 100644 (file)
index 0000000..139f5c7
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+
+int a, b, c, d, e;
+int f() {
+  c = 0;
+  for (; c >= 0; c--) {
+    d = 0;
+    for (; d <= 0; d++) {
+      e = 0;
+      for (; d + c + e >= 0; e--)
+        ;
+      a = 1;
+      b = 0;
+      for (; a; ++b)
+        a *= 2;
+      for (; b + d >= 0;)
+        return 0;
+    }
+  }
+}
index 3f9e9d0869f2d0c0103123791fe34d760ddd5c52..40b3bb06add003bc0ab7edfa4a1e98701cbd1d9a 100644 (file)
@@ -1487,15 +1487,16 @@ tree_unroll_loops_completely (bool may_increase_size, bool unroll_outer)
            }
          BITMAP_FREE (fathers);
 
+         /* Clean up the information about numbers of iterations, since
+            complete unrolling might have invalidated it.  */
+         scev_reset ();
+
          /* This will take care of removing completely unrolled loops
             from the loop structures so we can continue unrolling now
             innermost loops.  */
          if (cleanup_tree_cfg ())
            update_ssa (TODO_update_ssa_only_virtuals);
 
-         /* Clean up the information about numbers of iterations, since
-            complete unrolling might have invalidated it.  */
-         scev_reset ();
          if (flag_checking && loops_state_satisfies_p (LOOP_CLOSED_SSA))
            verify_loop_closed_ssa (true);
        }