Patchwork Fix PR tree-optimization/49926

login
register
mail settings
Submitter Ira Rosen
Date Aug. 1, 2011, 4:59 p.m.
Message ID <OF833544DB.8E8CDE67-ONC22578DF.005A4A04-C22578DF.005D4AD0@il.ibm.com>
Download mbox | patch
Permalink /patch/107784/
State New
Headers show

Comments

Ira Rosen - Aug. 1, 2011, 4:59 p.m.
Hi,

This patch  adds another missing check for SLP reduction detection: we
should check that a statement in a reduction chain has either one use
inside the loop, or two uses: in the reduction phi node and the loop exit
phi node.

Bootstrapped and tested on powerpc64-suse-linux.
Applied to trunk.

Ira

ChangeLog:

	PR tree-optimization/49926
	* tree-vect-loop.c (vect_is_slp_reduction): Check that a statement
	in a chain doesn't have uses both inside and outside the loop.

testsuite/ChangeLog:

	PR tree-optimization/49926
	* gcc.dg/vect/pr49926.c: New test.

Patch

Index: tree-vect-loop.c
===================================================================
--- tree-vect-loop.c    (revision 177062)
+++ tree-vect-loop.c    (working copy)
@@ -1730,7 +1730,7 @@  vect_is_slp_reduction (loop_vec_info loop_info, gi
   tree lhs;
   imm_use_iterator imm_iter;
   use_operand_p use_p;
-  int nloop_uses, size = 0;
+  int nloop_uses, size = 0, n_out_of_loop_uses;
   bool found = false;

   if (loop != vect_loop)
@@ -1741,6 +1741,7 @@  vect_is_slp_reduction (loop_vec_info loop_info, gi
   while (1)
     {
       nloop_uses = 0;
+      n_out_of_loop_uses = 0;
       FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs)
         {
          gimple use_stmt = USE_STMT (use_p);
@@ -1757,16 +1758,22 @@  vect_is_slp_reduction (loop_vec_info loop_info, gi
               break;
             }

-          if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt))
-              && vinfo_for_stmt (use_stmt)
-             && !STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (use_stmt)))
-           {
-             loop_use_stmt = use_stmt;
-             nloop_uses++;
-           }
+          if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
+            {
+              if (vinfo_for_stmt (use_stmt)
+                  && !STMT_VINFO_IN_PATTERN_P (vinfo_for_stmt (use_stmt)))
+                {
+                  loop_use_stmt = use_stmt;
+                  nloop_uses++;
+                }
+            }
+           else
+             n_out_of_loop_uses++;

-          if (nloop_uses > 1)
-            return false;
+           /* There are can be either a single use in the loop or two uses
in
+              phi nodes.  */
+           if (nloop_uses > 1 || (n_out_of_loop_uses && nloop_uses))
+             return false;
         }

       if (found)
Index: testsuite/gcc.dg/vect/pr49926.c
===================================================================
--- testsuite/gcc.dg/vect/pr49926.c     (revision 0)
+++ testsuite/gcc.dg/vect/pr49926.c     (revision 0)
@@ -0,0 +1,23 @@ 
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+
+int a, b, c[10];
+
+void
+foo (unsigned int x, int y, int z, int *w)
+{
+  do
+    {
+      *w = z;
+      y = x;
+      if (y)
+        for (b = -4; b; b++)
+          {
+            z = y &= a &= 1;
+            y &= c[b + 4];
+          }
+    }
+  while (1);
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */