[5/6] Allow poly_uint64 for group_size args to vector type query routines

Message ID 20231213123252.DF750383A612@sourceware.org
State New
Headers
Series Relax single-vector-size restriction |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed

Commit Message

Richard Biener Dec. 13, 2023, 12:31 p.m. UTC
  The following changes the unsigned group_size argument to a poly_uint64
one to avoid too much special-casing in callers for VLA vectors when
passing down the effective maximum desirable vector size to vector
type query routines.  The intent is to be able to pass down
the vectorization factor (times the SLP group size) eventually.

	* tree-vectorizer.h (get_vectype_for_scalar_type,
	get_mask_type_for_scalar_type, vect_get_vector_types_for_stmt):
	Change group_size argument to poly_uint64 type.
	(vect_get_mask_type_for_stmt): Remove prototype for no longer
	existing function.
	* tree-vect-stmts.cc (get_vectype_for_scalar_type): Change
	group_size argument to poly_uint64.
	(get_mask_type_for_scalar_type): Likewise.
	(vect_get_vector_types_for_stmt): Likewise.
---
 gcc/tree-vect-stmts.cc | 25 ++++++++++++++-----------
 gcc/tree-vectorizer.h  |  7 +++----
 2 files changed, 17 insertions(+), 15 deletions(-)
  

Patch

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 88401a2a00b..a5e26b746fb 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -13297,14 +13297,14 @@  get_related_vectype_for_scalar_type (machine_mode prevailing_mode,
 
 tree
 get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
-			     unsigned int group_size)
+			     poly_uint64 group_size)
 {
   /* For BB vectorization, we should always have a group size once we've
      constructed the SLP tree; the only valid uses of zero GROUP_SIZEs
      are tentative requests during things like early data reference
      analysis and pattern recognition.  */
   if (is_a <bb_vec_info> (vinfo))
-    gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
+    gcc_assert (vinfo->slp_instances.is_empty () || known_ne (group_size, 0));
   else
     group_size = 0;
 
@@ -13320,9 +13320,11 @@  get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
 
   /* If the natural choice of vector type doesn't satisfy GROUP_SIZE,
      try again with an explicit number of elements.  */
+  uint64_t cst_group_size;
   if (vectype
-      && group_size
-      && maybe_ge (TYPE_VECTOR_SUBPARTS (vectype), group_size))
+      && group_size.is_constant (&cst_group_size)
+      && cst_group_size != 0
+      && maybe_ge (TYPE_VECTOR_SUBPARTS (vectype), cst_group_size))
     {
       /* Start with the biggest number of units that fits within
 	 GROUP_SIZE and halve it until we find a valid vector type.
@@ -13336,7 +13338,7 @@  get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type,
 	 even though the group is not a multiple of that vector size.
 	 The BB vectorizer will then try to carve up the group into
 	 smaller pieces.  */
-      unsigned int nunits = 1 << floor_log2 (group_size);
+      unsigned int nunits = 1 << floor_log2 (cst_group_size);
       do
 	{
 	  vectype = get_related_vectype_for_scalar_type (vinfo->vector_mode,
@@ -13372,7 +13374,7 @@  get_vectype_for_scalar_type (vec_info *vinfo, tree scalar_type, slp_tree node)
 
 tree
 get_mask_type_for_scalar_type (vec_info *vinfo, tree scalar_type,
-			       unsigned int group_size)
+			       poly_uint64 group_size)
 {
   tree vectype = get_vectype_for_scalar_type (vinfo, scalar_type, group_size);
 
@@ -14243,7 +14245,7 @@  opt_result
 vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
 				tree *stmt_vectype_out,
 				tree *nunits_vectype_out,
-				unsigned int group_size)
+				poly_uint64 group_size)
 {
   gimple *stmt = stmt_info->stmt;
 
@@ -14252,7 +14254,7 @@  vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
      are tentative requests during things like early data reference
      analysis and pattern recognition.  */
   if (is_a <bb_vec_info> (vinfo))
-    gcc_assert (vinfo->slp_instances.is_empty () || group_size != 0);
+    gcc_assert (vinfo->slp_instances.is_empty () || known_ne (group_size, 0));
   else
     group_size = 0;
 
@@ -14281,7 +14283,7 @@  vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
 
   tree vectype;
   tree scalar_type = NULL_TREE;
-  if (group_size == 0 && STMT_VINFO_VECTYPE (stmt_info))
+  if (known_eq (group_size, 0U) && STMT_VINFO_VECTYPE (stmt_info))
     {
       vectype = STMT_VINFO_VECTYPE (stmt_info);
       if (dump_enabled_p ())
@@ -14310,10 +14312,11 @@  vect_get_vector_types_for_stmt (vec_info *vinfo, stmt_vec_info stmt_info,
 
       if (dump_enabled_p ())
 	{
-	  if (group_size)
+	  if (known_ne (group_size, 0U))
 	    dump_printf_loc (MSG_NOTE, vect_location,
 			     "get vectype for scalar type (group size %d):"
-			     " %T\n", group_size, scalar_type);
+			     " %T\n", (int)constant_lower_bound (group_size),
+			     scalar_type);
 	  else
 	    dump_printf_loc (MSG_NOTE, vect_location,
 			     "get vectype for scalar type: %T\n", scalar_type);
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index a2bab8676af..95240504d18 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2204,9 +2204,9 @@  extern edge vec_init_loop_exit_info (class loop *);
 /* In tree-vect-stmts.cc.  */
 extern tree get_related_vectype_for_scalar_type (machine_mode, tree,
 						 poly_uint64 = 0);
-extern tree get_vectype_for_scalar_type (vec_info *, tree, unsigned int = 0);
+extern tree get_vectype_for_scalar_type (vec_info *, tree, poly_uint64 = 0);
 extern tree get_vectype_for_scalar_type (vec_info *, tree, slp_tree);
-extern tree get_mask_type_for_scalar_type (vec_info *, tree, unsigned int = 0);
+extern tree get_mask_type_for_scalar_type (vec_info *, tree, poly_uint64 = 0);
 extern tree get_mask_type_for_scalar_type (vec_info *, tree, slp_tree);
 extern tree get_same_sized_vectype (tree, tree);
 extern bool vect_chooses_same_modes_p (vec_info *, machine_mode);
@@ -2295,8 +2295,7 @@  extern tree vect_gen_while (gimple_seq *, tree, tree, tree,
 extern tree vect_gen_while_not (gimple_seq *, tree, tree, tree);
 extern opt_result vect_get_vector_types_for_stmt (vec_info *,
 						  stmt_vec_info, tree *,
-						  tree *, unsigned int = 0);
-extern opt_tree vect_get_mask_type_for_stmt (stmt_vec_info, unsigned int = 0);
+						  tree *, poly_uint64 = 0);
 
 /* In tree-vect-data-refs.cc.  */
 extern bool vect_can_force_dr_alignment_p (const_tree, poly_uint64);