I am testing the following to fix PR81053.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2017-06-12  Richard Biener  <rguent...@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.

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c        (revision 249112)
+++ gcc/tree-vect-loop.c        (working copy)
@@ -2790,15 +2790,17 @@ vect_is_simple_reduction (loop_vec_info
     }
 
   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
       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.  */
Index: gcc/testsuite/gcc.dg/torture/pr81053.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr81053.c      (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr81053.c      (working copy)
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+int a, b[2], c, d;
+
+void fn1 ()
+{ 
+  for (; d < 2; d++)
+    { 
+      b[d] = a;
+      a = c;
+    }
+}

Reply via email to