Simplify intereaved store vectorization processing

Message ID 20230822131900.977183858D1E@sourceware.org
State Accepted
Headers
Series Simplify intereaved store vectorization processing |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Richard Biener Aug. 22, 2023, 1:18 p.m. UTC
  When doing interleaving we perform code generation when visiting the
last store of a chain.  We keep track of this via DR_GROUP_STORE_COUNT,
the following localizes this to the caller of vectorizable_store,
also avoing redundant non-processing of the other stores.

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

	* tree-vect-stmts.cc (vectorizable_store): Do not bump
	DR_GROUP_STORE_COUNT here.  Remove early out.
	(vect_transform_stmt): Only call vectorizable_store on
	the last element of an interleaving chain.
---
 gcc/tree-vect-stmts.cc | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)
  

Patch

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 33f62b77710..43502dc169f 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -8429,24 +8429,11 @@  vectorizable_store (vec_info *vinfo,
   else if (STMT_VINFO_SIMD_LANE_ACCESS_P (stmt_info) >= 3)
     return vectorizable_scan_store (vinfo, stmt_info, gsi, vec_stmt, ncopies);
 
-  if (STMT_VINFO_GROUPED_ACCESS (stmt_info))
-    DR_GROUP_STORE_COUNT (DR_GROUP_FIRST_ELEMENT (stmt_info))++;
-
   if (grouped_store)
     {
       /* FORNOW */
       gcc_assert (!loop || !nested_in_vect_loop_p (loop, stmt_info));
 
-      /* We vectorize all the stmts of the interleaving group when we
-	 reach the last stmt in the group.  */
-      if (DR_GROUP_STORE_COUNT (first_stmt_info)
-	  < DR_GROUP_SIZE (first_stmt_info)
-	  && !slp)
-	{
-	  *vec_stmt = NULL;
-	  return true;
-	}
-
       if (slp)
         {
           grouped_store = false;
@@ -12487,21 +12474,22 @@  vect_transform_stmt (vec_info *vinfo,
       break;
 
     case store_vec_info_type:
-      done = vectorizable_store (vinfo, stmt_info,
-				 gsi, &vec_stmt, slp_node, NULL);
-      gcc_assert (done);
-      if (STMT_VINFO_GROUPED_ACCESS (stmt_info) && !slp_node)
+      if (STMT_VINFO_GROUPED_ACCESS (stmt_info)
+	  && !slp_node
+	  && (++DR_GROUP_STORE_COUNT (DR_GROUP_FIRST_ELEMENT (stmt_info))
+	      < DR_GROUP_SIZE (DR_GROUP_FIRST_ELEMENT (stmt_info))))
+	/* In case of interleaving, the whole chain is vectorized when the
+	   last store in the chain is reached.  Store stmts before the last
+	   one are skipped, and there vec_stmt_info shouldn't be freed
+	   meanwhile.  */
+	;
+      else
 	{
-	  /* In case of interleaving, the whole chain is vectorized when the
-	     last store in the chain is reached.  Store stmts before the last
-	     one are skipped, and there vec_stmt_info shouldn't be freed
-	     meanwhile.  */
-	  stmt_vec_info group_info = DR_GROUP_FIRST_ELEMENT (stmt_info);
-	  if (DR_GROUP_STORE_COUNT (group_info) == DR_GROUP_SIZE (group_info))
-	    is_store = true;
+	  done = vectorizable_store (vinfo, stmt_info,
+				     gsi, &vec_stmt, slp_node, NULL);
+	  gcc_assert (done);
+	  is_store = true;
 	}
-      else
-	is_store = true;
       break;
 
     case condition_vec_info_type: