The following fixes PR69173.

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

Richard.

2016-01-11  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/69173
        * tree-vect-loop.c (vect_fixup_scalar_cycles_with_patterns): Only
        fixup the cycle if all stmts are in a pattern.

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

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c        (revision 232213)
+++ gcc/tree-vect-loop.c        (working copy)
@@ -985,9 +985,21 @@ vect_fixup_scalar_cycles_with_patterns (
   FOR_EACH_VEC_ELT (LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo), i, first)
     if (STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (first)))
       {
-       vect_fixup_reduc_chain (first);
-       LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo)[i]
-         = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (first));
+       gimple *next = GROUP_NEXT_ELEMENT (vinfo_for_stmt (first));
+       while (next)
+         {
+           if (! STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (next)))
+             break;
+           next = GROUP_NEXT_ELEMENT (vinfo_for_stmt (next));
+         }
+       /* If not all stmt in the chain are patterns try to handle
+          the chain without patterns.  */
+       if (! next)
+         {
+           vect_fixup_reduc_chain (first);
+           LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo)[i]
+             = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (first));
+         }
       }
 }
 
Index: gcc/testsuite/gcc.dg/torture/pr69173.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr69173.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr69173.c      (working copy)
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+unsigned a;
+unsigned *b;
+void fn1() {
+    char c;
+    while (b < (unsigned *)fn1)
+      {
+       a += b[2] + c;
+       b++;
+      }
+}

Reply via email to