[PATCH] Some vectorizable_reduction TLC

Richard Biener rguenther@suse.de
Wed Nov 6 12:56:00 GMT 2019


Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2019-11-06  Richard Biener  <rguenther@suse.de>

	* tree-vect-loop.c (vectorizable_reduction): Remember reduction
	PHI.  Use STMT_VINFO_REDUC_IDX to skip the reduction operand.
	Simplify single_defuse_cycle condition.

Index: gcc/tree-vect-loop.c
===================================================================
--- gcc/tree-vect-loop.c	(revision 277874)
+++ gcc/tree-vect-loop.c	(working copy)
@@ -5725,6 +5725,7 @@ vectorizable_reduction (stmt_vec_info st
     }
 
   stmt_vec_info orig_stmt_of_analysis = stmt_info;
+  stmt_vec_info phi_info = stmt_info;
   if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def
       || STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def)
     {
@@ -5749,8 +5750,8 @@ vectorizable_reduction (stmt_vec_info st
 	  bool res = single_imm_use (gimple_phi_result (stmt_info->stmt),
 				     &use_p, &use_stmt);
 	  gcc_assert (res);
-	  stmt_info = loop_vinfo->lookup_stmt (use_stmt);
-	  stmt_info = vect_stmt_to_vectorize (STMT_VINFO_REDUC_DEF (stmt_info));
+	  phi_info = loop_vinfo->lookup_stmt (use_stmt);
+	  stmt_info = vect_stmt_to_vectorize (STMT_VINFO_REDUC_DEF (phi_info));
 	}
       /* STMT_VINFO_REDUC_DEF doesn't point to the first but the last
          element.  */
@@ -5760,6 +5761,8 @@ vectorizable_reduction (stmt_vec_info st
 	  stmt_info = REDUC_GROUP_FIRST_ELEMENT (stmt_info);
 	}
     }
+  /* PHIs should not participate in patterns.  */
+  gcc_assert (!STMT_VINFO_RELATED_STMT (phi_info));
 
   if (nested_in_vect_loop_p (loop, stmt_info))
     {
@@ -5822,9 +5825,6 @@ vectorizable_reduction (stmt_vec_info st
      The last use is the reduction variable.  In case of nested cycle this
      assumption is not true: we use reduc_index to record the index of the
      reduction variable.  */
-  stmt_vec_info phi_info = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info));
-  /* PHIs should not participate in patterns.  */
-  gcc_assert (!STMT_VINFO_RELATED_STMT (phi_info));
   gphi *reduc_def_phi = as_a <gphi *> (phi_info->stmt);
 
   /* Verify following REDUC_IDX from the latch def leads us back to the PHI
@@ -5873,11 +5873,8 @@ vectorizable_reduction (stmt_vec_info st
 			     "use not simple.\n");
 	  return false;
 	}
-      if ((dt == vect_reduction_def || dt == vect_nested_cycle)
-	  && op == reduc_def)
-	{
-	  continue;
-	}
+      if (i == STMT_VINFO_REDUC_IDX (stmt_info))
+	continue;
 
       /* There should be only one cycle def in the stmt, the one
          leading to reduc_def.  */
@@ -6338,14 +6335,9 @@ vectorizable_reduction (stmt_vec_info st
    This only works when we see both the reduction PHI and its only consumer
    in vectorizable_reduction and there are no intermediate stmts
    participating.  */
-  stmt_vec_info use_stmt_info;
-  tree reduc_phi_result = gimple_phi_result (reduc_def_phi);
   if (ncopies > 1
       && (STMT_VINFO_RELEVANT (stmt_info) <= vect_used_only_live)
-      && (use_stmt_info = loop_vinfo->lookup_single_use (reduc_phi_result))
-      && (!STMT_VINFO_IN_PATTERN_P (use_stmt_info)
-	  || !STMT_VINFO_PATTERN_DEF_SEQ (use_stmt_info))
-      && vect_stmt_to_vectorize (use_stmt_info) == stmt_info)
+      && reduc_chain_length == 1)
     single_defuse_cycle = true;
 
   if (single_defuse_cycle || lane_reduc_code_p)



More information about the Gcc-patches mailing list