re PR tree-optimization/49087 (crash in vect_is_slp_reduction)
authorIra Rosen <ira.rosen@linaro.org>
Sun, 22 May 2011 08:04:43 +0000 (08:04 +0000)
committerIra Rosen <irar@gcc.gnu.org>
Sun, 22 May 2011 08:04:43 +0000 (08:04 +0000)
        PR tree-optimization/49087
        * tree-vect-loop.c (vect_is_slp_reduction): Fail if
        LHS has no uses.

From-SVN: r174026

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/O3-pr49087.c [new file with mode: 0644]
gcc/tree-vect-loop.c

index 789f258da3984e42bb2f3f653f6002c1c6a70cef..1ea25e418d448f45371144ebcab193d2f4785b85 100644 (file)
@@ -1,3 +1,9 @@
+2011-05-22  Ira Rosen  <ira.rosen@linaro.org>
+
+       PR tree-optimization/49087
+       * tree-vect-loop.c (vect_is_slp_reduction): Fail if
+       LHS has no uses.
+
 2011-05-21  Jason Merrill  <jason@redhat.com>
 
        PR c++/49092
index ccc34a7bae35dae4fb007cbaa00ed3b9e1adee92..0d937892dd2750448e8a24bae5802b5956bce35d 100644 (file)
@@ -1,3 +1,8 @@
+2011-05-22  Ira Rosen  <ira.rosen@linaro.org>
+
+       PR tree-optimization/49087
+       * gcc.dg/vect/O3-pr49087.c: New test.
+
 2011-05-21  Jason Merrill  <jason@redhat.com>
 
        * g++.dg/debug/const5.C: New.
diff --git a/gcc/testsuite/gcc.dg/vect/O3-pr49087.c b/gcc/testsuite/gcc.dg/vect/O3-pr49087.c
new file mode 100644 (file)
index 0000000..c897fbc
--- /dev/null
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+
+static char func2() { }
+
+struct S0
+{
+ int t;
+};
+
+int g;
+
+struct S0 s0;
+
+int 
+foo (int arg)
+{
+  int *ptr = &g;
+  int i, j;
+  for (i = 0; i < 10; i += 1)
+    {
+      for (j = 0; j < 1; j += 1)
+       {
+         int k;
+         if (arg)
+           {
+             int l;
+             for (k = 1; arg < 10; arg = func2 ())
+               {
+                 return l;
+               }
+           }
+         *ptr = func2 () ^ s0.t;
+       }
+    }
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
index 9942ebe815189d4ef232d2e04cd1c96f63c31985..98bb113629e492afdac00b37922ab68c600932af 100644 (file)
@@ -1704,7 +1704,7 @@ vect_is_slp_reduction (loop_vec_info loop_info, gimple phi, gimple first_stmt)
   tree lhs;
   imm_use_iterator imm_iter;
   use_operand_p use_p;
-  int nloop_uses, size = 0;
+  int nloop_uses, size = 0, nuses;
   bool found = false;
 
   if (loop != vect_loop)
@@ -1715,9 +1715,11 @@ vect_is_slp_reduction (loop_vec_info loop_info, gimple phi, gimple first_stmt)
   while (1)
     {
       nloop_uses = 0;
+      nuses = 0;
       FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs)
         {
           use_stmt = USE_STMT (use_p);
+          nuses++;
           if (is_gimple_debug (use_stmt))
             continue;
 
@@ -1739,6 +1741,10 @@ vect_is_slp_reduction (loop_vec_info loop_info, gimple phi, gimple first_stmt)
             return false;
         }
 
+      /* We reached a statement with no uses.  */
+      if (nuses == 0)
+       return false;
+
       if (found)
         break;