]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check if dependency is valid before using in may_recompute_p.
authorAndrew MacLeod <amacleod@redhat.com>
Wed, 5 Apr 2023 19:59:38 +0000 (15:59 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 6 Apr 2023 12:32:04 +0000 (08:32 -0400)
When the IL is rewritten after a statement has been processed and
dependencies cached, its possible that an ssa-name in the dependency
cache is no longer in the IL.  Check this before trying to recompute.

PR tree-optimization/109417
gcc/
* gimple-range-gori.cc (gori_compute::may_recompute_p): Check if
dependency is in SSA_NAME_FREE_LIST.

gcc/testsuite/
* gcc.dg/pr109417.c: New.

gcc/gimple-range-gori.cc
gcc/testsuite/gcc.dg/pr109417.c [new file with mode: 0644]

index e44d271fedb3eea181cf22aaa6b95878a4f61cdc..d77e1f51ac20a5347e70b92b632fa1847b2cc483 100644 (file)
@@ -1314,7 +1314,9 @@ gori_compute::may_recompute_p (tree name, basic_block bb, int depth)
   tree dep2 = depend2 (name);
 
   // If the first dependency is not set, there is no recomputation.
-  if (!dep1)
+  // Dependencies reflect original IL, not current state.   Check if the
+  // SSA_NAME is still valid as well.
+  if (!dep1 || SSA_NAME_IN_FREE_LIST (dep1))
     return false;
 
   // Don't recalculate PHIs or statements with side_effects.
diff --git a/gcc/testsuite/gcc.dg/pr109417.c b/gcc/testsuite/gcc.dg/pr109417.c
new file mode 100644 (file)
index 0000000..15711db
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int printf(const char *, ...);
+int c, d, *e, f[1][2], g;
+int main() {
+  int h = 0, *a = &h, **b[1] = {&a};
+  while (e)
+    while (g) {
+    L:
+      for (h = 0; h < 2; h++) {
+        while (d)
+          for (*e = 0; *e < 1;)
+            printf("0");
+        while (c)
+          ;
+        f[g][h] = 0;
+      }
+    }
+  if (h)
+    goto L;
+  return 0;
+}
+