Remove group_size argument from vect_built_slp_tree* APIs

Message ID n8o900q7-1646-2q53-o6s8-818pr81s19o0@fhfr.qr
State Committed
Commit b026344b5e7bbffc9433e16ebb84ca7e14957c6a
Headers
Series Remove group_size argument from vect_built_slp_tree* APIs |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap fail Build failed
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Richard Biener July 8, 2026, 12:32 p.m. UTC
  The group_size argument is redundant with the stmt vector length.

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

This is because there's confusion about what group_size is,
the number of scalar lanes or the number of statements.  With
statements becoming possibly vector stmts how did you handle
group_size?  If the argument becomes useful there we should
probably rename it?

	* tree-vect-slp.cc (vect_build_slp_tree_1): Remove group_size
	argument and adjust.
	(vect_build_slp_tree_2): Likewise.
	(vect_build_slp_tree): Likewise.
	(optimize_load_redistribution_1): Likewise.
	(vect_build_slp_instance): Likewise.
	(vect_analyze_slp_reduc_chain): Likewise.
	(vect_analyze_slp_reduction): Likewise.
	(vect_analyze_slp_reduction_group): Likewise.
	(vect_analyze_slp_instance): Likewise.
	(vect_lower_load_permutations): Likewise.
---
 gcc/tree-vect-slp.cc | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)
  

Comments

Tamar Christina July 8, 2026, 12:46 p.m. UTC | #1
> -----Original Message-----
> From: Richard Biener <rguenther@suse.de>
> Sent: 08 July 2026 13:33
> To: gcc-patches@gcc.gnu.org
> Cc: Tamar Christina <Tamar.Christina@arm.com>
> Subject: [PATCH] Remove group_size argument from vect_built_slp_tree* APIs
> 
> The group_size argument is redundant with the stmt vector length.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> 
> This is because there's confusion about what group_size is,
> the number of scalar lanes or the number of statements.  With
> statements becoming possibly vector stmts how did you handle
> group_size?  If the argument becomes useful there we should
> probably rename it?
> 

Thanks I think it's better to indeed remove it, since I was trying to figure out
how to deal with SLP build for VLA vector statements and group_size was
definitely an issue.

So LGTM!

Thanks,
Tamar

> 	* tree-vect-slp.cc (vect_build_slp_tree_1): Remove group_size
> 	argument and adjust.
> 	(vect_build_slp_tree_2): Likewise.
> 	(vect_build_slp_tree): Likewise.
> 	(optimize_load_redistribution_1): Likewise.
> 	(vect_build_slp_instance): Likewise.
> 	(vect_analyze_slp_reduc_chain): Likewise.
> 	(vect_analyze_slp_reduction): Likewise.
> 	(vect_analyze_slp_reduction_group): Likewise.
> 	(vect_analyze_slp_instance): Likewise.
> 	(vect_lower_load_permutations): Likewise.
> ---
>  gcc/tree-vect-slp.cc | 41 +++++++++++++++++++++--------------------
>  1 file changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
> index 0266e75888c..ff11b392305 100644
> --- a/gcc/tree-vect-slp.cc
> +++ b/gcc/tree-vect-slp.cc
> @@ -1147,10 +1147,11 @@ vect_record_max_nunits (vec_info *vinfo,
> stmt_vec_info stmt_info,
> 
>  static bool
>  vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
> -		       vec<stmt_vec_info> stmts, unsigned int group_size,
> +		       vec<stmt_vec_info> stmts,
>  		       poly_uint64 *max_nunits, bool *matches,
>  		       bool *two_operators, tree *node_vectype)
>  {
> +  unsigned int group_size = stmts.length ();
>    unsigned int i;
>    stmt_vec_info first_stmt_info = stmts[0];
>    code_helper first_stmt_code = ERROR_MARK;
> @@ -1881,18 +1882,19 @@ static unsigned
> least_upthread_swappable_op_distance = -1U;
> 
>  static slp_tree
>  vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
> -		       vec<stmt_vec_info> stmts, unsigned int group_size,
> +		       vec<stmt_vec_info> stmts,
>  		       poly_uint64 *max_nunits,
>  		       bool *matches, unsigned *limit, unsigned *tree_size,
>  		       scalar_stmts_to_slp_tree_map_t *bst_map);
> 
>  static slp_tree
>  vect_build_slp_tree (vec_info *vinfo,
> -		     vec<stmt_vec_info> stmts, unsigned int group_size,
> +		     vec<stmt_vec_info> stmts,
>  		     poly_uint64 *max_nunits,
>  		     bool *matches, unsigned *limit, unsigned *tree_size,
>  		     scalar_stmts_to_slp_tree_map_t *bst_map)
>  {
> +  unsigned int group_size = stmts.length ();
>    if (slp_tree *leader = bst_map->get (stmts))
>      {
>        if (dump_enabled_p ())
> @@ -1937,7 +1939,7 @@ vect_build_slp_tree (vec_info *vinfo,
>  		     "starting SLP discovery for node %p\n", (void *) res);
> 
>    poly_uint64 this_max_nunits = 1;
> -  slp_tree res_ = vect_build_slp_tree_2 (vinfo, res, stmts, group_size,
> +  slp_tree res_ = vect_build_slp_tree_2 (vinfo, res, stmts,
>  					&this_max_nunits,
>  					matches, limit, tree_size, bst_map);
>    if (!res_)
> @@ -2025,11 +2027,12 @@ vect_slp_build_two_operator_nodes (slp_tree
> perm, tree vectype,
> 
>  static slp_tree
>  vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
> -		       vec<stmt_vec_info> stmts, unsigned int group_size,
> +		       vec<stmt_vec_info> stmts,
>  		       poly_uint64 *max_nunits,
>  		       bool *matches, unsigned *limit, unsigned *tree_size,
>  		       scalar_stmts_to_slp_tree_map_t *bst_map)
>  {
> +  unsigned int group_size = stmts.length ();
>    unsigned nops, i, this_tree_size = 0;
>    poly_uint64 this_max_nunits = *max_nunits;
> 
> @@ -2108,7 +2111,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree
> node,
>    bool two_operators = false;
>    unsigned char *swap = XALLOCAVEC (unsigned char, group_size);
>    tree vectype = NULL_TREE;
> -  if (!vect_build_slp_tree_1 (vinfo, swap, stmts, group_size,
> +  if (!vect_build_slp_tree_1 (vinfo, swap, stmts,
>  			      &this_max_nunits, matches, &two_operators,
>  			      &vectype))
>      return NULL;
> @@ -2205,7 +2208,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree
> node,
>  		    }
>  		  bool *matches2 = XALLOCAVEC (bool, dr_group_size);
>  		  slp_tree unperm_load
> -		    = vect_build_slp_tree (vinfo, stmts2, dr_group_size,
> +		    = vect_build_slp_tree (vinfo, stmts2,
>  					   &this_max_nunits, matches2, limit,
>  					   &this_tree_size, bst_map);
>  		  /* When we are able to do the full masked load emit that
> @@ -2509,7 +2512,7 @@ vect_build_slp_tree_2 (vec_info *vinfo, slp_tree
> node,
>  			else
>  			  op_stmts.quick_push (NULL);
>  		      child = vect_build_slp_tree (vinfo, op_stmts,
> -						   group_size,
> &this_max_nunits,
> +						   &this_max_nunits,
>  						   matches, limit,
>  						   &this_tree_size, bst_map);
>  		      /* ???  We're likely getting too many fatal mismatches
> @@ -2947,7 +2950,7 @@ out:
>  	  vec<stmt_vec_info> def_stmts2;
>  	  def_stmts2.create (1);
>  	  def_stmts2.quick_push (oprnd_info->def_stmts[0]);
> -	  child = vect_build_slp_tree (vinfo, def_stmts2, 1,
> +	  child = vect_build_slp_tree (vinfo, def_stmts2,
>  				       &this_max_nunits,
>  				       matches, limit,
>  				       &this_tree_size, bst_map);
> @@ -3021,7 +3024,7 @@ out:
>        else if (least_upthread_swappable_op_distance != -1U)
>  	least_upthread_swappable_op_distance++;
>        child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
> -				   group_size, &this_max_nunits,
> +				   &this_max_nunits,
>  				   matches, limit,
>  				   &this_tree_size, bst_map);
>        least_upthread_swappable_op_distance = old_swap_distance;
> @@ -3083,7 +3086,7 @@ out:
>  	  /* And try again with scratch 'matches' ... */
>  	  bool *tem = XALLOCAVEC (bool, group_size);
>  	  if ((child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
> -					    group_size, &this_max_nunits,
> +					    &this_max_nunits,
>  					    tem, limit,
>  					    &this_tree_size, bst_map)) != NULL)
>  	    {
> @@ -3807,7 +3810,7 @@ optimize_load_redistribution_1
> (scalar_stmts_to_slp_tree_map_t *bst_map,
>        bool *matches = XALLOCAVEC (bool, group_size);
>        poly_uint64 max_nunits = 1;
>        unsigned tree_size = 0, limit = 1;
> -      node = vect_build_slp_tree (vinfo, stmts, group_size, &max_nunits,
> +      node = vect_build_slp_tree (vinfo, stmts, &max_nunits,
>  				  matches, &limit, &tree_size, bst_map);
>        if (!node)
>  	stmts.release ();
> @@ -4236,7 +4239,7 @@ vect_build_slp_instance (vec_info *vinfo,
>        matches[1] = false;
>      }
>    else
> -    node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
> +    node = vect_build_slp_tree (vinfo, scalar_stmts,
>  				&max_nunits, matches, limit,
>  				&tree_size, bst_map);
>    if (node != NULL)
> @@ -4498,7 +4501,7 @@ vect_analyze_slp_reduc_chain (loop_vec_info
> vinfo,
>        bool *matches = XALLOCAVEC (bool, group_size);
>        poly_uint64 max_nunits = 1;
>        unsigned tree_size = 0;
> -      slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
> +      slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts,
>  					   &max_nunits, matches, limit,
>  					   &tree_size, bst_map);
>        if (!node)
> @@ -4646,7 +4649,7 @@ vect_analyze_slp_reduc_chain (loop_vec_info
> vinfo,
>    for (unsigned i = 0; i < scalar_stmts.length (); ++i)
>      REDUC_GROUP_FIRST_ELEMENT (scalar_stmts[i]) = scalar_stmts[0];
> 
> -  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
> +  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts,
>  				       &max_nunits, matches, limit,
>  				       &tree_size, bst_map);
> 
> @@ -4790,7 +4793,7 @@ vect_analyze_slp_reduction (loop_vec_info vinfo,
>    poly_uint64 max_nunits = 1;
>    unsigned tree_size = 0;
> 
> -  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
> +  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts,
>  				       &max_nunits, matches, limit,
>  				       &tree_size, bst_map);
>    if (node != NULL)
> @@ -4862,7 +4865,6 @@ vect_analyze_slp_reduction_group (loop_vec_info
> loop_vinfo,
>    poly_uint64 max_nunits = 1;
>    unsigned tree_size = 0;
>    slp_tree node = vect_build_slp_tree (loop_vinfo, scalar_stmts,
> -				       group_size,
>  				       &max_nunits, matches, limit,
>  				       &tree_size, bst_map);
>    if (!node)
> @@ -5089,7 +5091,7 @@ vect_analyze_slp_instance (vec_info *vinfo,
>        matches[1] = false;
>      }
>    else
> -    node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
> +    node = vect_build_slp_tree (vinfo, scalar_stmts,
>  				&max_nunits, matches, limit,
>  				&tree_size, bst_map);
>    if (node != NULL)
> @@ -5278,7 +5280,7 @@ vect_analyze_slp_instance (vec_info *vinfo,
>  	      for (unsigned j = start; j < end; ++j)
>  		substmts.quick_push (scalar_stmts[j]);
>  	      max_nunits = 1;
> -	      node = vect_build_slp_tree (vinfo, substmts, end - start,
> +	      node = vect_build_slp_tree (vinfo, substmts,
>  					  &max_nunits,
>  					  matches, limit, &tree_size, bst_map);
>  	      if (node)
> @@ -5651,7 +5653,6 @@ vect_lower_load_permutations (loop_vec_info
> loop_vinfo,
>        unsigned limit = 1;
>        unsigned tree_size = 0;
>        slp_tree l0 = vect_build_slp_tree (loop_vinfo, stmts,
> -					 group_lanes,
>  					 &max_nunits, matches, &limit,
>  					 &tree_size, bst_map);
>        gcc_assert (!SLP_TREE_LOAD_PERMUTATION (l0).exists ());
> --
> 2.51.0
  

Patch

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 0266e75888c..ff11b392305 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -1147,10 +1147,11 @@  vect_record_max_nunits (vec_info *vinfo, stmt_vec_info stmt_info,
 
 static bool
 vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
-		       vec<stmt_vec_info> stmts, unsigned int group_size,
+		       vec<stmt_vec_info> stmts,
 		       poly_uint64 *max_nunits, bool *matches,
 		       bool *two_operators, tree *node_vectype)
 {
+  unsigned int group_size = stmts.length ();
   unsigned int i;
   stmt_vec_info first_stmt_info = stmts[0];
   code_helper first_stmt_code = ERROR_MARK;
@@ -1881,18 +1882,19 @@  static unsigned least_upthread_swappable_op_distance = -1U;
 
 static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
-		       vec<stmt_vec_info> stmts, unsigned int group_size,
+		       vec<stmt_vec_info> stmts,
 		       poly_uint64 *max_nunits,
 		       bool *matches, unsigned *limit, unsigned *tree_size,
 		       scalar_stmts_to_slp_tree_map_t *bst_map);
 
 static slp_tree
 vect_build_slp_tree (vec_info *vinfo,
-		     vec<stmt_vec_info> stmts, unsigned int group_size,
+		     vec<stmt_vec_info> stmts,
 		     poly_uint64 *max_nunits,
 		     bool *matches, unsigned *limit, unsigned *tree_size,
 		     scalar_stmts_to_slp_tree_map_t *bst_map)
 {
+  unsigned int group_size = stmts.length ();
   if (slp_tree *leader = bst_map->get (stmts))
     {
       if (dump_enabled_p ())
@@ -1937,7 +1939,7 @@  vect_build_slp_tree (vec_info *vinfo,
 		     "starting SLP discovery for node %p\n", (void *) res);
 
   poly_uint64 this_max_nunits = 1;
-  slp_tree res_ = vect_build_slp_tree_2 (vinfo, res, stmts, group_size,
+  slp_tree res_ = vect_build_slp_tree_2 (vinfo, res, stmts,
 					&this_max_nunits,
 					matches, limit, tree_size, bst_map);
   if (!res_)
@@ -2025,11 +2027,12 @@  vect_slp_build_two_operator_nodes (slp_tree perm, tree vectype,
 
 static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
-		       vec<stmt_vec_info> stmts, unsigned int group_size,
+		       vec<stmt_vec_info> stmts,
 		       poly_uint64 *max_nunits,
 		       bool *matches, unsigned *limit, unsigned *tree_size,
 		       scalar_stmts_to_slp_tree_map_t *bst_map)
 {
+  unsigned int group_size = stmts.length ();
   unsigned nops, i, this_tree_size = 0;
   poly_uint64 this_max_nunits = *max_nunits;
 
@@ -2108,7 +2111,7 @@  vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
   bool two_operators = false;
   unsigned char *swap = XALLOCAVEC (unsigned char, group_size);
   tree vectype = NULL_TREE;
-  if (!vect_build_slp_tree_1 (vinfo, swap, stmts, group_size,
+  if (!vect_build_slp_tree_1 (vinfo, swap, stmts,
 			      &this_max_nunits, matches, &two_operators,
 			      &vectype))
     return NULL;
@@ -2205,7 +2208,7 @@  vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
 		    }
 		  bool *matches2 = XALLOCAVEC (bool, dr_group_size);
 		  slp_tree unperm_load
-		    = vect_build_slp_tree (vinfo, stmts2, dr_group_size,
+		    = vect_build_slp_tree (vinfo, stmts2,
 					   &this_max_nunits, matches2, limit,
 					   &this_tree_size, bst_map);
 		  /* When we are able to do the full masked load emit that
@@ -2509,7 +2512,7 @@  vect_build_slp_tree_2 (vec_info *vinfo, slp_tree node,
 			else
 			  op_stmts.quick_push (NULL);
 		      child = vect_build_slp_tree (vinfo, op_stmts,
-						   group_size, &this_max_nunits,
+						   &this_max_nunits,
 						   matches, limit,
 						   &this_tree_size, bst_map);
 		      /* ???  We're likely getting too many fatal mismatches
@@ -2947,7 +2950,7 @@  out:
 	  vec<stmt_vec_info> def_stmts2;
 	  def_stmts2.create (1);
 	  def_stmts2.quick_push (oprnd_info->def_stmts[0]);
-	  child = vect_build_slp_tree (vinfo, def_stmts2, 1,
+	  child = vect_build_slp_tree (vinfo, def_stmts2,
 				       &this_max_nunits,
 				       matches, limit,
 				       &this_tree_size, bst_map);
@@ -3021,7 +3024,7 @@  out:
       else if (least_upthread_swappable_op_distance != -1U)
 	least_upthread_swappable_op_distance++;
       child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
-				   group_size, &this_max_nunits,
+				   &this_max_nunits,
 				   matches, limit,
 				   &this_tree_size, bst_map);
       least_upthread_swappable_op_distance = old_swap_distance;
@@ -3083,7 +3086,7 @@  out:
 	  /* And try again with scratch 'matches' ... */
 	  bool *tem = XALLOCAVEC (bool, group_size);
 	  if ((child = vect_build_slp_tree (vinfo, oprnd_info->def_stmts,
-					    group_size, &this_max_nunits,
+					    &this_max_nunits,
 					    tem, limit,
 					    &this_tree_size, bst_map)) != NULL)
 	    {
@@ -3807,7 +3810,7 @@  optimize_load_redistribution_1 (scalar_stmts_to_slp_tree_map_t *bst_map,
       bool *matches = XALLOCAVEC (bool, group_size);
       poly_uint64 max_nunits = 1;
       unsigned tree_size = 0, limit = 1;
-      node = vect_build_slp_tree (vinfo, stmts, group_size, &max_nunits,
+      node = vect_build_slp_tree (vinfo, stmts, &max_nunits,
 				  matches, &limit, &tree_size, bst_map);
       if (!node)
 	stmts.release ();
@@ -4236,7 +4239,7 @@  vect_build_slp_instance (vec_info *vinfo,
       matches[1] = false;
     }
   else
-    node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
+    node = vect_build_slp_tree (vinfo, scalar_stmts,
 				&max_nunits, matches, limit,
 				&tree_size, bst_map);
   if (node != NULL)
@@ -4498,7 +4501,7 @@  vect_analyze_slp_reduc_chain (loop_vec_info vinfo,
       bool *matches = XALLOCAVEC (bool, group_size);
       poly_uint64 max_nunits = 1;
       unsigned tree_size = 0;
-      slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
+      slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts,
 					   &max_nunits, matches, limit,
 					   &tree_size, bst_map);
       if (!node)
@@ -4646,7 +4649,7 @@  vect_analyze_slp_reduc_chain (loop_vec_info vinfo,
   for (unsigned i = 0; i < scalar_stmts.length (); ++i)
     REDUC_GROUP_FIRST_ELEMENT (scalar_stmts[i]) = scalar_stmts[0];
 
-  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
+  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts,
 				       &max_nunits, matches, limit,
 				       &tree_size, bst_map);
 
@@ -4790,7 +4793,7 @@  vect_analyze_slp_reduction (loop_vec_info vinfo,
   poly_uint64 max_nunits = 1;
   unsigned tree_size = 0;
 
-  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
+  slp_tree node = vect_build_slp_tree (vinfo, scalar_stmts,
 				       &max_nunits, matches, limit,
 				       &tree_size, bst_map);
   if (node != NULL)
@@ -4862,7 +4865,6 @@  vect_analyze_slp_reduction_group (loop_vec_info loop_vinfo,
   poly_uint64 max_nunits = 1;
   unsigned tree_size = 0;
   slp_tree node = vect_build_slp_tree (loop_vinfo, scalar_stmts,
-				       group_size,
 				       &max_nunits, matches, limit,
 				       &tree_size, bst_map);
   if (!node)
@@ -5089,7 +5091,7 @@  vect_analyze_slp_instance (vec_info *vinfo,
       matches[1] = false;
     }
   else
-    node = vect_build_slp_tree (vinfo, scalar_stmts, group_size,
+    node = vect_build_slp_tree (vinfo, scalar_stmts,
 				&max_nunits, matches, limit,
 				&tree_size, bst_map);
   if (node != NULL)
@@ -5278,7 +5280,7 @@  vect_analyze_slp_instance (vec_info *vinfo,
 	      for (unsigned j = start; j < end; ++j)
 		substmts.quick_push (scalar_stmts[j]);
 	      max_nunits = 1;
-	      node = vect_build_slp_tree (vinfo, substmts, end - start,
+	      node = vect_build_slp_tree (vinfo, substmts,
 					  &max_nunits,
 					  matches, limit, &tree_size, bst_map);
 	      if (node)
@@ -5651,7 +5653,6 @@  vect_lower_load_permutations (loop_vec_info loop_vinfo,
       unsigned limit = 1;
       unsigned tree_size = 0;
       slp_tree l0 = vect_build_slp_tree (loop_vinfo, stmts,
-					 group_lanes,
 					 &max_nunits, matches, &limit,
 					 &tree_size, bst_map);
       gcc_assert (!SLP_TREE_LOAD_PERMUTATION (l0).exists ());