On Tue, 6 Oct 2015, Richard Biener wrote:

> 
> This fixes an ICE in SCCVN - not sure how we got away with not clearing
> new slots...  possibly SSA name recycling triggered.

Ah, it's not supposed to happen.  Bisection shows the cause, fixed
with the following instead.

Bootstrap / regtest pending on x86_64-unknown-linux-gnu.

Richard.

2015-10-06  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/67859
        * tree-ssa-pre.c (create_expression_by_pieces): Properly
        discard not inserted stmts.

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

Index: gcc/testsuite/gcc.dg/torture/pr67859.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr67859.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr67859.c      (working copy)
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+int a, b, c;
+
+void
+fn1 ()
+{
+  b = c ? 0 : 1 << a;
+  b |= 0x9D7A5FD9;
+  for (;;)
+    {
+      int d = 1;
+      b &= (unsigned) d;
+    }
+}
Index: gcc/tree-ssa-pre.c
===================================================================
*** gcc/tree-ssa-pre.c  (revision 228514)
--- gcc/tree-ssa-pre.c  (working copy)
*************** create_expression_by_pieces (basic_block
*** 2897,2907 ****
  
    folded = gimple_convert (&forced_stmts, exprtype, folded);
  
!   /* If everything simplified to an exisiting SSA name or constant just
!      return that.  */
!   if (gimple_seq_empty_p (forced_stmts)
!       || is_gimple_min_invariant (folded))
      return folded;
  
    gcc_assert (TREE_CODE (folded) == SSA_NAME);
  
--- 2897,2912 ----
  
    folded = gimple_convert (&forced_stmts, exprtype, folded);
  
!   /* If there is nothing to insert, return the simplified result.  */
!   if (gimple_seq_empty_p (forced_stmts))
      return folded;
+   /* If we simplified to a constant return it and discard eventually
+      built stmts.  */
+   if (is_gimple_min_invariant (folded))
+     {
+       gimple_seq_discard (forced_stmts);
+       return folded;
+     }
  
    gcc_assert (TREE_CODE (folded) == SSA_NAME);
  

Reply via email to