[gcc r16-3847] Integrate SLP permute transform into vect_transform_stmt

Richard Biener rguenth@gcc.gnu.org
Sun Sep 14 09:08:21 GMT 2025


https://gcc.gnu.org/g:21d1bb1922fa7cd98f2a27d002e48b488e772176

commit r16-3847-g21d1bb1922fa7cd98f2a27d002e48b488e772176
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Sep 12 13:52:51 2025 +0200

    Integrate SLP permute transform into vect_transform_stmt
    
    This adds permute_info_type and removes the duplication from
    vect_schedule_slp_node.
    
            * tree-vectorizer.h (stmt_vec_info_type::permute_info_type): Add.
            (vectorizable_slp_permutation): Declare.
            * tree-vect-slp.cc (vectorizable_slp_permutation): Export.
            (vect_slp_analyze_node_operations_1): Set permute_info_type
            on permute nodes successfully analyzed.
            (vect_schedule_slp_node): Dispatch to vect_transform_stmt
            for all nodes.
            * tree-vect-stmts.cc (vect_transform_stmt): Remove redundant
            dump, handle permute_info_type.
    
            * gcc.dg/vect/vect-reduc-chain-2.c: Adjust.
            * gcc.dg/vect/vect-reduc-chain-3.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-reduc-chain-2.c |  6 ++--
 gcc/testsuite/gcc.dg/vect/vect-reduc-chain-3.c |  4 +--
 gcc/tree-vect-slp.cc                           | 40 +++++++-------------------
 gcc/tree-vect-stmts.cc                         | 12 ++++----
 gcc/tree-vectorizer.h                          |  5 +++-
 5 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-2.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-2.c
index 5bc2686fc9d6..0d8d012ec2ea 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-2.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-2.c
@@ -74,6 +74,6 @@ main (void)
 }
 
 /* { dg-final { scan-tree-dump "vect_recog_dot_prod_pattern: detected" "vect" } } */
-/* { dg-final { scan-tree-dump "vectorizing statement: \\S+ = DOT_PROD_EXPR" "vect" { target { vect_sdot_qi } } } } */
-/* { dg-final { scan-tree-dump "vectorizing statement: \\S+ = DOT_PROD_EXPR" "vect" { target { vect_udot_qi } } } } */
-/* { dg-final { scan-tree-dump "vectorizing statement: \\S+ = DOT_PROD_EXPR" "vect" { target { vect_sdot_hi } } } } */
+/* { dg-final { scan-tree-dump "vectorizing SLP node starting from: \\S+ = DOT_PROD_EXPR" "vect" { target { vect_sdot_qi } } } } */
+/* { dg-final { scan-tree-dump "vectorizing SLP node starting from: \\S+ = DOT_PROD_EXPR" "vect" { target { vect_udot_qi } } } } */
+/* { dg-final { scan-tree-dump "vectorizing SLP node starting from: \\S+ = DOT_PROD_EXPR" "vect" { target { vect_sdot_hi } } } } */
diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-3.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-3.c
index 6a733fbac534..1cefbe0b959f 100644
--- a/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-3.c
+++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-chain-3.c
@@ -64,5 +64,5 @@ main (void)
     __builtin_abort ();
 }
 
-/* { dg-final { scan-tree-dump "vectorizing statement: \\S+ = SAD_EXPR" "vect" { target vect_udot_qi } } } */
-/* { dg-final { scan-tree-dump "vectorizing statement: \\S+ = DOT_PROD_EXPR" "vect" { target vect_sdot_hi } } } */
+/* { dg-final { scan-tree-dump "vectorizing SLP node starting from: \\S+ = SAD_EXPR" "vect" { target vect_udot_qi } } } */
+/* { dg-final { scan-tree-dump "vectorizing SLP node starting from: \\S+ = DOT_PROD_EXPR" "vect" { target vect_sdot_hi } } } */
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 8187dbc47f1d..895fb88ab7fe 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -64,8 +64,6 @@ static bool vect_transform_slp_perm_load_1 (vec_info *, slp_tree,
 static int vectorizable_slp_permutation_1 (vec_info *, gimple_stmt_iterator *,
 					   slp_tree, lane_permutation_t &,
 					   vec<slp_tree> &, bool);
-static bool vectorizable_slp_permutation (vec_info *, gimple_stmt_iterator *,
-					  slp_tree, stmt_vector_for_cost *);
 static void vect_print_slp_tree (dump_flags_t, dump_location_t, slp_tree);
 static bool vect_slp_can_convert_to_external (const vec<stmt_vec_info> &);
 
@@ -8072,6 +8070,7 @@ vect_slp_analyze_node_operations_1 (vec_info *vinfo, slp_tree node,
 					       false, cost_vec))
 	    return false;
 	}
+      SLP_TREE_TYPE (node) = permute_info_type;
       return true;
     }
 
@@ -11359,7 +11358,7 @@ vectorizable_slp_permutation_1 (vec_info *vinfo, gimple_stmt_iterator *gsi,
      [ { 0, 2 }, { 0, 3 } ]
    Where currently only a subset is supported by code generating below.  */
 
-static bool
+bool
 vectorizable_slp_permutation (vec_info *vinfo, gimple_stmt_iterator *gsi,
 			      slp_tree node, stmt_vector_for_cost *cost_vec)
 {
@@ -11596,37 +11595,20 @@ vect_schedule_slp_node (vec_info *vinfo,
 	}
     }
 
-  /* Handle purely internal nodes.  */
-  if (SLP_TREE_PERMUTE_P (node))
-    {
-      if (dump_enabled_p ())
-	dump_printf_loc (MSG_NOTE, vect_location,
-			 "------>vectorizing SLP permutation node\n");
-      /* ???  the transform kind was stored to STMT_VINFO_TYPE which might
-	 be shared with different SLP nodes (but usually it's the same
-	 operation apart from the case the stmt is only there for denoting
-	 the actual scalar lane defs ...).  So do not call vect_transform_stmt
-	 but open-code it here (partly).  */
-      bool done = vectorizable_slp_permutation (vinfo, &si, node, NULL);
-      gcc_assert (done);
-      stmt_vec_info slp_stmt_info;
-      unsigned int i;
-      FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, slp_stmt_info)
-	if (slp_stmt_info && STMT_VINFO_LIVE_P (slp_stmt_info))
-	  {
-	    done = vectorizable_live_operation (vinfo, slp_stmt_info, node,
-						instance, i, true, NULL);
-	    gcc_assert (done);
-	  }
-    }
-  else
+  if (dump_enabled_p ())
     {
-      if (dump_enabled_p ())
+      if (stmt_info)
 	dump_printf_loc (MSG_NOTE, vect_location,
 			 "------>vectorizing SLP node starting from: %G",
 			 stmt_info->stmt);
-      vect_transform_stmt (vinfo, stmt_info, &si, node, instance);
+      else
+	{
+	  dump_printf_loc (MSG_NOTE, vect_location,
+			   "------>vectorizing SLP node:\n");
+	  vect_print_slp_tree (MSG_NOTE, vect_location, node);
+	}
     }
+  vect_transform_stmt (vinfo, stmt_info, &si, node, instance);
 }
 
 /* Replace scalar calls from SLP node NODE with setting of their lhs to zero.
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 852bc401035e..d46c1e3d56d2 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12731,11 +12731,8 @@ vect_transform_stmt (vec_info *vinfo,
 
   gcc_assert (slp_node);
 
-  if (dump_enabled_p ())
-    dump_printf_loc (MSG_NOTE, vect_location,
-		     "------>vectorizing statement: %G", stmt_info->stmt);
-
-  STMT_VINFO_VECTYPE (stmt_info) = NULL_TREE;
+  if (stmt_info)
+    STMT_VINFO_VECTYPE (stmt_info) = NULL_TREE;
 
   switch (SLP_TREE_TYPE (slp_node))
     {
@@ -12845,6 +12842,11 @@ vect_transform_stmt (vec_info *vinfo,
       gcc_assert (done);
       break;
 
+    case permute_info_type:
+      done = vectorizable_slp_permutation (vinfo, gsi, slp_node, NULL);
+      gcc_assert (done);
+      break;
+
     default:
       if (!STMT_VINFO_LIVE_P (stmt_info))
 	{
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 34a3a57e904b..b7c2188ab3d7 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -242,7 +242,8 @@ enum stmt_vec_info_type {
   lc_phi_info_type,
   phi_info_type,
   recurr_info_type,
-  loop_exit_ctrl_vec_info_type
+  loop_exit_ctrl_vec_info_type,
+  permute_info_type
 };
 
 /************************************************************************
@@ -2755,6 +2756,8 @@ extern bool vect_transform_slp_perm_load (vec_info *, slp_tree, const vec<tree>
 					  gimple_stmt_iterator *, poly_uint64,
 					  bool, unsigned *,
 					  unsigned * = nullptr, bool = false);
+extern bool vectorizable_slp_permutation (vec_info *, gimple_stmt_iterator *,
+					  slp_tree, stmt_vector_for_cost *);
 extern bool vect_slp_analyze_operations (vec_info *);
 extern void vect_schedule_slp (vec_info *, const vec<slp_instance> &);
 extern opt_result vect_analyze_slp (vec_info *, unsigned, bool);


More information about the Gcc-cvs mailing list