This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix vectorizable_reduction (PR tree-optimization/56350)


Hi!

On the following testcase, a = a / 8; looks like reasonable reduction
statement, but we pattern recognize it as
patt_1 = a < 0 ? 7 : 0;
patt_2 = a + patt_1;
a = patt2 >> 3;
and in the first pattern stmt the reduction operand is in the condition of
COND_EXPR, not operands as vectorizable_reduction was asserting.  Generally,
it couldn't be used anywhere in a pattern stmt, it could be just some
preparation statement.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2013-02-18  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/56350
	* tree-vect-loop.c (vectorizable_reduction): If orig_stmt, return false
	if haven't found reduction or nested cycle operand, rather than
	asserting we must find it.

	* gcc.dg/pr56350.c: New test.

--- gcc/tree-vect-loop.c.jj	2013-01-15 10:30:19.000000000 +0100
+++ gcc/tree-vect-loop.c	2013-02-18 11:32:30.306566358 +0100
@@ -4692,7 +4692,7 @@ vectorizable_reduction (gimple stmt, gim
      The last use is the reduction variable.  In case of nested cycle this
      assumption is not true: we use reduc_index to record the index of the
      reduction variable.  */
-  for (i = 0; i < op_type-1; i++)
+  for (i = 0; i < op_type - 1; i++)
     {
       /* The condition of COND_EXPR is checked in vectorizable_condition().  */
       if (i == 0 && code == COND_EXPR)
@@ -4724,11 +4724,18 @@ vectorizable_reduction (gimple stmt, gim
   if (!vectype_in)
     vectype_in = tem;
   gcc_assert (is_simple_use);
-  gcc_assert (dt == vect_reduction_def
-              || dt == vect_nested_cycle
-              || ((dt == vect_internal_def || dt == vect_external_def
-                   || dt == vect_constant_def || dt == vect_induction_def)
-                   && nested_cycle && found_nested_cycle_def));
+  if (!(dt == vect_reduction_def
+	|| dt == vect_nested_cycle
+	|| ((dt == vect_internal_def || dt == vect_external_def
+	     || dt == vect_constant_def || dt == vect_induction_def)
+	    && nested_cycle && found_nested_cycle_def)))
+    {
+      /* For pattern recognized stmts, orig_stmt might be a reduction,
+	 but some helper statements for the pattern might not, or
+	 might be COND_EXPRs with reduction uses in the condition.  */
+      gcc_assert (orig_stmt);
+      return false;
+    }
   if (!found_nested_cycle_def)
     reduc_def_stmt = def_stmt;
 
--- gcc/testsuite/gcc.dg/pr56350.c.jj	2013-02-18 11:30:12.117327599 +0100
+++ gcc/testsuite/gcc.dg/pr56350.c	2013-02-18 11:29:59.000000000 +0100
@@ -0,0 +1,13 @@
+/* PR tree-optimization/56350 */
+/* { dg-do compile } */
+/* { dg-options "-O -ftree-vectorize" } */
+
+int a, b, c;
+
+void
+f (void)
+{
+  for (; c; c++)
+    for (b = 0; b < 2; b++)
+      a /= 8;
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]