aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2023-04-05 15:59:38 -0400
committerAndrew MacLeod <amacleod@redhat.com>2023-04-06 08:32:04 -0400
commit7f056d5f4a0b9e29561d0375d5b4ad42c9f3f61e (patch)
treeecae54d1ba39aa1892e835c9a0d59014cacc5adc
parentd2a499a9881c7c079d2a722b57c7fcf022a864dd (diff)
downloadgcc-7f056d5f4a0b9e29561d0375d5b4ad42c9f3f61e.zip
gcc-7f056d5f4a0b9e29561d0375d5b4ad42c9f3f61e.tar.gz
gcc-7f056d5f4a0b9e29561d0375d5b4ad42c9f3f61e.tar.bz2
Check if dependency is valid before using in may_recompute_p.
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.
-rw-r--r--gcc/gimple-range-gori.cc4
-rw-r--r--gcc/testsuite/gcc.dg/pr109417.c24
2 files changed, 27 insertions, 1 deletions
diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index e44d271..d77e1f5 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -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
index 0000000..15711db
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109417.c
@@ -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;
+}
+