Fix PR87266

Message ID alpine.LSU.2.20.1809121411570.16707@zhemvz.fhfr.qr
State New
Headers show
Series
  • Fix PR87266
Related show

Commit Message

Richard Biener Sept. 12, 2018, 12:13 p.m.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2018-09-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/87266
	* tree-ssa-sccvn.c (do_rpo_vn): Always iterate to not yet
	visited blocks.

	* gcc.dg/torture/pr87266-1.c: New testcase.
	* gcc.dg/torture/pr87266-2.c: Likewise.
	* gcc.dg/torture/pr87266-3.c: Likewise.
	* gcc.dg/torture/pr87266-4.c: Likewise.

Patch

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c	(revision 264234)
+++ gcc/tree-ssa-sccvn.c	(working copy)
@@ -6471,6 +6471,17 @@  do_rpo_vn (function *fn, edge entry, bit
 		== (EDGE_DFS_BACK|EDGE_EXECUTABLE)
 		&& rpo_state[bb_to_rpo[e->dest->index]].iterate)
 	      {
+		int destidx = bb_to_rpo[e->dest->index];
+		if (!rpo_state[destidx].visited)
+		  {
+		    if (dump_file && (dump_flags & TDF_DETAILS))
+		      fprintf (dump_file, "Unvisited destination %d\n",
+			       e->dest->index);
+		    if (iterate_to == -1
+			|| destidx < iterate_to)
+		      iterate_to = destidx;
+		    continue;
+		  }
 		if (dump_file && (dump_flags & TDF_DETAILS))
 		  fprintf (dump_file, "Looking for changed values of backedge "
 			   "%d->%d destination PHIs\n",
@@ -6497,7 +6508,6 @@  do_rpo_vn (function *fn, edge entry, bit
 			    && dump_file && (dump_flags & TDF_DETAILS))
 			  fprintf (dump_file, "PHI was CSEd and hashtable "
 				   "state (changed)\n");
-			int destidx = bb_to_rpo[e->dest->index];
 			if (iterate_to == -1
 			    || destidx < iterate_to)
 			  iterate_to = destidx;
Index: gcc/testsuite/gcc.dg/torture/pr87266-1.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr87266-1.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr87266-1.c	(working copy)
@@ -0,0 +1,32 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-ccp -fno-tree-forwprop" } */
+
+void
+iw (int gu, int mq, int r2)
+{
+  int yn = 0;
+
+  while (gu < 1)
+    {
+      for (;;)
+        ;
+
+ bb:;
+      int ay = 0;
+
+      while (ay < 1)
+        ++mq;
+    }
+
+  if (yn != 0)
+    goto up;
+
+  if (0)
+    {
+ up:
+      if (r2 == 0)
+        goto bb;
+    }
+
+  goto up;
+}
Index: gcc/testsuite/gcc.dg/torture/pr87266-2.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr87266-2.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr87266-2.c	(working copy)
@@ -0,0 +1,32 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-ccp -fno-tree-forwprop" } */
+
+void
+iw (int gu, int mq, int r2)
+{
+  int yn = 0;
+
+  while (gu < 1)
+    {
+      for (;;)
+        ;
+
+ bb:;
+      int ay = 0;
+
+      while (yn < 1)
+        ++mq;
+    }
+
+  if (yn != 0)
+    goto up;
+
+  if (0)
+    {
+ up:
+      if (r2 == 0)
+        goto bb;
+    }
+
+  goto up;
+}
Index: gcc/testsuite/gcc.dg/torture/pr87266-3.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr87266-3.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr87266-3.c	(working copy)
@@ -0,0 +1,32 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-ccp -fno-tree-forwprop" } */
+
+void
+iw (int gu, int mq, int r2)
+{
+  int yn = 0;
+
+  while (gu < 1)
+    {
+      int ay = 0;
+
+      for (;;)
+        ;
+
+ bb:
+      while (ay < 1)
+        ++mq;
+    }
+
+  if (yn != 0)
+    goto up;
+
+  if (0)
+    {
+ up:
+      if (r2 == 0)
+        goto bb;
+    }
+
+  goto up;
+}
Index: gcc/testsuite/gcc.dg/torture/pr87266-4.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr87266-4.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr87266-4.c	(working copy)
@@ -0,0 +1,38 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-dominator-opts -fno-tree-forwprop" } */
+
+unsigned long int
+re (long int j9)
+{
+  if (j9 == 0)
+    return 1;
+
+  return j9;
+}
+
+void
+zq (int bt, int yy)
+{
+  int p3 = 0, go = 4, ez = go;
+
+  while (go != 0)
+    {
+      if (ez + !!bt - re (bt) != 0 && go != 0)
+	{
+	  if (yy != 0)
+	    p3 = yy;
+	}
+      else
+	return;
+
+      go = 2;
+    }
+}
+
+void
+my (unsigned long int n6, int bt, int yy)
+{
+  zq (bt, yy);
+  n6 = n6 == bt;
+  zq (bt, yy);
+}