tree-optimization/108574 - wrong-code with PRE PHI node processing
Checks
Commit Message
The PR108523 was too optimistic in replacing the same value with
an equivalence from a possibly not taken edge. The following
rectifies this and instead refrains from using the equivalence in
the problematic cases.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/108574
* tree-ssa-sccvn.cc (visit_phi): Instead of swapping
sameval and def, ignore the equivalence if there's the
danger of oscillating between two values.
* gcc.dg/torture/pr108574-1.c: New testcase.
* gcc.dg/torture/pr108574-2.c: Likewise.
* gcc.dg/torture/pr108574-3.c: Likewise.
---
gcc/testsuite/gcc.dg/torture/pr108574-1.c | 19 ++++++++++++++++
gcc/testsuite/gcc.dg/torture/pr108574-2.c | 25 +++++++++++++++++++++
gcc/testsuite/gcc.dg/torture/pr108574-3.c | 27 +++++++++++++++++++++++
gcc/tree-ssa-sccvn.cc | 11 +++++----
4 files changed, 76 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr108574-1.c
create mode 100644 gcc/testsuite/gcc.dg/torture/pr108574-2.c
create mode 100644 gcc/testsuite/gcc.dg/torture/pr108574-3.c
new file mode 100644
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+int a = 1, b, c = 2, d;
+int main() {
+ if (b)
+ goto L2;
+ L1:
+ {
+ int e = c;
+ a = 1 % a;
+ while (e && 1 <= d)
+ ;
+ d >= b;
+ L2:
+ if (1 >= e)
+ goto L1;
+ }
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* { dg-do run } */
+
+int a, b, c, d, e, f, g = -1, h;
+void l() {
+ if (!e)
+ goto i;
+ for (; g; g++) {
+ b = ~d;
+ int j = 0, k = 1;
+ if (k && (b || f))
+ j = b;
+ i:
+ a = ~j;
+ }
+}
+int main() {
+ h = 3;
+ for (; h; h--) {
+ e = 1;
+ int m = ~a, n = 1 % m;
+ c = n;
+ l();
+ }
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* { dg-do run } */
+
+int a = 3557301289, d;
+char b, f;
+unsigned short c = 241;
+short e, g;
+static void h() {
+ if (!a)
+ goto i;
+ b = a;
+ for (; a < 2; a = b) {
+ unsigned short j;
+ if (c || !g) {
+ j = c;
+ i:
+ e = j;
+ }
+ f = j;
+ d = ~(f & ~2880764155);
+ while (d > -2316069)
+ ;
+ }
+}
+int main() {
+ h();
+ return 0;
+}
@@ -5908,7 +5908,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
if (! val && vnresult && vnresult->predicated_values)
{
val = vn_nary_op_get_predicated_value (vnresult, e->src);
- if (val && integer_truep (val))
+ if (val && integer_truep (val)
+ && !(sameval_e && (sameval_e->flags & EDGE_DFS_BACK)))
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
@@ -5919,8 +5920,6 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
fprintf (dump_file, " are equal on edge %d -> %d\n",
e->src->index, e->dest->index);
}
- if (sameval_e && (sameval_e->flags & EDGE_DFS_BACK))
- sameval = def;
continue;
}
/* If on all previous edges the value was equal to def
@@ -5928,7 +5927,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
if (EDGE_COUNT (bb->preds) == 2
&& (val = vn_nary_op_get_predicated_value
(vnresult, EDGE_PRED (bb, 0)->src))
- && integer_truep (val))
+ && integer_truep (val)
+ && !(e->flags & EDGE_DFS_BACK))
{
if (dump_file && (dump_flags & TDF_DETAILS))
{
@@ -5940,8 +5940,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
EDGE_PRED (bb, 0)->src->index,
EDGE_PRED (bb, 0)->dest->index);
}
- if (!(e->flags & EDGE_DFS_BACK))
- sameval = def;
+ sameval = def;
continue;
}
}