https://gcc.gnu.org/g:f0421daae209257c46a7420401199b5f9cc3f647

commit r17-2597-gf0421daae209257c46a7420401199b5f9cc3f647
Author: Tamar Christina <[email protected]>
Date:   Tue Jul 21 20:46:33 2026 +0100

    vect: replace usages of SLP_TREE_SCALAR_SMTS where possible
    
    Continuing the work started in GCC 12 with g:a0dae768c6f78eba
    this patch replaces uses of SLP_TREE_SCALAR_STMTS with SLP_TREE_LANES when 
used
    to determine the number of lanes in the SLP tree.  This de-couples the need 
to
    have the same number of scalar statements as lanes in the SLP tree.
    
    gcc/ChangeLog:
    
            * tree-vect-slp-patterns.cc (compatible_complex_nodes_p): Support
            mismatched group sizes and use group size to iterate.
            * tree-vect-slp.cc (vect_build_slp_instance,
            vect_analyze_slp_reduc_chain, vect_analyze_slp_reduction,
            vect_analyze_slp_reduction_group, vect_analyze_slp_instance,
            vect_analyze_slp): Compare against lanes instead of .length ().
            (vect_optimize_slp_pass::get_result_with_layout): replace .length ()
            with .exist ().
            (vect_transform_slp_perm_load_1): Use lanes instead of .length ().
            (vect_remove_slp_scalar_calls): Replace iterators.
            * tree-vect-stmts.cc (vectorizable_shift): Use group size over ops
            length.

Diff:
---
 gcc/tree-vect-slp-patterns.cc |  5 ++++-
 gcc/tree-vect-slp.cc          | 42 +++++++++++++++++++++---------------------
 gcc/tree-vect-stmts.cc        | 21 ++++++++++++---------
 3 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/gcc/tree-vect-slp-patterns.cc b/gcc/tree-vect-slp-patterns.cc
index 181281c2154b..3194642ef88e 100644
--- a/gcc/tree-vect-slp-patterns.cc
+++ b/gcc/tree-vect-slp-patterns.cc
@@ -762,7 +762,10 @@ compatible_complex_nodes_p (slp_compat_nodes_map_t 
*compat_cache,
      are externals.  */
   if (SLP_TREE_DEF_TYPE (a) != vect_internal_def)
     {
-      for (unsigned i = 0; i < SLP_TREE_SCALAR_OPS (a).length (); i++)
+      unsigned group_size = SLP_TREE_LANES (a);
+      gcc_assert (SLP_TREE_SCALAR_OPS (a).length () == group_size
+                 && SLP_TREE_SCALAR_OPS (b).length () == group_size);
+      for (unsigned i = 0; i < group_size; i++)
        {
          tree op1 = SLP_TREE_SCALAR_OPS (a)[pa[i % 2]];
          tree op2 = SLP_TREE_SCALAR_OPS (b)[pb[i % 2]];
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 850cb1efacc5..fe406a4cb6a4 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -4293,10 +4293,10 @@ vect_build_slp_instance (vec_info *vinfo,
          vinfo->slp_instances.safe_push (new_instance);
 
          /* ???  We've replaced the old SLP_INSTANCE_GROUP_SIZE with
-            the number of scalar stmts in the root in a few places.
+            the number of SLP lanes of the root in a few places.
             Verify that assumption holds.  */
-         gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
-                       .length () == group_size);
+         gcc_assert (SLP_TREE_LANES (SLP_INSTANCE_TREE (new_instance))
+                      == group_size);
 
          if (dump_enabled_p ())
            {
@@ -4785,10 +4785,10 @@ vect_analyze_slp_reduc_chain (loop_vec_info vinfo,
       vinfo->slp_instances.safe_push (new_instance);
 
       /* ???  We've replaced the old SLP_INSTANCE_GROUP_SIZE with
-        the number of scalar stmts in the root in a few places.
+        the number of SLP lanes of the root in a few places.
         Verify that assumption holds.  */
-      gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
-                 .length () == group_size);
+      gcc_assert (SLP_TREE_LANES (SLP_INSTANCE_TREE (new_instance))
+                 == group_size);
 
       if (dump_enabled_p ())
        {
@@ -4874,10 +4874,10 @@ vect_analyze_slp_reduction (loop_vec_info vinfo,
       vinfo->slp_instances.safe_push (new_instance);
 
       /* ???  We've replaced the old SLP_INSTANCE_GROUP_SIZE with
-        the number of scalar stmts in the root in a few places.
+        the number of SLP lanes of the root in a few places.
         Verify that assumption holds.  */
-      gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
-                 .length () == group_size);
+      gcc_assert (SLP_TREE_LANES (SLP_INSTANCE_TREE (new_instance))
+                 == group_size);
 
       if (dump_enabled_p ())
        {
@@ -4946,10 +4946,10 @@ vect_analyze_slp_reduction_group (loop_vec_info 
loop_vinfo,
   loop_vinfo->slp_instances.safe_push (new_instance);
 
   /* ???  We've replaced the old SLP_INSTANCE_GROUP_SIZE with
-     the number of scalar stmts in the root in a few places.
+     the number of SLP lanes of the root in a few places.
      Verify that assumption holds.  */
-  gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
-             .length () == group_size);
+  gcc_assert (SLP_TREE_LANES (SLP_INSTANCE_TREE (new_instance))
+             == group_size);
 
   if (dump_enabled_p ())
     {
@@ -5202,10 +5202,10 @@ vect_analyze_slp_instance (vec_info *vinfo,
          vinfo->slp_instances.safe_push (new_instance);
 
          /* ???  We've replaced the old SLP_INSTANCE_GROUP_SIZE with
-            the number of scalar stmts in the root in a few places.
+            the number of SLP lanes of the root in a few places.
             Verify that assumption holds.  */
-         gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
-                       .length () == group_size);
+         gcc_assert (SLP_TREE_LANES (SLP_INSTANCE_TREE (new_instance))
+                     == group_size);
 
          if (dump_enabled_p ())
            {
@@ -5449,10 +5449,10 @@ vect_analyze_slp_instance (vec_info *vinfo,
          vinfo->slp_instances.safe_push (new_instance);
 
          /* ???  We've replaced the old SLP_INSTANCE_GROUP_SIZE with
-            the number of scalar stmts in the root in a few places.
+            the number of SLP lanes of the root in a few places.
             Verify that assumption holds.  */
-         gcc_assert (SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (new_instance))
-                       .length () == group_size);
+         gcc_assert (SLP_TREE_LANES (SLP_INSTANCE_TREE (new_instance))
+                     == group_size);
 
          if (dump_enabled_p ())
            {
@@ -7971,7 +7971,7 @@ vect_optimize_slp_pass::get_result_with_layout (slp_tree 
node,
 
       unsigned int num_lanes = SLP_TREE_LANES (node);
       result = vect_create_new_slp_node (num_inputs, VEC_PERM_EXPR);
-      if (SLP_TREE_SCALAR_STMTS (node).length ())
+      if (SLP_TREE_SCALAR_STMTS (node).exists ())
        {
          auto &stmts = SLP_TREE_SCALAR_STMTS (result);
          stmts.safe_splice (SLP_TREE_SCALAR_STMTS (node));
@@ -8884,7 +8884,7 @@ vect_prologue_cost_for_slp (vec_info *vinfo, slp_tree 
node,
      constants can be implemented as load from the constant pool.
      When all elements are the same we can use a splat.  */
   tree vectype = SLP_TREE_VECTYPE (node);
-  unsigned group_size = SLP_TREE_SCALAR_OPS (node).length ();
+  unsigned group_size = SLP_TREE_LANES (node);
   unsigned HOST_WIDE_INT const_nunits;
   unsigned nelt_limit;
   unsigned nvectors = vect_get_num_copies (vinfo, node);
@@ -11047,7 +11047,7 @@ vect_transform_slp_perm_load_1 (vec_info *vinfo, 
slp_tree node,
   stmt_vec_info stmt_info = SLP_TREE_SCALAR_STMTS (node)[0];
   int vec_index = 0;
   tree vectype = SLP_TREE_VECTYPE (node);
-  unsigned int group_size = SLP_TREE_SCALAR_STMTS (node).length ();
+  unsigned int group_size = SLP_TREE_LANES (node);
   unsigned int mask_element;
   unsigned dr_group_size;
   machine_mode mode;
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 700b3e7e0686..488b9754bed4 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -6388,15 +6388,18 @@ vectorizable_shift (vec_info *vinfo,
       /* Now adjust the constant shift amount in place.  */
       if (incompatible_op1_vectype_p
          && dt[1] == vect_constant_def)
-       for (unsigned i = 0;
-            i < SLP_TREE_SCALAR_OPS (slp_op1).length (); ++i)
-         {
-           SLP_TREE_SCALAR_OPS (slp_op1)[i]
-             = fold_convert (TREE_TYPE (vectype),
-                             SLP_TREE_SCALAR_OPS (slp_op1)[i]);
-           gcc_assert ((TREE_CODE (SLP_TREE_SCALAR_OPS (slp_op1)[i])
-                        == INTEGER_CST));
-         }
+       {
+         unsigned group_size = SLP_TREE_LANES (slp_op1);
+         gcc_assert (SLP_TREE_SCALAR_OPS (slp_op1).length () == group_size);
+         for (unsigned i = 0; i < group_size; ++i)
+           {
+             SLP_TREE_SCALAR_OPS (slp_op1)[i]
+               = fold_convert (TREE_TYPE (vectype),
+                               SLP_TREE_SCALAR_OPS (slp_op1)[i]);
+             gcc_assert ((TREE_CODE (SLP_TREE_SCALAR_OPS (slp_op1)[i])
+                          == INTEGER_CST));
+           }
+       }
       SLP_TREE_TYPE (slp_node) = shift_vec_info_type;
       DUMP_VECT_SCOPE ("vectorizable_shift");
       vect_model_simple_cost (vinfo, 1, slp_node, cost_vec);

Reply via email to