The following fixes the assumption that we consistently have patterns
used in SLP.  That's not true given we skip them if the original
def is life or relevant during SLP analysis.

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

Richard.

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

        PR tree-optimization/69168
        * tree-vect-loop.c (vect_analyze_loop_2): Reset both main and
        pattern stmt SLP type.
        * tree-vect-slp.c (vect_detect_hybrid_slp_stmts): Patterns may
        end up unused so cope with that case.

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

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c        (revision 232231)
+++ gcc/tree-vect-loop.c        (working copy)
@@ -2189,10 +2189,11 @@ again:
           !gsi_end_p (si); gsi_next (&si))
        {
          stmt_vec_info stmt_info = vinfo_for_stmt (gsi_stmt (si));
+         STMT_SLP_TYPE (stmt_info) = loop_vect;
          if (STMT_VINFO_IN_PATTERN_P (stmt_info))
            {
-             gcc_assert (STMT_SLP_TYPE (stmt_info) == loop_vect);
              stmt_info = vinfo_for_stmt (STMT_VINFO_RELATED_STMT (stmt_info));
+             STMT_SLP_TYPE (stmt_info) = loop_vect;
              for (gimple_stmt_iterator pi
                     = gsi_start (STMT_VINFO_PATTERN_DEF_SEQ (stmt_info));
                   !gsi_end_p (pi); gsi_next (&pi))
@@ -2201,7 +2202,6 @@ again:
                  STMT_SLP_TYPE (vinfo_for_stmt (pstmt)) = loop_vect;
                }
            }
-         STMT_SLP_TYPE (stmt_info) = loop_vect;
        }
     }
   /* Free optimized alias test DDRS.  */
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c (revision 232231)
+++ gcc/tree-vect-slp.c (working copy)
@@ -2016,10 +2016,10 @@ vect_detect_hybrid_slp_stmts (slp_tree n
     {
       /* Check if a pure SLP stmt has uses in non-SLP stmts.  */
       gcc_checking_assert (PURE_SLP_STMT (stmt_vinfo));
-      /* We always get the pattern stmt here, but for immediate
-        uses we have to use the LHS of the original stmt.  */
-      gcc_checking_assert (!STMT_VINFO_IN_PATTERN_P (stmt_vinfo));
-      if (STMT_VINFO_RELATED_STMT (stmt_vinfo))
+      /* If we get a pattern stmt here we have to use the LHS of the
+         original stmt for immediate uses.  */
+      if (! STMT_VINFO_IN_PATTERN_P (stmt_vinfo)
+         && STMT_VINFO_RELATED_STMT (stmt_vinfo))
        stmt = STMT_VINFO_RELATED_STMT (stmt_vinfo);
       if (TREE_CODE (gimple_op (stmt, 0)) == SSA_NAME)
        FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, gimple_op (stmt, 0))
Index: gcc/testsuite/gcc.dg/torture/pr69168.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr69168.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr69168.c      (working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+long a, b, e;
+short *c;
+int *d;
+void fn1()
+{
+  int i;
+  for (; e; e--)
+    {
+      i = 2;
+      for (; i; i--)
+       a = b = *d++ / (1 << 9);
+      b = b ? 8 : a;
+      *c++ = *c++ = b;
+    }
+}

Reply via email to