I am testing the following.

Richard.

2018-08-28  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/87126
        * tree-ssa-sccvn.c (vn_reference_insert): Remove assert.

        * gcc.dg/tree-ssa/pr87126.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c        (revision 263917)
+++ gcc/tree-ssa-sccvn.c        (working copy)
@@ -2696,7 +2696,17 @@ vn_reference_insert (tree op, tree resul
      but save a lookup if we deal with already inserted refs here.  */
   if (*slot)
     {
-      gcc_assert (operand_equal_p ((*slot)->result, vr1->result, 0));
+      /* We cannot assert that we have the same value either because
+         when disentangling an irreducible region we may end up visiting
+        a use before the corresponding def.  That's a missed optimization
+        only though.  See gcc.dg/tree-ssa/pr87126.c for example.  */
+      if (dump_file && (dump_flags & TDF_DETAILS)
+         && !operand_equal_p ((*slot)->result, vr1->result, 0))
+       {
+         fprintf (dump_file, "Keeping old value ");
+         print_generic_expr (dump_file, (*slot)->result);
+         fprintf (dump_file, " because of collision\n");
+       }
       free_reference (vr1);
       obstack_free (&vn_tables_obstack, vr1);
       return;
Index: gcc/testsuite/gcc.dg/tree-ssa/pr87126.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/pr87126.c     (nonexistent)
+++ gcc/testsuite/gcc.dg/tree-ssa/pr87126.c     (working copy)
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
+
+int a, *b;
+
+void f ()
+{ 
+  int d = 0, e = d;
+  while (a++)
+    ;
+  if (e)
+    goto L2;
+L1:
+  d = e;
+  b = &d;
+L2:
+  if (d)
+    goto L1;
+}
+
+/* The load of d could be eliminated if we'd value-number the
+   irreducible region in RPO of the reducible result.  Likewise
+   a redundant store could be removed.  */
+/* { dg-final { scan-tree-dump-times "d = 0;" 1 "fre1" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-not " = d;" "fre1" { xfail *-*-* } } } */

Reply via email to