tree-vect-loop.c (vect_is_simple_reduction_1): Relax the requirement of the reduction...
authorCong Hou <congh@google.com>
Tue, 15 Oct 2013 17:17:43 +0000 (13:17 -0400)
committerCong Hou <congh@gcc.gnu.org>
Tue, 15 Oct 2013 17:17:43 +0000 (13:17 -0400)
2013-10-15  Cong Hou  <congh@google.com>

        * tree-vect-loop.c (vect_is_simple_reduction_1): Relax the
        requirement of the reduction pattern so that one operand of the
        reduction operation can come from outside of the loop.

2013-10-15  Cong Hou  <congh@google.com>

        * gcc.dg/vect/vect-reduc-pattern-3.c: New test.

From-SVN: r203625

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-3.c [new file with mode: 0644]
gcc/tree-vect-loop.c

index 09e2494edcd25ccca0f606b82c38628d90e306cf..7a7033aa5425288bd8ddf4a4b2835e05f020539a 100644 (file)
@@ -1,3 +1,9 @@
+2013-10-15  Cong Hou  <congh@google.com>
+
+       * tree-vect-loop.c (vect_is_simple_reduction_1): Relax the 
+       requirement of the reduction pattern so that one operand of the 
+       reduction operation can come from outside of the loop.
+
 2013-10-15  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * config/arm/neon-schedgen.ml: Remove.
index f290da8ac78c5fb2e47f4fcd1d70532f7aafc8de..eb5eea2c80d2b8cfb06e2d6c28898c37a489cb63 100644 (file)
@@ -1,3 +1,7 @@
+2013-10-15  Cong Hou  <congh@google.com>
+
+       * gcc.dg/vect/vect-reduc-pattern-3.c: New test.
+
 2013-10-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/58707
diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-3.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-pattern-3.c
new file mode 100644 (file)
index 0000000..06a9416
--- /dev/null
@@ -0,0 +1,41 @@
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+#define N 10
+#define RES 1024
+
+/* A reduction pattern in which there is no data ref in
+   the loop and one operand is defined outside of the loop.  */
+
+__attribute__ ((noinline)) int
+foo (int v)
+{
+  int i;
+  int result = 1;
+
+  ++v;
+  for (i = 0; i < N; i++)
+    result *= v;
+
+  return result;
+}
+
+int
+main (void)
+{
+  int res;
+
+  check_vect ();
+
+  res = foo (1);
+  if (res != RES)
+    abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+
index 638b981d5e77d0f4e1748002dd73d30006d6d8ca..d9125f690d2437229ca79a912805ed9226490446 100644 (file)
@@ -2091,6 +2091,13 @@ vect_is_slp_reduction (loop_vec_info loop_info, gimple phi, gimple first_stmt)
      a3 = ...
      a2 = operation (a3, a1)
 
+   or
+
+   a3 = ...
+   loop_header:
+     a1 = phi < a0, a2 >
+     a2 = operation (a3, a1)
+
    such that:
    1. operation is commutative and associative and it is safe to
       change the order of the computation (if CHECK_REDUCTION is true)
@@ -2451,6 +2458,7 @@ vect_is_simple_reduction_1 (loop_vec_info loop_info, gimple phi,
   if (def2 && def2 == phi
       && (code == COND_EXPR
          || !def1 || gimple_nop_p (def1)
+         || !flow_bb_inside_loop_p (loop, gimple_bb (def1))
           || (def1 && flow_bb_inside_loop_p (loop, gimple_bb (def1))
               && (is_gimple_assign (def1)
                  || is_gimple_call (def1)
@@ -2469,6 +2477,7 @@ vect_is_simple_reduction_1 (loop_vec_info loop_info, gimple phi,
   if (def1 && def1 == phi
       && (code == COND_EXPR
          || !def2 || gimple_nop_p (def2)
+         || !flow_bb_inside_loop_p (loop, gimple_bb (def2))
           || (def2 && flow_bb_inside_loop_p (loop, gimple_bb (def2))
              && (is_gimple_assign (def2)
                  || is_gimple_call (def2)