This fixes PR67221.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2015-08-17  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/67221
        * tree-ssa-sccvn.c (visit_phi): Keep all-TOP args TOP.
        (sccvn_dom_walker::before_dom_children): Mark backedges of
        non-executable blocks as not executable.

        * gcc.dg/torture/pr67221.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c        (revision 226934)
+++ gcc/tree-ssa-sccvn.c        (working copy)
@@ -3271,6 +3277,11 @@ visit_phi (gimple phi)
            break;
          }
       }
+  
+  /* If none of the edges was executable or all incoming values are
+     undefined keep the value-number at VN_TOP.  */
+  if (sameval == VN_TOP)
+    return set_ssa_val_to (PHI_RESULT (phi), VN_TOP);
 
   /* First see if it is equivalent to a phi node in this block.  We prefer
      this as it allows IV elimination - see PRs 66502 and 67167.  */
@@ -4463,7 +4498,7 @@ sccvn_dom_walker::before_dom_children (b
       reachable |= (e->flags & EDGE_EXECUTABLE);
 
   /* If the block is not reachable all outgoing edges are not
-     executable.  */
+     executable.  Neither are incoming edges with src dominated by us.  */
   if (!reachable)
     {
       if (dump_file && (dump_flags & TDF_DETAILS))
@@ -4472,6 +4507,18 @@ sccvn_dom_walker::before_dom_children (b
 
       FOR_EACH_EDGE (e, ei, bb->succs)
        e->flags &= ~EDGE_EXECUTABLE;
+
+      FOR_EACH_EDGE (e, ei, bb->preds)
+       {
+         if (dominated_by_p (CDI_DOMINATORS, e->src, bb))
+           {
+             if (dump_file && (dump_flags & TDF_DETAILS))
+               fprintf (dump_file, "Marking backedge from BB %d into "
+                        "unreachable BB %d as not executable\n",
+                        e->src->index, bb->index);
+             e->flags &= ~EDGE_EXECUTABLE;
+           }
+       }
       return;
     }
 
Index: gcc/testsuite/gcc.dg/torture/pr67221.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr67221.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr67221.c      (working copy)
@@ -0,0 +1,31 @@
+/* { dg-do compile } */
+
+int a, b;
+
+int
+fn1 (int p)
+{
+  return 0 == 0 ? p : 0;
+}
+
+void
+fn2 ()
+{
+  int c = 1, d[1] = { 1 };
+lbl:
+  for (;;)
+    {
+      int e;
+      c ? 0 : 0 / c;
+      c = 0;
+      if (fn1 (d[0]))
+       break;
+      for (e = 0; e < 1; e++)
+       for (c = 1; b;)
+         {
+           if (a)
+             break;
+           goto lbl;
+         }
+    }
+}

Reply via email to