Re: [064/nnn] poly_int: SLP max_units

2017-12-05 Thread Jeff Law
On 10/23/2017 11:26 AM, Richard Sandiford wrote:
> This match makes tree-vect-slp.c track the maximum number of vector
> units as a poly_uint64 rather than an unsigned int.
> 
> 
> 2017-10-23  Richard Sandiford  
>   Alan Hayward  
>   David Sherwood  
> 
> gcc/
>   * tree-vect-slp.c (vect_record_max_nunits, vect_build_slp_tree_1)
>   (vect_build_slp_tree_2, vect_build_slp_tree): Change max_nunits
>   from an unsigned int * to a poly_uint64_pod *.
>   (calculate_unrolling_factor): New function.
>   (vect_analyze_slp_instance): Use it.  Track polynomial max_nunits.
OK.

jeff


[064/nnn] poly_int: SLP max_units

2017-10-23 Thread Richard Sandiford
This match makes tree-vect-slp.c track the maximum number of vector
units as a poly_uint64 rather than an unsigned int.


2017-10-23  Richard Sandiford  
Alan Hayward  
David Sherwood  

gcc/
* tree-vect-slp.c (vect_record_max_nunits, vect_build_slp_tree_1)
(vect_build_slp_tree_2, vect_build_slp_tree): Change max_nunits
from an unsigned int * to a poly_uint64_pod *.
(calculate_unrolling_factor): New function.
(vect_analyze_slp_instance): Use it.  Track polynomial max_nunits.

Index: gcc/tree-vect-slp.c
===
--- gcc/tree-vect-slp.c 2017-10-23 17:22:26.573499378 +0100
+++ gcc/tree-vect-slp.c 2017-10-23 17:22:27.793744215 +0100
@@ -489,7 +489,7 @@ vect_get_and_check_slp_defs (vec_info *v
 
 static bool
 vect_record_max_nunits (vec_info *vinfo, gimple *stmt, unsigned int group_size,
-   tree vectype, unsigned int *max_nunits)
+   tree vectype, poly_uint64 *max_nunits)
 {
   if (!vectype)
 {
@@ -506,8 +506,11 @@ vect_record_max_nunits (vec_info *vinfo,
 
   /* If populating the vector type requires unrolling then fail
  before adjusting *max_nunits for basic-block vectorization.  */
+  poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (vectype);
+  unsigned HOST_WIDE_INT const_nunits;
   if (is_a  (vinfo)
-  && TYPE_VECTOR_SUBPARTS (vectype) > group_size)
+  && (!nunits.is_constant (_nunits)
+ || const_nunits > group_size))
 {
   dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
   "Build SLP failed: unrolling required "
@@ -517,9 +520,7 @@ vect_record_max_nunits (vec_info *vinfo,
 }
 
   /* In case of multiple types we need to detect the smallest type.  */
-  if (*max_nunits < TYPE_VECTOR_SUBPARTS (vectype))
-*max_nunits = TYPE_VECTOR_SUBPARTS (vectype);
-
+  vect_update_max_nunits (max_nunits, vectype);
   return true;
 }
 
@@ -540,7 +541,7 @@ vect_record_max_nunits (vec_info *vinfo,
 static bool
 vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   vec stmts, unsigned int group_size,
-  unsigned nops, unsigned int *max_nunits,
+  unsigned nops, poly_uint64 *max_nunits,
   bool *matches, bool *two_operators)
 {
   unsigned int i;
@@ -966,16 +967,15 @@ bst_traits::equal (value_type existing,
 static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo,
   vec stmts, unsigned int group_size,
-  unsigned int *max_nunits,
+  poly_uint64 *max_nunits,
   vec *loads,
   bool *matches, unsigned *npermutes, unsigned *tree_size,
   unsigned max_tree_size);
 
 static slp_tree
 vect_build_slp_tree (vec_info *vinfo,
- vec stmts, unsigned int group_size,
- unsigned int *max_nunits,
- vec *loads,
+vec stmts, unsigned int group_size,
+poly_uint64 *max_nunits, vec *loads,
 bool *matches, unsigned *npermutes, unsigned *tree_size,
 unsigned max_tree_size)
 {
@@ -1007,12 +1007,13 @@ vect_build_slp_tree (vec_info *vinfo,
 static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo,
   vec stmts, unsigned int group_size,
-  unsigned int *max_nunits,
+  poly_uint64 *max_nunits,
   vec *loads,
   bool *matches, unsigned *npermutes, unsigned *tree_size,
   unsigned max_tree_size)
 {
-  unsigned nops, i, this_tree_size = 0, this_max_nunits = *max_nunits;
+  unsigned nops, i, this_tree_size = 0;
+  poly_uint64 this_max_nunits = *max_nunits;
   gimple *stmt;
   slp_tree node;
 
@@ -1951,6 +1952,15 @@ vect_split_slp_store_group (gimple *firs
   return group2;
 }
 
+/* Calculate the unrolling factor for an SLP instance with GROUP_SIZE
+   statements and a vector of NUNITS elements.  */
+
+static poly_uint64
+calculate_unrolling_factor (poly_uint64 nunits, unsigned int group_size)
+{
+  return exact_div (common_multiple (nunits, group_size), group_size);
+}
+
 /* Analyze an SLP instance starting from a group of grouped stores.  Call
vect_build_slp_tree to build a tree of packed stmts if possible.
Return FALSE if it's impossible to SLP any stmt in the loop.  */
@@ -1962,11 +1972,9 @@ vect_analyze_slp_instance (vec_info *vin
   slp_instance new_instance;
   slp_tree node;
   unsigned int group_size = GROUP_SIZE (vinfo_for_stmt (stmt));
-  unsigned int nunits;
   tree vectype, scalar_type = NULL_TREE;
   gimple *next;
   unsigned int i;
-  unsigned int max_nunits = 0;
   vec loads;
   struct data_reference *dr = STMT_VINFO_DATA_REF (vinfo_for_stmt (stmt));
   vec scalar_stmts;
@@