re PR tree-optimization/87349 (ICE: Segmentation fault (in useless_type_conversion_p...
authorRichard Biener <rguenther@suse.de>
Wed, 19 Sep 2018 07:10:42 +0000 (07:10 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 19 Sep 2018 07:10:42 +0000 (07:10 +0000)
2018-09-19  Richard Biener  <rguenther@suse.de>

PR tree-optimization/87349
PR tree-optimization/87342
* tree-ssa-sccvn.c (do_rpo_vn): Iterate max_rpo computation.

* gcc.dg/torture/pr87349-1.c: New testcase.
* gcc.dg/torture/pr87349-2.c: Likewise.
* gcc.dg/torture/pr87342.c: Likewise.

From-SVN: r264419

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr87342.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr87349-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr87349-2.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 69e2e147bb90c9443c743821def3972e3aa4e600..68d8be20e71dcb78e679251906acadbf279f749d 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/87349
+       PR tree-optimization/87342
+       * tree-ssa-sccvn.c (do_rpo_vn): Iterate max_rpo computation.
+
 2018-09-18  Marek Polacek  <polacek@redhat.com>
 
        P1064R0 - Allowing Virtual Function Calls in Constant Expressions
index 29946077ecde80630ee700efd874b60f37361aef..f26e1e29fc21771bb85007067c6aa80ef50206f2 100644 (file)
@@ -1,3 +1,11 @@
+2018-09-19  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/87349
+       PR tree-optimization/87342
+       * gcc.dg/torture/pr87349-1.c: New testcase.
+       * gcc.dg/torture/pr87349-2.c: Likewise.
+       * gcc.dg/torture/pr87342.c: Likewise.
+
 2018-09-18  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/29550
diff --git a/gcc/testsuite/gcc.dg/torture/pr87342.c b/gcc/testsuite/gcc.dg/torture/pr87342.c
new file mode 100644 (file)
index 0000000..ba33fb4
--- /dev/null
@@ -0,0 +1,44 @@
+/* { dg-do compile } */
+
+int ix;
+
+void
+o6 (int rh)
+{
+  if (rh == 0)
+    {
+      ix = 0;
+      while (ix < 1)
+       {
+       }
+
+      for (;;)
+       if (ix == 0)
+         while (rh < 1)
+           {
+             if (rh == 0)
+               {
+                 __builtin_unreachable ();
+
+kp:
+                 if (ix == 0)
+                   {
+hk:
+                     ix = 0;
+                   }
+               }
+
+             while (rh < 1)
+               if (ix == 0)
+                 goto kp;
+
+             while (rh < 1)
+               {
+               }
+           }
+       else
+         goto kp;
+    }
+
+  goto hk;
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr87349-1.c b/gcc/testsuite/gcc.dg/torture/pr87349-1.c
new file mode 100644 (file)
index 0000000..27e5fdb
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+
+void
+h1 (int *fh, int pw)
+{
+  *fh = 0;
+  if (*fh != 0)
+    for (;;)
+      {
+       fh = &pw;
+
+       if (pw == 0)
+         {
+         }
+       else
+         while (pw < 1)
+           {
+             if (pw == 0)
+               {
+ut:
+                 ;
+               }
+
+             ++pw;
+           }
+
+       if (pw == 0)
+         goto ut;
+      }
+
+  goto ut;
+}
+
diff --git a/gcc/testsuite/gcc.dg/torture/pr87349-2.c b/gcc/testsuite/gcc.dg/torture/pr87349-2.c
new file mode 100644 (file)
index 0000000..e8160ac
--- /dev/null
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+
+void
+h1 (int *fh, int pw)
+{
+  *fh = 0;
+  if (*fh != 0)
+    for (;;)
+      {
+       fh = &pw;
+
+       if (pw == 0)
+         {
+         }
+       else
+         while (pw < 1)
+           {
+             if (pw == 0)
+               {
+ut:
+                 ;
+               }
+
+             ++pw;
+           }
+
+       if (pw == *fh)
+         goto ut;
+      }
+
+  goto ut;
+}
+
index a49e7f6745138521f94ddd24f795036f20c1d9a1..cee3d73a75b1eb0171e2264a8f84668f43b823aa 100644 (file)
@@ -6374,6 +6374,7 @@ do_rpo_vn (function *fn, edge entry, bitmap exit_bbs,
   vn_valueize = rpo_vn_valueize;
 
   /* Initialize the unwind state and edge/BB executable state.  */
+  bool need_max_rpo_iterate = false;
   for (int i = 0; i < n; ++i)
     {
       basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
@@ -6388,11 +6389,14 @@ do_rpo_vn (function *fn, edge entry, bitmap exit_bbs,
          if (e->flags & EDGE_DFS_BACK)
            has_backedges = true;
          e->flags &= ~EDGE_EXECUTABLE;
-         if (e == entry)
+         if (iterate || e == entry)
            continue;
          if (bb_to_rpo[e->src->index] > i)
-           rpo_state[i].max_rpo = MAX (rpo_state[i].max_rpo,
-                                       bb_to_rpo[e->src->index]);
+           {
+             rpo_state[i].max_rpo = MAX (rpo_state[i].max_rpo,
+                                         bb_to_rpo[e->src->index]);
+             need_max_rpo_iterate = true;
+           }
          else
            rpo_state[i].max_rpo
              = MAX (rpo_state[i].max_rpo,
@@ -6403,6 +6407,35 @@ do_rpo_vn (function *fn, edge entry, bitmap exit_bbs,
   entry->flags |= EDGE_EXECUTABLE;
   entry->dest->flags |= BB_EXECUTABLE;
 
+  /* When there are irreducible regions the simplistic max_rpo computation
+     above for the case of backedges doesn't work and we need to iterate
+     until there are no more changes.  */
+  unsigned nit = 0;
+  while (need_max_rpo_iterate)
+    {
+      nit++;
+      need_max_rpo_iterate = false;
+      for (int i = 0; i < n; ++i)
+       {
+         basic_block bb = BASIC_BLOCK_FOR_FN (fn, rpo[i]);
+         edge e;
+         edge_iterator ei;
+         FOR_EACH_EDGE (e, ei, bb->preds)
+           {
+             if (e == entry)
+               continue;
+             int max_rpo = MAX (rpo_state[i].max_rpo,
+                                rpo_state[bb_to_rpo[e->src->index]].max_rpo);
+             if (rpo_state[i].max_rpo != max_rpo)
+               {
+                 rpo_state[i].max_rpo = max_rpo;
+                 need_max_rpo_iterate = true;
+               }
+           }
+       }
+    }
+  statistics_histogram_event (cfun, "RPO max_rpo iterations", nit);
+
   /* As heuristic to improve compile-time we handle only the N innermost
      loops and the outermost one optimistically.  */
   if (iterate)