]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Pass vectype to vect_check_gather_scatter
authorRichard Biener <rguenther@suse.de>
Mon, 1 Sep 2025 13:01:24 +0000 (15:01 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 2 Sep 2025 10:51:12 +0000 (12:51 +0200)
The strided-store path needs to have the SLP trees vector type so
the following patch passes dowm the vector type to be used to
vect_check_gather_scatter and adjusts all other callers.  This
removes one of the last pieces requiring STMT_VINFO_VECTYPE
during SLP stmt analysis.

* tree-vectorizer.h (vect_check_gather_scatter): Add
vectype parameter.
* tree-vect-data-refs.cc (vect_check_gather_scatter): Get
vectype as parameter.
(vect_analyze_data_refs): Adjust.
* tree-vect-patterns.cc (vect_recog_gather_scatter_pattern): Likewise.
* tree-vect-slp.cc (vect_get_and_check_slp_defs): Get vectype
as parameter, pass down.
(vect_build_slp_tree_2): Adjust.
* tree-vect-stmts.cc (vect_mark_stmts_to_be_vectorized): Likewise.
(vect_use_strided_gather_scatters_p): Likewise.

gcc/tree-vect-data-refs.cc
gcc/tree-vect-patterns.cc
gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc
gcc/tree-vectorizer.h

index f9bf6a2169706a5b4ca02f823d911b08ad6de785..1395776599a2ae4f607bf04b3b4b18bb5d278f34 100644 (file)
@@ -4554,12 +4554,13 @@ vect_describe_gather_scatter_call (stmt_vec_info stmt_info,
 }
 
 /* Return true if a non-affine read or write in STMT_INFO is suitable for a
-   gather load or scatter store.  Describe the operation in *INFO if so.
-   If it is suitable and ELSVALS is nonzero store the supported else values
-   in the vector it points to.  */
+   gather load or scatter store with VECTYPE.  Describe the operation in *INFO
+   if so.  If it is suitable and ELSVALS is nonzero store the supported else
+   values in the vector it points to.  */
 
 bool
-vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
+vect_check_gather_scatter (stmt_vec_info stmt_info, tree vectype,
+                          loop_vec_info loop_vinfo,
                           gather_scatter_info *info, vec<int> *elsvals)
 {
   HOST_WIDE_INT scale = 1;
@@ -4568,7 +4569,6 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo,
   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
   tree offtype = NULL_TREE;
   tree decl = NULL_TREE, base, off;
-  tree vectype = STMT_VINFO_VECTYPE (stmt_info);
   tree memory_type = TREE_TYPE (DR_REF (dr));
   machine_mode pmode;
   int punsignedp, reversep, pvolatilep = 0;
@@ -5273,7 +5273,7 @@ vect_analyze_data_refs (vec_info *vinfo, bool *fatal)
       if (gatherscatter != SG_NONE)
        {
          gather_scatter_info gs_info;
-         if (!vect_check_gather_scatter (stmt_info,
+         if (!vect_check_gather_scatter (stmt_info, vectype,
                                          as_a <loop_vec_info> (vinfo),
                                          &gs_info)
              || !get_vectype_for_scalar_type (vinfo,
index 16694d7991cdf3cf99fd523f341bcaf8ca1f041e..64a49cccc2450ef061e2386cabfe1762c3c82a16 100644 (file)
@@ -6032,16 +6032,17 @@ vect_recog_gather_scatter_pattern (vec_info *vinfo,
      This is null if the operation is unconditional.  */
   tree mask = vect_get_load_store_mask (stmt_info);
 
+  /* DR analysis nailed down the vector type for the access.  */
+  tree gs_vectype = STMT_VINFO_VECTYPE (stmt_info);
+
   /* Make sure that the target supports an appropriate internal
      function for the gather/scatter operation.  */
   gather_scatter_info gs_info;
-  if (!vect_check_gather_scatter (stmt_info, loop_vinfo, &gs_info)
+  if (!vect_check_gather_scatter (stmt_info, gs_vectype, loop_vinfo, &gs_info)
       || gs_info.ifn == IFN_LAST)
     return NULL;
 
   /* Convert the mask to the right form.  */
-  tree gs_vectype = get_vectype_for_scalar_type (loop_vinfo,
-                                                gs_info.element_type);
   if (mask)
     mask = vect_convert_mask_for_vectype (mask, gs_vectype, stmt_info,
                                          loop_vinfo);
@@ -6103,8 +6104,7 @@ vect_recog_gather_scatter_pattern (vec_info *vinfo,
   stmt_vec_info pattern_stmt_info = loop_vinfo->add_stmt (pattern_stmt);
   loop_vinfo->move_dr (pattern_stmt_info, stmt_info);
 
-  tree vectype = STMT_VINFO_VECTYPE (stmt_info);
-  *type_out = vectype;
+  *type_out = gs_vectype;
   vect_pattern_detected ("gather/scatter pattern", stmt_info->stmt);
 
   return pattern_stmt;
index 5236eac5a42a8fea60147a58c9091a0a73925349..6258a8eb53de10d03d244682b60d68b5c6218883 100644 (file)
@@ -641,7 +641,7 @@ vect_slp_child_index_for_operand (const gimple *stmt, int op,
    swapping operands of father node of this one, return 1; if everything is
    ok return 0.  */
 static int
-vect_get_and_check_slp_defs (vec_info *vinfo, unsigned char swap,
+vect_get_and_check_slp_defs (vec_info *vinfo, tree vectype, unsigned char swap,
                             bool *skip_args,
                             vec<stmt_vec_info> stmts, unsigned stmt_num,
                             vec<slp_oprnd_info> *oprnds_info)
@@ -711,7 +711,7 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned char swap,
        {
          gcc_assert (STMT_VINFO_GATHER_SCATTER_P (stmt_info));
          if (!is_a <loop_vec_info> (vinfo)
-             || !vect_check_gather_scatter (stmt_info,
+             || !vect_check_gather_scatter (stmt_info, vectype,
                                             as_a <loop_vec_info> (vinfo),
                                             first ? &oprnd_info->first_gs_info
                                             : &gs_info))
@@ -2618,7 +2618,8 @@ out:
   slp_oprnd_info oprnd_info;
   FOR_EACH_VEC_ELT (stmts, i, stmt_info)
     {
-      int res = vect_get_and_check_slp_defs (vinfo, swap[i], skip_args,
+      int res = vect_get_and_check_slp_defs (vinfo, vectype,
+                                            swap[i], skip_args,
                                             stmts, i, &oprnds_info);
       if (res != 0)
        matches[(res == -1) ? 0 : i] = false;
index 15e0d069dccd7226322673307a40236cfdbfdc6d..b63a180811e32a674724f605e3fed421712c911e 100644 (file)
@@ -891,7 +891,9 @@ vect_mark_stmts_to_be_vectorized (loop_vec_info loop_vinfo, bool *fatal)
       if (STMT_VINFO_GATHER_SCATTER_P (stmt_vinfo))
        {
          gather_scatter_info gs_info;
-         if (!vect_check_gather_scatter (stmt_vinfo, loop_vinfo, &gs_info))
+         if (!vect_check_gather_scatter (stmt_vinfo,
+                                         STMT_VINFO_VECTYPE (stmt_vinfo),
+                                         loop_vinfo, &gs_info))
            gcc_unreachable ();
          opt_result res
            = process_use (stmt_vinfo, gs_info.offset, loop_vinfo, relevant,
@@ -1738,7 +1740,8 @@ vect_use_strided_gather_scatters_p (stmt_vec_info stmt_info, tree vectype,
                                    unsigned int group_size,
                                    bool single_element_p)
 {
-  if (!vect_check_gather_scatter (stmt_info, loop_vinfo, gs_info, elsvals)
+  if (!vect_check_gather_scatter (stmt_info, vectype,
+                                 loop_vinfo, gs_info, elsvals)
       || gs_info->ifn == IFN_LAST)
     {
       if (!vect_truncate_gather_scatter_offset (stmt_info, vectype, loop_vinfo,
index 260cb2ddd3e6957f6383f9a1537dd1fab56b39c7..87ffe497008a2ba7aa4606b6c802695a2ac4673e 100644 (file)
@@ -2622,8 +2622,8 @@ extern opt_result vect_prune_runtime_alias_test_list (loop_vec_info);
 extern bool vect_gather_scatter_fn_p (vec_info *, bool, bool, tree, tree,
                                      tree, int, internal_fn *, tree *,
                                      vec<int> * = nullptr);
-extern bool vect_check_gather_scatter (stmt_vec_info, loop_vec_info,
-                                      gather_scatter_info *,
+extern bool vect_check_gather_scatter (stmt_vec_info, tree,
+                                      loop_vec_info, gather_scatter_info *,
                                       vec<int> * = nullptr);
 extern void vect_describe_gather_scatter_call (stmt_vec_info,
                                               gather_scatter_info *);