The following fixes PR82473 - we were using a random (the first
non-reduction) operand of the reduction stmt to compute ncopies
but that's of course wrong.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2017-10-20  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/82473
        * tree-vect-loop.c (vectorizable_reduction): Properly get at
        the largest input type.

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

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c        (revision 253926)
+++ gcc/tree-vect-loop.c        (working copy)
@@ -5836,9 +5836,12 @@ vectorizable_reduction (gimple *stmt, gi
          reduc_index = i;
          continue;
        }
-      else
+      else if (tem)
        {
-         if (!vectype_in)
+         /* To properly compute ncopies we are interested in the widest
+            input type in case we're looking at a widening accumulation.  */
+         if (!vectype_in
+             || TYPE_VECTOR_SUBPARTS (vectype_in) > TYPE_VECTOR_SUBPARTS (tem))
            vectype_in = tem;
        }
 
Index: gcc/testsuite/gcc.dg/torture/pr82473.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr82473.c      (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr82473.c      (working copy)
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ftree-vectorize" } */
+
+void
+zz (int x9, short int gt)
+{
+  if (0)
+    {
+      while (gt < 1)
+       {
+         int pz;
+
+k6:
+         for (pz = 0; pz < 3; ++pz)
+           x9 += gt;
+         ++gt;
+       }
+    }
+
+  if (x9 != 0)
+    goto k6;
+}

Reply via email to