]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Add helper macros for gather/scatter.
authorRobin Dapp <rdapp@ventanamicro.com>
Thu, 3 Jul 2025 09:04:25 +0000 (11:04 +0200)
committerRobin Dapp <rdapp@ventanamicro.com>
Thu, 24 Jul 2025 14:12:39 +0000 (16:12 +0200)
This encapsulates the IFN and the builtin-function way of handling
gather/scatter via three defines:

  GATHER_SCATTER_IFN_P
  GATHER_SCATTER_LEGACY_P
  GATHER_SCATTER_EMULATED_P

and introduces a helper define for SLP operand handling as well.

gcc/ChangeLog:

* tree-vect-slp.cc (GATHER_SCATTER_OFFSET): New define.
(vect_get_and_check_slp_defs): Use.
* tree-vectorizer.h (GATHER_SCATTER_LEGACY_P): New define.
(GATHER_SCATTER_IFN_P): Ditto.
(GATHER_SCATTER_EMULATED_P): Ditto.
* tree-vect-stmts.cc (vectorizable_store): Use.
(vectorizable_load): Use.

gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc
gcc/tree-vectorizer.h

index 7776b2f1d8e6ea86f3befab02cfc80cb2b61f7b1..cfa841b3ce232e2641f92a8630082de1aa271527 100644 (file)
@@ -507,6 +507,8 @@ vect_def_types_match (enum vect_def_type dta, enum vect_def_type dtb)
              && (dtb == vect_external_def || dtb == vect_constant_def)));
 }
 
+#define GATHER_SCATTER_OFFSET (-3)
+
 static const int no_arg_map[] = { 0 };
 static const int arg0_map[] = { 1, 0 };
 static const int arg1_map[] = { 1, 1 };
@@ -516,10 +518,10 @@ static const int arg1_arg4_arg5_map[] = { 3, 1, 4, 5 };
 static const int arg1_arg3_arg4_map[] = { 3, 1, 3, 4 };
 static const int arg3_arg2_map[] = { 2, 3, 2 };
 static const int op1_op0_map[] = { 2, 1, 0 };
-static const int off_map[] = { 1, -3 };
-static const int off_op0_map[] = { 2, -3, 0 };
-static const int off_arg2_arg3_map[] = { 3, -3, 2, 3 };
-static const int off_arg3_arg2_map[] = { 3, -3, 3, 2 };
+static const int off_map[] = { 1, GATHER_SCATTER_OFFSET };
+static const int off_op0_map[] = { 2, GATHER_SCATTER_OFFSET, 0 };
+static const int off_arg2_arg3_map[] = { 3, GATHER_SCATTER_OFFSET, 2, 3 };
+static const int off_arg3_arg2_map[] = { 3, GATHER_SCATTER_OFFSET, 3, 2 };
 static const int mask_call_maps[6][7] = {
   { 1, 1, },
   { 2, 1, 2, },
@@ -691,7 +693,7 @@ vect_get_and_check_slp_defs (vec_info *vinfo, unsigned char swap,
     {
       oprnd_info = (*oprnds_info)[i];
       int opno = map ? map[i] : int (i);
-      if (opno == -3)
+      if (opno == GATHER_SCATTER_OFFSET)
        {
          gcc_assert (STMT_VINFO_GATHER_SCATTER_P (stmt_info));
          if (!is_a <loop_vec_info> (vinfo)
index 7eb072b66dd2c7effdfa1eff8278a14d8f460f42..5b8168fdea14184031bec47174b900c4f5039794 100644 (file)
@@ -2455,7 +2455,7 @@ get_load_store_type (vec_info  *vinfo, stmt_vec_info stmt_info,
         If that failed for some reason (e.g. because another pattern
         took priority), just handle cases in which the offset already
         has the right type.  */
-      else if (gs_info->ifn != IFN_LAST
+      else if (GATHER_SCATTER_IFN_P (*gs_info)
               && !is_gimple_call (stmt_info->stmt)
               && !tree_nop_conversion_p (TREE_TYPE (gs_info->offset),
                                          TREE_TYPE (gs_info->offset_vectype)))
@@ -8104,7 +8104,8 @@ vectorizable_store (vec_info *vinfo,
        }
       else if (memory_access_type != VMAT_LOAD_STORE_LANES
               && (memory_access_type != VMAT_GATHER_SCATTER
-                  || (gs_info.decl && !VECTOR_BOOLEAN_TYPE_P (mask_vectype))))
+                  || (GATHER_SCATTER_LEGACY_P (gs_info)
+                      && !VECTOR_BOOLEAN_TYPE_P (mask_vectype))))
        {
          if (dump_enabled_p ())
            dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -8112,8 +8113,7 @@ vectorizable_store (vec_info *vinfo,
          return false;
        }
       else if (memory_access_type == VMAT_GATHER_SCATTER
-              && gs_info.ifn == IFN_LAST
-              && !gs_info.decl)
+              && GATHER_SCATTER_EMULATED_P (gs_info))
        {
          if (dump_enabled_p ())
            dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -8838,7 +8838,7 @@ vectorizable_store (vec_info *vinfo,
                                               final_mask, vec_mask, gsi);
            }
 
-         if (gs_info.ifn != IFN_LAST)
+         if (GATHER_SCATTER_IFN_P (gs_info))
            {
              if (costing_p)
                {
@@ -8901,7 +8901,7 @@ vectorizable_store (vec_info *vinfo,
              vect_finish_stmt_generation (vinfo, stmt_info, call, gsi);
              new_stmt = call;
            }
-          else if (gs_info.decl)
+         else if (GATHER_SCATTER_LEGACY_P (gs_info))
            {
              /* The builtin decls path for scatter is legacy, x86 only.  */
              gcc_assert (nunits.is_constant ()
@@ -9812,8 +9812,7 @@ vectorizable_load (vec_info *vinfo,
          return false;
        }
       else if (memory_access_type == VMAT_GATHER_SCATTER
-              && gs_info.ifn == IFN_LAST
-              && !gs_info.decl)
+              && GATHER_SCATTER_EMULATED_P (gs_info))
        {
          if (dump_enabled_p ())
            dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -10775,7 +10774,7 @@ vectorizable_load (vec_info *vinfo,
 
          /* 2. Create the vector-load in the loop.  */
          unsigned HOST_WIDE_INT align;
-         if (gs_info.ifn != IFN_LAST)
+         if (GATHER_SCATTER_IFN_P (gs_info))
            {
              if (costing_p)
                {
@@ -10847,7 +10846,7 @@ vectorizable_load (vec_info *vinfo,
              new_stmt = call;
              data_ref = NULL_TREE;
            }
-         else if (gs_info.decl)
+         else if (GATHER_SCATTER_LEGACY_P (gs_info))
            {
              /* The builtin decls path for gather is legacy, x86 only.  */
              gcc_assert (!final_len && nunits.is_constant ());
index 80f8853733de566fcd3499b2ddeafa08a006b4d5..0f9b529fcea559abad467f5c297e7dff9a219d51 100644 (file)
@@ -1655,6 +1655,14 @@ struct gather_scatter_info {
 #define PURE_SLP_STMT(S)                  ((S)->slp_type == pure_slp)
 #define STMT_SLP_TYPE(S)                   (S)->slp_type
 
+#define GATHER_SCATTER_LEGACY_P(info) ((info).decl != NULL_TREE \
+                                      && (info).ifn == IFN_LAST)
+#define GATHER_SCATTER_IFN_P(info) ((info).decl == NULL_TREE \
+                                   && (info).ifn != IFN_LAST)
+#define GATHER_SCATTER_EMULATED_P(info) ((info).decl == NULL_TREE \
+                                        && (info).ifn == IFN_LAST)
+
+
 /* Contains the scalar or vector costs for a vec_info.  */
 class vector_costs
 {