This fixes PR60382 where the vectorizer identified a double-reduction
it cannot later re-identify properly.  The only reasonable fix at this
point is to not identify that as a double-reduction.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk,
will apply to branch after testing there.

Richard.

2014-03-04  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/60382
        * tree-vect-loop.c (vect_is_simple_reduction_1): Do not consider
        dead PHIs a reduction.

        * gcc.dg/vect/pr60382.c: New testcase.

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c        (revision 208269)
+++ gcc/tree-vect-loop.c        (working copy)
@@ -2193,6 +2193,12 @@ vect_is_simple_reduction_1 (loop_vec_inf
               || (!check_reduction && flow_loop_nested_p (vect_loop, loop)));
 
   name = PHI_RESULT (phi);
+  /* ???  If there are no uses of the PHI result the inner loop reduction
+     won't be detected as possibly double-reduction by vectorizable_reduction
+     because that tries to walk the PHI arg from the preheader edge which
+     can be constant.  See PR60382.  */
+  if (has_zero_uses (name))
+    return NULL;
   nloop_uses = 0;
   FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name)
     {
Index: gcc/testsuite/gcc.dg/vect/pr60382.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/pr60382.c (revision 0)
+++ gcc/testsuite/gcc.dg/vect/pr60382.c (working copy)
@@ -0,0 +1,32 @@
+#include "tree-vect.h"
+
+int a, b, c, e, f;
+
+void
+foo ()
+{
+  for (b = 0; b < 3; b++)
+    if (e)
+      {
+       for (c = 0; c < 4; c++)
+         {
+           if (b)
+             continue;
+           f = 1;
+           for (a = 0; a < 2; a++)
+             f |= 1;
+         }
+       for (;;)
+         ;
+      }
+}
+
+int
+main ()
+{
+  check_vect ();
+  foo ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */

Reply via email to