]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/112827 - corrupt SCEV cache during SCCP
authorRichard Biener <rguenther@suse.de>
Mon, 4 Dec 2023 09:46:11 +0000 (10:46 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 4 Dec 2023 11:53:55 +0000 (12:53 +0100)
The following avoids corrupting the SCEV cache by my last change
to propagate constant final values immediately.  The easiest fix
is to keep a dead initialization around.

PR tree-optimization/112827
* tree-scalar-evolution.cc (final_value_replacement_loop):
Do not release SSA name but keep a dead initialization around.

* gcc.dg/torture/pr112827-1.c: New testcase.
* gcc.dg/torture/pr112827-2.c: Likewise.

gcc/testsuite/gcc.dg/torture/pr112827-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr112827-2.c [new file with mode: 0644]
gcc/tree-scalar-evolution.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr112827-1.c b/gcc/testsuite/gcc.dg/torture/pr112827-1.c
new file mode 100644 (file)
index 0000000..6838cbb
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+int a, b, c, d, e;
+int main() {
+  for (; c; c++) {
+    for (a = 0; a < 2; a++)
+      ;
+    for (; b; b++) {
+      e = d;
+      d = a;
+    }
+  }
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr112827-2.c b/gcc/testsuite/gcc.dg/torture/pr112827-2.c
new file mode 100644 (file)
index 0000000..a7a2a70
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+short a, b[1], f;
+char c, g;
+int d, e;
+int main() {
+  for (; f; f++) {
+    for (d = 0; d < 2; d++)
+      ;
+    if (a)
+      for (g = 0; g < 2; g++)
+        for (c = 0; c < 2; c += b[d+g])
+          ;
+    for (; e; e++)
+      ;
+  }
+  return 0;
+}
index 065bcd0743d7f7b979d50d6cdd13413092fa3c94..7556d89e9f8891a25bff943fd88efe09be467312 100644 (file)
@@ -3847,13 +3847,10 @@ final_value_replacement_loop (class loop *loop)
       def = unshare_expr (def);
       remove_phi_node (&psi, false);
 
-      /* Propagate constants immediately.  */
+      /* Propagate constants immediately, but leave an unused initialization
+        around to avoid invalidating the SCEV cache.  */
       if (CONSTANT_CLASS_P (def))
-       {
-         replace_uses_by (rslt, def);
-         release_ssa_name (rslt);
-         continue;
-       }
+       replace_uses_by (rslt, def);
 
       /* Create the replacement statements.  */
       gimple_seq stmts;