[gcc r17-3407] Assign vertex weight to all nodes

Richard Biener via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:e891ad2e77a5373d62af39c8b5f815993fccf253

commit r17-3407-ge891ad2e77a5373d62af39c8b5f815993fccf253
Author: Richard Biener <[email protected]>
Date:   Tue Aug 18 14:23:01 2026 +0200

    Assign vertex weight to all nodes
    
    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.
    
            * 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.

Diff:
---
 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 72eb1722bece..f00e44287745 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);
 }
 
@@ -7440,10 +7444,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.
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.