public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5492] tree-optimization/108574 - wrong-code with PRE PHI node processing
@ 2023-01-30  9:51 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-01-30  9:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7ac3e69e311351b70407d7f87a0169c4d463e57b

commit r13-5492-g7ac3e69e311351b70407d7f87a0169c4d463e57b
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jan 30 09:25:23 2023 +0100

    tree-optimization/108574 - wrong-code with PRE PHI node processing
    
    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.
    
            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.

Diff:
---
 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(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-1.c b/gcc/testsuite/gcc.dg/torture/pr108574-1.c
new file mode 100644
index 00000000000..7066b5ee2a2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108574-1.c
@@ -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;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-2.c b/gcc/testsuite/gcc.dg/torture/pr108574-2.c
new file mode 100644
index 00000000000..1e38d087646
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108574-2.c
@@ -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;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr108574-3.c b/gcc/testsuite/gcc.dg/torture/pr108574-3.c
new file mode 100644
index 00000000000..3c9146e31ac
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr108574-3.c
@@ -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;
+}
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index edb553b07cb..028bedbc9a0 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -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;
 		      }
 		  }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-30  9:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-30  9:51 [gcc r13-5492] tree-optimization/108574 - wrong-code with PRE PHI node processing Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).