Once again the vectorizer isn't prepared to vectorize dead code.
Fortunately in this case it's easy to fix - just remove the assert
that triggers and continue doing nothing for the non-existing
use of the reduction result.

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

Richard.

2013-08-30  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/58010
        * tree-vect-loop.c (vect_create_epilog_for_reduction): Remove
        assert that we have a loop-closed PHI.

        * gcc.dg/pr58010.c: New testcase.

Index: gcc/tree-vect-loop.c
===================================================================
*** gcc/tree-vect-loop.c        (revision 202068)
--- gcc/tree-vect-loop.c        (working copy)
*************** vect_finalize_reduction:
*** 4373,4381 ****
          if (!flow_bb_inside_loop_p (loop, gimple_bb (USE_STMT (use_p))))
            phis.safe_push (USE_STMT (use_p));
  
!       /* We expect to have found an exit_phi because of loop-closed-ssa
!          form.  */
!       gcc_assert (!phis.is_empty ());
  
        FOR_EACH_VEC_ELT (phis, i, exit_phi)
          {
--- 4373,4380 ----
          if (!flow_bb_inside_loop_p (loop, gimple_bb (USE_STMT (use_p))))
            phis.safe_push (USE_STMT (use_p));
  
!       /* While we expect to have found an exit_phi because of loop-closed-ssa
!          form we can end up without one if the scalar cycle is dead.  */
  
        FOR_EACH_VEC_ELT (phis, i, exit_phi)
          {
Index: gcc/testsuite/gcc.dg/pr58010.c
===================================================================
*** gcc/testsuite/gcc.dg/pr58010.c      (revision 0)
--- gcc/testsuite/gcc.dg/pr58010.c      (working copy)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -funswitch-loops -ftree-vectorize" } */
+ 
+ short a, b, c, d;
+ 
+ void f(void)
+ {
+   short e;
+ 
+   for(; e; e++)
+     for(; b; b++);
+ 
+   for(d = 0; d < 4; d++)
+     a ^= (e ^= 1) || c ? : e;
+ }

Reply via email to