diff mbox series

tree-optimization/100566 - fix another predication issue in VN

Message ID 4495796-95p0-3255-3172-s08nq55qoop@fhfr.qr
State New
Headers show
Series tree-optimization/100566 - fix another predication issue in VN | expand

Commit Message

Richard Biener May 12, 2021, 3:01 p.m. UTC
This amends the fix for PR100053 where I failed to amend all edge
tests in dominated_by_p_w_unex.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk 
sofar.

2021-05-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/100566
	* tree-ssa-sccvn.c (dominated_by_p_w_unex): Properly handle
	allow_back for all edge queries.

	* gcc.dg/torture/pr100566.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr100566.c | 36 +++++++++++++++++++++++++
 gcc/tree-ssa-sccvn.c                    |  6 +++--
 2 files changed, 40 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr100566.c
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/torture/pr100566.c b/gcc/testsuite/gcc.dg/torture/pr100566.c
new file mode 100644
index 00000000000..ed856913639
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr100566.c
@@ -0,0 +1,36 @@ 
+/* { dg-do run } */
+
+volatile int s, c;
+
+__attribute__((noipa)) void
+foo (void)
+{
+  if (c++ > 1)
+    __builtin_abort ();
+}
+
+__attribute__((noipa)) int
+bar (void)
+{
+  int i = 0, j = s;
+  if (j == 0)
+    goto lab;
+  for (i = 0; i < j; i++)
+    {
+    lab:
+      foo ();
+      if (!j)
+        goto lab;
+    }
+  return 0;
+}
+
+int
+main ()
+{
+  s = 1;
+  bar ();
+  if (c != 1)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index e54a0c9065c..e8761219460 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -4529,7 +4529,8 @@  dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool allow_back)
   /* Iterate to the single executable bb2 successor.  */
   edge succe = NULL;
   FOR_EACH_EDGE (e, ei, bb2->succs)
-    if (e->flags & EDGE_EXECUTABLE)
+    if ((e->flags & EDGE_EXECUTABLE)
+	|| (!allow_back && (e->flags & EDGE_DFS_BACK)))
       {
 	if (succe)
 	  {
@@ -4547,7 +4548,8 @@  dominated_by_p_w_unex (basic_block bb1, basic_block bb2, bool allow_back)
 	{
 	  FOR_EACH_EDGE (e, ei, succe->dest->preds)
 	    if (e != succe
-		&& (e->flags & EDGE_EXECUTABLE))
+		&& ((e->flags & EDGE_EXECUTABLE)
+		    || (!allow_back && (e->flags & EDGE_DFS_BACK))))
 	      {
 		succe = NULL;
 		break;