re PR tree-optimization/81053 (ICE on valid code at -O3 on x86_64-linux-gnu: in as_a...
authorRichard Biener <rguenther@suse.de>
Mon, 12 Jun 2017 10:42:57 +0000 (10:42 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 12 Jun 2017 10:42:57 +0000 (10:42 +0000)
2017-06-12  Richard Biener  <rguenther@suse.de>

PR tree-optimization/81053
* tree-vect-loop.c (vect_is_simple_reduction): Handle PHI
with backedge value not defined in loop.  Simplify def stmt
compute.

* gcc.dg/torture/pr81053.c: New testcase.

From-SVN: r249113

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

index 192e869..9a95c6c 100644 (file)
@@ -1,3 +1,10 @@
+2017-06-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/81053
+       * tree-vect-loop.c (vect_is_simple_reduction): Handle PHI
+       with backedge value not defined in loop.  Simplify def stmt
+       compute.
+
 2017-06-11  Tom de Vries  <tom@codesourcery.com>
 
        PR target/79939
index 531c787..71be107 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/81053
+       * gcc.dg/torture/pr81053.c: New testcase.
+
 2017-06-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/80988
diff --git a/gcc/testsuite/gcc.dg/torture/pr81053.c b/gcc/testsuite/gcc.dg/torture/pr81053.c
new file mode 100644 (file)
index 0000000..98ab95d
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+int a, b[2], c, d;
+
+void fn1 ()
+{ 
+  for (; d < 2; d++)
+    { 
+      b[d] = a;
+      a = c;
+    }
+}
index 64cf05d..cf9cd3b 100644 (file)
@@ -2790,15 +2790,17 @@ vect_is_simple_reduction (loop_vec_info loop_info, gimple *phi,
     }
 
   def_stmt = SSA_NAME_DEF_STMT (loop_arg);
-  if (gimple_nop_p (def_stmt))
+  if (is_gimple_assign (def_stmt))
     {
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                        "reduction: no def_stmt\n");
-      return NULL;
+      name = gimple_assign_lhs (def_stmt);
+      phi_def = false;
     }
-
-  if (!is_gimple_assign (def_stmt) && gimple_code (def_stmt) != GIMPLE_PHI)
+  else if (gimple_code (def_stmt) == GIMPLE_PHI)
+    {
+      name = PHI_RESULT (def_stmt);
+      phi_def = true;
+    }
+  else
     {
       if (dump_enabled_p ())
        {
@@ -2809,37 +2811,27 @@ vect_is_simple_reduction (loop_vec_info loop_info, gimple *phi,
       return NULL;
     }
 
-  if (is_gimple_assign (def_stmt))
-    {
-      name = gimple_assign_lhs (def_stmt);
-      phi_def = false;
-    }
-  else
-    {
-      name = PHI_RESULT (def_stmt);
-      phi_def = true;
-    }
-
   nloop_uses = 0;
   auto_vec<gphi *, 3> lcphis;
-  FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name)
-    {
-      gimple *use_stmt = USE_STMT (use_p);
-      if (is_gimple_debug (use_stmt))
-       continue;
-      if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
-       nloop_uses++;
-      else
-       /* We can have more than one loop-closed PHI.  */
-       lcphis.safe_push (as_a <gphi *> (use_stmt));
-      if (nloop_uses > 1)
-       {
-         if (dump_enabled_p ())
-           dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                            "reduction used in loop.\n");
-         return NULL;
-       }
-    }
+  if (flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)))
+    FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name)
+      {
+       gimple *use_stmt = USE_STMT (use_p);
+       if (is_gimple_debug (use_stmt))
+         continue;
+       if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
+         nloop_uses++;
+       else
+         /* We can have more than one loop-closed PHI.  */
+         lcphis.safe_push (as_a <gphi *> (use_stmt));
+       if (nloop_uses > 1)
+         {
+           if (dump_enabled_p ())
+             dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                              "reduction used in loop.\n");
+           return NULL;
+         }
+      }
 
   /* If DEF_STMT is a phi node itself, we expect it to have a single argument
      defined in the inner loop.  */