[PATCH] tree-optimization/95309 - fix invariant SLP node costing

Richard Biener rguenther@suse.de
Mon May 25 14:01:05 GMT 2020


This makes sure to compute SLP_TREE_NUMBER_OF_VEC_STMTS during SLP
analysis even for invariant / external nodes so costing properly
knows what to cost.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  This might
also fix a few other cost issues reported.

2020-05-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/95309
	* tree-vect-slp.c (vect_get_constant_vectors): Move number
	of vector computation ...
	(vect_slp_analyze_node_operations): ... to analysis phase.
---
 gcc/tree-vect-slp.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index ec3675e7070..c4fd045e9be 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2856,17 +2856,37 @@ vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node,
      other referrers.  */
   if (res)
     FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child)
-      if (SLP_TREE_DEF_TYPE (child) != vect_internal_def)
+      if ((SLP_TREE_DEF_TYPE (child) == vect_constant_def
+	   || SLP_TREE_DEF_TYPE (child) == vect_external_def)
+	  /* Perform usual caching, note code-generation still
+	     code-gens these nodes multiple times but we expect
+	     to CSE them later.  */
+	  && !visited.contains (child)
+	  && !lvisited.add (child))
 	{
 	  /* ???  After auditing more code paths make a "default"
 	     and push the vector type from NODE to all children
 	     if it is not already set.  */
-	  /* Perform usual caching, note code-generation still
-	     code-gens these nodes multiple times but we expect
-	     to CSE them later.  */
-	  if (!visited.contains (child)
-	      && !lvisited.add (child))
-	    vect_prologue_cost_for_slp (vinfo, child, cost_vec);
+	  /* Compute the number of vectors to be generated.  */
+	  tree vector_type = SLP_TREE_VECTYPE (child);
+	  if (!vector_type)
+	    {
+	      /* For shifts with a scalar argument we don't need
+		 to cost or code-generate anything.
+		 ???  Represent this more explicitely.  */
+	      gcc_assert ((STMT_VINFO_TYPE (SLP_TREE_SCALAR_STMTS (node)[0])
+			   == shift_vec_info_type)
+			  && j == 1);
+	      continue;
+	    }
+	  unsigned group_size = SLP_TREE_SCALAR_OPS (child).length ();
+	  poly_uint64 vf = 1;
+	  if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo))
+	    vf = loop_vinfo->vectorization_factor;
+	  SLP_TREE_NUMBER_OF_VEC_STMTS (child)
+	    = vect_get_num_vectors (vf * group_size, vector_type);
+	  /* And cost them.  */
+	  vect_prologue_cost_for_slp (vinfo, child, cost_vec);
 	}
 
   /* If this node can't be vectorized, try pruning the tree here rather
@@ -3638,12 +3658,7 @@ vect_get_constant_vectors (vec_info *vinfo,
 					 (vinfo, TREE_TYPE (op), op_node)));
     }
 
-  poly_uint64 vf = 1;
-  if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo))
-    vf = loop_vinfo->vectorization_factor;
-  unsigned int number_of_vectors
-    = vect_get_num_vectors (vf * group_size, vector_type);
-
+  unsigned int number_of_vectors = SLP_TREE_NUMBER_OF_VEC_STMTS (op_node);
   vec_oprnds->create (number_of_vectors);
   auto_vec<tree> voprnds (number_of_vectors);
 
-- 
2.25.1


More information about the Gcc-patches mailing list