Fix pasto in the substitute_and_fold_engine merge with evrp.
authorAldy Hernandez <aldyh@redhat.com>
Tue, 16 Jun 2020 11:43:57 +0000 (13:43 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 16 Jun 2020 18:46:42 +0000 (20:46 +0200)
The original code only propagated into PHI arguments if the value was
a constant.  This behavior was lost in the conversion, allowing
any value (SSAs for instance) to be propagated into PHIs.

gcc/ChangeLog:

PR tree-optimization/95649
* tree-ssa-propagate.c (propagate_into_phi_args): Do not propagate unless
value is a constant.

gcc/testsuite/ChangeLog:

* g++.dg/tree-ssa/pr95649.C: New test.
* gcc.dg/tree-ssa/pr95649.c: New test.

gcc/testsuite/g++.dg/tree-ssa/pr95649.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr95649.c [new file with mode: 0644]
gcc/tree-ssa-propagate.c

diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr95649.C b/gcc/testsuite/g++.dg/tree-ssa/pr95649.C
new file mode 100644 (file)
index 0000000..139f699
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern unsigned short var_5;
+extern int var_8, var_9;
+extern short arr_7[];
+void test() {
+  for (; 0 < (char)var_5;)
+    for (int a(var_9 ? var_5 : 0); a < 3002972621U + 1291994699;
+         a += 19499 - 19497)
+      for (long b(var_8); b; b += 4)
+        arr_7[a * b] = 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr95649.c b/gcc/testsuite/gcc.dg/tree-ssa/pr95649.c
new file mode 100644 (file)
index 0000000..cc9b764
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-scev-cprop" } */
+
+char b (void);
+char *d;
+int e;
+int f;
+void
+g (char *h)
+{
+  while (d)
+    {
+      long i = b ();
+      if (h + i > d)
+       break;
+      if (f > 0 || e)
+       do
+         *h++ = *h;
+       while (--i);
+    }
+}
index 4fda296..01ee7fd 100644 (file)
@@ -1035,7 +1035,8 @@ substitute_and_fold_engine::propagate_into_phi_args (basic_block bb)
              || virtual_operand_p (arg))
            continue;
          tree val = get_value (arg, phi);
-         if (val && may_propagate_copy (arg, val))
+         if (val && is_gimple_min_invariant (val)
+             && may_propagate_copy (arg, val))
            propagate_value (use_p, val);
        }
     }