Re: [PATCH 1/2] Assign vertex weight to all nodes

Richard Biener <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
On Thu, 20 Aug 2026, Richard Sandiford wrote:

> Richard Biener <[email protected]> writes:
> > SLP permute nodes (can) have no SLP_TREE_REPRESENTATIVE, avoid
> > leaving vertex weight (later used for costing) at zero but
> > assign weight based on the region entry block.
> 
> That's better than 0 :) but is there a plan to make the choice of
> block more accurate in future?  Using the entry block for something
> that actually ends up in a loop would defeat the speed-based costing.

Well, permutes are invented by the vectorizer, so they do not have
a natural "block choice".  One could assign a weigth based on the
weigth of the permuted operands (possibly recursively) or it's
uses.  Or based on the place where we'd code generate it (which
is based on the operands places).  But the processing doesn't walk
the graph in a particular oder, so that looked iffy to implement.

As you say, using a cost based on the entry is better than 0.

The other ad-hoc possibility would be to use one of the
scalar stmts assigned to the lanes, but we also have
permutes with none of those (for existing vector defs).

Richard.


> Richard
> 
> >
> > This avoids regressing bb-slp-layout-18.c and bb-slp-pr54400.c
> > with 2/2 which drops SLP_TREE_REPRESENTATIVE from all permute
> > nodes.
> >
> > 	* tree-vect-slp.cc (vect_slp_node_weight): Get vinfo as
> > 	context.  For nodes without representative use the
> > 	region entry block.
> > 	(vect_optimize_slp_pass::start_choosing_layouts): Always
> > 	assign vertex weight.
> > ---
> >  gcc/tree-vect-slp.cc | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
> > index 5e729e478ce..b2f14e6528a 100644
> > --- a/gcc/tree-vect-slp.cc
> > +++ b/gcc/tree-vect-slp.cc
> > @@ -346,10 +346,14 @@ vect_free_oprnd_info (vec<slp_oprnd_info> &oprnds_info)
> >     a "more important" node when optimizing for speed).  */
> >  
> >  static sreal
> > -vect_slp_node_weight (slp_tree node)
> > +vect_slp_node_weight (vec_info *vinfo, slp_tree node)
> >  {
> > -  stmt_vec_info stmt_info = vect_orig_stmt (SLP_TREE_REPRESENTATIVE (node));
> > -  basic_block bb = gimple_bb (stmt_info->stmt);
> > +  stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (node);
> > +  basic_block bb;
> > +  if (!stmt_info)
> > +    bb = vinfo->bbs[0];
> > +  else
> > +    bb = gimple_bb (vect_orig_stmt (stmt_info)->stmt);
> >    return bb->count.to_sreal_scale (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count);
> >  }
> >  
> > @@ -7520,10 +7524,10 @@ vect_optimize_slp_pass::start_choosing_layouts ()
> >        auto &partition = m_partitions[vertex.partition];
> >        slp_tree node = vertex.node;
> >  
> > +      vertex.weight = vect_slp_node_weight (m_vinfo, node);
> > +
> >        if (stmt_vec_info rep = SLP_TREE_REPRESENTATIVE (node))
> >  	{
> > -	  vertex.weight = vect_slp_node_weight (node);
> > -
> >  	  /* We do not handle stores with a permutation, so all
> >  	     incoming permutations must have been materialized.
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Jochen Jaser, Andrew McDonald, Abhinav Puri; (HRB 36809, AG Nuernberg)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.