OSDN Git Service

PR tree-optimization/30858
authordorit <dorit@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 22 Feb 2007 08:16:18 +0000 (08:16 +0000)
committerdorit <dorit@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 22 Feb 2007 08:16:18 +0000 (08:16 +0000)
        * tree-vectorizer.c (vect_is_simple_reduction): Check that the stmts
        in the reduction cycle have a single use in the loop.
        * tree-vectorizer.h (relevant): Add documentation.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122220 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr30858.c [new file with mode: 0644]
gcc/tree-vectorizer.c
gcc/tree-vectorizer.h

index 9e43e9e..829872f 100644 (file)
@@ -1,3 +1,10 @@
+2007-02-22  Dorit Nuzman  <dorit@il.ibm.com>
+
+       PR tree-optimization/30858
+       * tree-vectorizer.c (vect_is_simple_reduction): Check that the stmts
+       in the reduction cycle have a single use in the loop.
+       * tree-vectorizer.h (relevant): Add documentation.
+
 2007-02-20  Mike Stump  <mrs@apple.com>
 
        * configure.ac (powerpc*-*-darwin*): #include <sys/cdefs.h>.
index 282d205..8556c43 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-22  Dorit Nuzman  <dorit@il.ibm.com>
+
+        PR tree-optimization/30858
+       * gcc.dg/vect/pr30858.c: New test.
+
 2007-02-21  Mark Mitchell  <mark@codesourcery.com>
 
        * lib/wrapper.exp (${tool}_maybe_build_wrapper): Allow the caller
diff --git a/gcc/testsuite/gcc.dg/vect/pr30858.c b/gcc/testsuite/gcc.dg/vect/pr30858.c
new file mode 100644 (file)
index 0000000..0af2f8e
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+
+int
+foo (int ko)
+{
+ int j,i;
+  for (j = 0; j < ko; j++)
+   i += (i > 10) ? -5 : 7;
+ return i;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 0 loops" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Unknown def-use cycle pattern." 1 "vect" } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
index fab5723..2a53b9c 100644 (file)
@@ -1935,14 +1935,35 @@ vect_is_simple_reduction (struct loop *loop, tree phi)
   int op_type;
   tree operation, op1, op2;
   tree type;
+  int nloop_uses;
+  tree name;
+  imm_use_iterator imm_iter;
+  use_operand_p use_p;
 
-  if (TREE_CODE (loop_arg) != SSA_NAME)
+  name = PHI_RESULT (phi);
+  nloop_uses = 0;
+  FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name)
     {
-      if (vect_print_dump_info (REPORT_DETAILS))
+      tree use_stmt = USE_STMT (use_p);
+      if (flow_bb_inside_loop_p (loop, bb_for_stmt (use_stmt))
+         && vinfo_for_stmt (use_stmt)
+         && !is_pattern_stmt_p (vinfo_for_stmt (use_stmt)))
+        nloop_uses++;
+      if (nloop_uses > 1)
         {
-          fprintf (vect_dump, "reduction: not ssa_name: ");
-          print_generic_expr (vect_dump, loop_arg, TDF_SLIM);
+          if (vect_print_dump_info (REPORT_DETAILS))
+            fprintf (vect_dump, "reduction used in loop.");
+          return NULL_TREE;
         }
+    }
+
+  if (TREE_CODE (loop_arg) != SSA_NAME)
+    {
+      if (vect_print_dump_info (REPORT_DETAILS))
+       {
+         fprintf (vect_dump, "reduction: not ssa_name: ");
+         print_generic_expr (vect_dump, loop_arg, TDF_SLIM);
+       }
       return NULL_TREE;
     }
 
@@ -1950,19 +1971,34 @@ vect_is_simple_reduction (struct loop *loop, tree phi)
   if (!def_stmt)
     {
       if (vect_print_dump_info (REPORT_DETAILS))
-        fprintf (vect_dump, "reduction: no def_stmt.");
+       fprintf (vect_dump, "reduction: no def_stmt.");
       return NULL_TREE;
     }
 
   if (TREE_CODE (def_stmt) != GIMPLE_MODIFY_STMT)
     {
       if (vect_print_dump_info (REPORT_DETAILS))
-        {
-          print_generic_expr (vect_dump, def_stmt, TDF_SLIM);
-        }
+        print_generic_expr (vect_dump, def_stmt, TDF_SLIM);
       return NULL_TREE;
     }
 
+  name = GIMPLE_STMT_OPERAND (def_stmt, 0);
+  nloop_uses = 0;
+  FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name)
+    {
+      tree use_stmt = USE_STMT (use_p);
+      if (flow_bb_inside_loop_p (loop, bb_for_stmt (use_stmt))
+         && vinfo_for_stmt (use_stmt)
+         && !is_pattern_stmt_p (vinfo_for_stmt (use_stmt)))
+       nloop_uses++;
+      if (nloop_uses > 1)
+       {
+         if (vect_print_dump_info (REPORT_DETAILS))
+           fprintf (vect_dump, "reduction used in loop.");
+         return NULL_TREE;
+       }
+    }
+
   operation = GIMPLE_STMT_OPERAND (def_stmt, 1);
   code = TREE_CODE (operation);
   if (!commutative_tree_code (code) || !associative_tree_code (code))
index dd41f2b..4f0e7b9 100644 (file)
@@ -175,7 +175,15 @@ enum stmt_vec_info_type {
 /* Indicates whether/how a variable is used in the loop.  */
 enum vect_relevant {
   vect_unused_in_loop = 0,
+
+  /* defs that feed computations that end up (only) in a reduction. These
+     defs may be used by non-reduction stmts, but eventually, any 
+     computations/values that are affected by these defs are used to compute 
+     a reduction (i.e. don't get stored to memory, for example). We use this 
+     to identify computations that we can change the order in which they are 
+     computed.  */
   vect_used_by_reduction,
+
   vect_used_in_loop  
 };