]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Integrate SLP permute transform into vect_transform_stmt
authorRichard Biener <rguenther@suse.de>
Fri, 12 Sep 2025 11:52:51 +0000 (13:52 +0200)
committerRichard Biener <rguenther@suse.de>
Sun, 14 Sep 2025 09:08:10 +0000 (11:08 +0200)
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.

gcc/testsuite/gcc.dg/vect/vect-reduc-chain-2.c
gcc/testsuite/gcc.dg/vect/vect-reduc-chain-3.c
gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc
gcc/tree-vectorizer.h

index 5bc2686fc9d674be2fa81f7a2f6a72be7c4b57e8..0d8d012ec2eae1a5e422e29ba8a966c5c76317af 100644 (file)
@@ -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 } } } } */
index 6a733fbac5343aadda32b1d69028d6107783079e..1cefbe0b959f0e7df0cfaa760739c0825bddba28 100644 (file)
@@ -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 } } } */
index 8187dbc47f1d7a79ca2a6955cd4d0a32d3e80340..895fb88ab7fe8a04df54dd3b58dfec52cc66b7d3 100644 (file)
@@ -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.
index 852bc401035e66c86052b77ff9b19d0d074b205d..d46c1e3d56d205aa5bbccc5a542c64d014d4d705 100644 (file)
@@ -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))
        {
index 34a3a57e904b0fbd5d8bde71634d4179847ac568..b7c2188ab3d7bee426697af5e3f4c8f87842a2b0 100644 (file)
@@ -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);