On Mon, Sep 15, 2025 at 8:51 PM Robin Dapp <rdapp....@gmail.com> wrote:
>
> Hi,
>
> This patch removes the type argument from the vector_misalignment hook.
> Ever since we switched from element to byte misalignment its
> semantics haven't been particularly clear and nowadays it should be
> redundant.
>
> Also, in case of gather/scatter, the patch sets misalignment to the
> misalignment of one unit of the vector mode so targets can
> distinguish between element size alignment and element mode alignment.
>
> is_packed is now always set, regardless of misalignment.
>
> Regtested and bootstrapped on x86 and power10.  Regtested on aarch64 and
> rv64gcv_zvl512b.

OK.

Thanks,
Richard.

> Regards
>  Robin
>
> gcc/ChangeLog:
>
>         * config/aarch64/aarch64.cc 
> (aarch64_builtin_support_vector_misalignment):
>         Remove type.
>         * config/arm/arm.cc (arm_builtin_support_vector_misalignment):
>         Ditto.
>         * config/epiphany/epiphany.cc (epiphany_support_vector_misalignment):
>         Ditto.
>         * config/gcn/gcn.cc (gcn_vectorize_support_vector_misalignment):
>         Ditto.
>         * config/loongarch/loongarch.cc 
> (loongarch_builtin_support_vector_misalignment):
>         Ditto.
>         * config/riscv/riscv.cc (riscv_support_vector_misalignment):
>         Ditto.
>         * config/rs6000/rs6000.cc 
> (rs6000_builtin_support_vector_misalignment):
>         Ditto.
>         * config/s390/s390.cc (s390_support_vector_misalignment):
>         Ditto.
>         * doc/tm.texi: Adjust vector misalignment docs.
>         * target.def: Ditto.
>         * targhooks.cc (default_builtin_support_vector_misalignment):
>         Remove type.
>         * targhooks.h (default_builtin_support_vector_misalignment):
>         Ditto.
>         * tree-vect-data-refs.cc (vect_can_force_dr_alignment_p):
>         Set misalignment for gather/scatter and remove type.
>         (vect_supportable_dr_alignment): Ditto.
> ---
>  gcc/config/aarch64/aarch64.cc     |  5 ++---
>  gcc/config/arm/arm.cc             |  5 ++---
>  gcc/config/epiphany/epiphany.cc   |  6 +++---
>  gcc/config/gcn/gcn.cc             |  7 ++++---
>  gcc/config/loongarch/loongarch.cc |  3 +--
>  gcc/config/riscv/riscv.cc         | 11 +++++------
>  gcc/config/rs6000/rs6000.cc       | 13 ++++++-------
>  gcc/config/s390/s390.cc           |  3 +--
>  gcc/doc/tm.texi                   | 12 ++++++------
>  gcc/target.def                    | 12 ++++++------
>  gcc/targhooks.cc                  |  2 --
>  gcc/targhooks.h                   |  1 -
>  gcc/tree-vect-data-refs.cc        | 14 ++++++++------
>  13 files changed, 44 insertions(+), 50 deletions(-)
>
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index ef9c16598c0..baa38fcc4b3 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -354,7 +354,6 @@ static void aarch64_override_options_after_change (void);
>  static bool aarch64_vector_mode_supported_p (machine_mode);
>  static int aarch64_address_cost (rtx, machine_mode, addr_space_t, bool);
>  static bool aarch64_builtin_support_vector_misalignment (machine_mode mode,
> -                                                        const_tree type,
>                                                          int misalignment,
>                                                          bool is_packed,
>                                                          bool 
> is_gather_scatter);
> @@ -24601,7 +24600,7 @@ aarch64_simd_vector_alignment_reachable (const_tree 
> type, bool is_packed)
>     target.  */
>  static bool
>  aarch64_builtin_support_vector_misalignment (machine_mode mode,
> -                                            const_tree type, int 
> misalignment,
> +                                            int misalignment,
>                                              bool is_packed,
>                                              bool is_gather_scatter)
>  {
> @@ -24618,7 +24617,7 @@ aarch64_builtin_support_vector_misalignment 
> (machine_mode mode,
>        if (misalignment == -1)
>         return false;
>      }
> -  return default_builtin_support_vector_misalignment (mode, type, 
> misalignment,
> +  return default_builtin_support_vector_misalignment (mode, misalignment,
>                                                       is_packed,
>                                                       is_gather_scatter);
>  }
> diff --git a/gcc/config/arm/arm.cc b/gcc/config/arm/arm.cc
> index 8b951f3d4a6..f074a429200 100644
> --- a/gcc/config/arm/arm.cc
> +++ b/gcc/config/arm/arm.cc
> @@ -287,7 +287,6 @@ static bool arm_class_likely_spilled_p (reg_class_t);
>  static HOST_WIDE_INT arm_vector_alignment (const_tree type);
>  static bool arm_vector_alignment_reachable (const_tree type, bool is_packed);
>  static bool arm_builtin_support_vector_misalignment (machine_mode mode,
> -                                                    const_tree type,
>                                                      int misalignment,
>                                                      bool is_packed,
>                                                      bool is_gather_scatter);
> @@ -30662,7 +30661,7 @@ arm_vector_alignment_reachable (const_tree type, bool 
> is_packed)
>
>  static bool
>  arm_builtin_support_vector_misalignment (machine_mode mode,
> -                                        const_tree type, int misalignment,
> +                                        int misalignment,
>                                          bool is_packed,
>                                          bool is_gather_scatter)
>  {
> @@ -30688,7 +30687,7 @@ arm_builtin_support_vector_misalignment (machine_mode 
> mode,
>        return ((misalignment % align) == 0);
>      }
>
> -  return default_builtin_support_vector_misalignment (mode, type, 
> misalignment,
> +  return default_builtin_support_vector_misalignment (mode, misalignment,
>                                                       is_packed,
>                                                       is_gather_scatter);
>  }
> diff --git a/gcc/config/epiphany/epiphany.cc b/gcc/config/epiphany/epiphany.cc
> index f53a643575b..2446b02389a 100644
> --- a/gcc/config/epiphany/epiphany.cc
> +++ b/gcc/config/epiphany/epiphany.cc
> @@ -2815,15 +2815,15 @@ epiphany_vector_alignment_reachable (const_tree type, 
> bool is_packed)
>  }
>
>  static bool
> -epiphany_support_vector_misalignment (machine_mode mode, const_tree type,
> -                                     int misalignment, bool is_packed,
> +epiphany_support_vector_misalignment (machine_mode mode, int misalignment,
> +                                     bool is_packed,
>                                       bool is_gather_scatter)
>  {
>    if (is_gather_scatter)
>      return true;
>    if (GET_MODE_SIZE (mode) == 8 && misalignment % 4 == 0)
>      return true;
> -  return default_builtin_support_vector_misalignment (mode, type, 
> misalignment,
> +  return default_builtin_support_vector_misalignment (mode, misalignment,
>                                                       is_packed,
>                                                       is_gather_scatter);
>  }
> diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
> index df1c1a5b19b..b26b0cda9ae 100644
> --- a/gcc/config/gcn/gcn.cc
> +++ b/gcc/config/gcn/gcn.cc
> @@ -5368,14 +5368,14 @@ gcn_preferred_vector_alignment (const_tree type)
>
>  static bool
>  gcn_vectorize_support_vector_misalignment (machine_mode ARG_UNUSED (mode),
> -                                          const_tree type, int misalignment,
> +                                          int misalignment,
>                                            bool is_packed,
>                                            bool is_gather_scatter)
>  {
>    if (is_gather_scatter)
>      return true;
>
> -  if (is_packed)
> +  if (misalignment == DR_MISALIGNMENT_UNKNOWN && is_packed)
>      return false;
>
>    /* If the misalignment is unknown, we should be able to handle the access
> @@ -5387,7 +5387,8 @@ gcn_vectorize_support_vector_misalignment (machine_mode 
> ARG_UNUSED (mode),
>       of the vector's element type.  This is probably always going to be
>       true in practice, since we've already established that this isn't a
>       packed access.  */
> -  return misalignment % TYPE_ALIGN_UNIT (type) == 0;
> +  return misalignment
> +    % (GET_MODE_ALIGNMENT (GET_MODE_INNER (mode)) / BITS_PER_UNIT) == 0;
>  }
>
>  /* Implement TARGET_VECTORIZE_VECTOR_ALIGNMENT_REACHABLE.
> diff --git a/gcc/config/loongarch/loongarch.cc 
> b/gcc/config/loongarch/loongarch.cc
> index ef5d5f4e060..145ed644f8b 100644
> --- a/gcc/config/loongarch/loongarch.cc
> +++ b/gcc/config/loongarch/loongarch.cc
> @@ -11058,7 +11058,6 @@ void loongarch_emit_swdivsf (rtx res, rtx a, rtx b, 
> machine_mode mode)
>
>  static bool
>  loongarch_builtin_support_vector_misalignment (machine_mode mode,
> -                                              const_tree type,
>                                                int misalignment,
>                                                bool is_packed,
>                                                bool is_gather_scatter)
> @@ -11072,7 +11071,7 @@ loongarch_builtin_support_vector_misalignment 
> (machine_mode mode,
>        if (misalignment == -1)
>         return false;
>      }
> -  return default_builtin_support_vector_misalignment (mode, type, 
> misalignment,
> +  return default_builtin_support_vector_misalignment (mode, misalignment,
>                                                       is_packed,
>                                                       is_gather_scatter);
>  }
> diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
> index b93103616b8..959caf23b43 100644
> --- a/gcc/config/riscv/riscv.cc
> +++ b/gcc/config/riscv/riscv.cc
> @@ -12648,12 +12648,11 @@ riscv_estimated_poly_value (poly_int64 val,
>  /* Return true if the vector misalignment factor is supported by the
>     target.  */
>  bool
> -riscv_support_vector_misalignment (machine_mode mode, const_tree type,
> -                                  int misalignment, bool is_packed,
> -                                  bool is_gather_scatter)
> +riscv_support_vector_misalignment (machine_mode mode, int misalignment,
> +                                  bool is_packed, bool is_gather_scatter)
>  {
>    /* IS_PACKED is true if the corresponding scalar element is not naturally
> -     aligned.  If the misalignment is unknown and the the access is packed
> +     aligned.  If the misalignment is unknown and the access is packed
>       we defer to the default hook which will check if movmisalign is present.
>       Movmisalign, in turn, depends on TARGET_VECTOR_MISALIGN_SUPPORTED.  */
>    if (misalignment == DR_MISALIGNMENT_UNKNOWN)
> @@ -12665,12 +12664,12 @@ riscv_support_vector_misalignment (machine_mode 
> mode, const_tree type,
>      {
>        /* If we know that misalignment is a multiple of the element size, 
> we're
>          good.  */
> -      if (misalignment % TYPE_ALIGN_UNIT (type) == 0)
> +      if (misalignment % (GET_MODE_UNIT_SIZE (GET_MODE_INNER (mode))) == 0)
>         return true;
>      }
>
>    /* Otherwise fall back to movmisalign again.  */
> -  return default_builtin_support_vector_misalignment (mode, type, 
> misalignment,
> +  return default_builtin_support_vector_misalignment (mode, misalignment,
>                                                       is_packed,
>                                                       is_gather_scatter);
>  }
> diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
> index 8dd23f8619c..66e95c557e0 100644
> --- a/gcc/config/rs6000/rs6000.cc
> +++ b/gcc/config/rs6000/rs6000.cc
> @@ -4949,7 +4949,6 @@ rs6000_vector_alignment_reachable (const_tree type 
> ATTRIBUTE_UNUSED, bool is_pac
>     target.  */
>  static bool
>  rs6000_builtin_support_vector_misalignment (machine_mode mode,
> -                                           const_tree type,
>                                             int misalignment,
>                                             bool is_packed,
>                                             bool is_gather_scatter)
> @@ -4975,13 +4974,13 @@ rs6000_builtin_support_vector_misalignment 
> (machine_mode mode,
>         {
>           /* Misalignment factor is unknown at compile time but we know
>              it's word aligned.  */
> -         if (rs6000_vector_alignment_reachable (type, is_packed))
> -            {
> -              int element_size = TREE_INT_CST_LOW (TYPE_SIZE (type));
> +         if (rs6000_vector_alignment_reachable (NULL_TREE, is_packed))
> +           {
> +             int element_size = GET_MODE_UNIT_BITSIZE (mode);
>
> -              if (element_size == 64 || element_size == 32)
> -               return true;
> -            }
> +             if (element_size == 64 || element_size == 32)
> +               return true;
> +           }
>
>           return false;
>         }
> diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
> index 1a47f477dd3..d65109026f2 100644
> --- a/gcc/config/s390/s390.cc
> +++ b/gcc/config/s390/s390.cc
> @@ -17503,7 +17503,6 @@ s390_preferred_simd_mode (scalar_mode mode)
>  /* Our hardware does not require vectors to be strictly aligned.  */
>  static bool
>  s390_support_vector_misalignment (machine_mode mode ATTRIBUTE_UNUSED,
> -                                 const_tree type ATTRIBUTE_UNUSED,
>                                   int misalignment ATTRIBUTE_UNUSED,
>                                   bool is_packed ATTRIBUTE_UNUSED,
>                                   bool is_gather_scatter ATTRIBUTE_UNUSED)
> @@ -17511,7 +17510,7 @@ s390_support_vector_misalignment (machine_mode mode 
> ATTRIBUTE_UNUSED,
>    if (TARGET_VX)
>      return true;
>
> -  return default_builtin_support_vector_misalignment (mode, type, 
> misalignment,
> +  return default_builtin_support_vector_misalignment (mode, misalignment,
>                                                       is_packed,
>                                                       is_gather_scatter);
>  }
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index b80e6846dd7..2351bc7b29d 100644
> --- a/gcc/doc/tm.texi
> +++ b/gcc/doc/tm.texi
> @@ -6388,14 +6388,14 @@ return type of the vectorized function shall be of 
> vector type
>  @var{vec_type_out} and the argument types should be @var{vec_type_in}.
>  @end deftypefn
>
> -@deftypefn {Target Hook} bool TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT 
> (machine_mode @var{mode}, const_tree @var{type}, int @var{misalignment}, bool 
> @var{is_packed}, bool @var{is_gather_scatter})
> +@deftypefn {Target Hook} bool TARGET_VECTORIZE_SUPPORT_VECTOR_MISALIGNMENT 
> (machine_mode @var{mode}, int @var{misalignment}, bool @var{is_packed}, bool 
> @var{is_gather_scatter})
>  This hook should return true if the target supports misaligned vector
>  store/load of a specific factor denoted in the @var{misalignment}
> -parameter.  The vector store/load should be of machine mode @var{mode} and
> -the elements in the vectors should be of type @var{type}.  The
> -@var{is_packed} parameter is true if the misalignment is unknown and the
> -memory access is defined in a packed struct.  @var{is_gather_scatter} is true
> -if the load/store is a gather or scatter.
> +parameter.  The vector store/load should be of machine mode @var{mode}.
> +The @var{is_packed} parameter is true if the misalignment is unknown and the
> +original memory access not naturally aligned.  @var{is_gather_scatter} is
> +true if the load/store is a gather or scatter.  In that case misalignment
> +denotes the misalignment of @var{mode}'s element mode.
>  @end deftypefn
>
>  @deftypefn {Target Hook} machine_mode TARGET_VECTORIZE_PREFERRED_SIMD_MODE 
> (scalar_mode @var{mode})
> diff --git a/gcc/target.def b/gcc/target.def
> index d4fd3b46a7d..4933aab87a3 100644
> --- a/gcc/target.def
> +++ b/gcc/target.def
> @@ -1925,13 +1925,13 @@ DEFHOOK
>  (support_vector_misalignment,
>   "This hook should return true if the target supports misaligned vector\n\
>  store/load of a specific factor denoted in the @var{misalignment}\n\
> -parameter.  The vector store/load should be of machine mode @var{mode} and\n\
> -the elements in the vectors should be of type @var{type}.  The\n\
> -@var{is_packed} parameter is true if the misalignment is unknown and the\n\
> -memory access is defined in a packed struct.  @var{is_gather_scatter} is 
> true\n\
> -if the load/store is a gather or scatter.",
> +parameter.  The vector store/load should be of machine mode @var{mode}.\n\
> +The @var{is_packed} parameter is true if the misalignment is unknown and 
> the\n\
> +original memory access not naturally aligned.  @var{is_gather_scatter} is\n\
> +true if the load/store is a gather or scatter.  In that case misalignment\n\
> +denotes the misalignment of @var{mode}'s element mode.",
>   bool,
> - (machine_mode mode, const_tree type, int misalignment, bool is_packed,
> + (machine_mode mode, int misalignment, bool is_packed,
>    bool is_gather_scatter),
>   default_builtin_support_vector_misalignment)
>
> diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc
> index 947e39aedc1..dfd46eeb8af 100644
> --- a/gcc/targhooks.cc
> +++ b/gcc/targhooks.cc
> @@ -1551,8 +1551,6 @@ default_builtin_vector_alignment_reachable (const_tree 
> /*type*/, bool is_packed)
>     is_packed is true if the memory access is defined in a packed struct.  */
>  bool
>  default_builtin_support_vector_misalignment (machine_mode mode,
> -                                            const_tree type
> -                                            ATTRIBUTE_UNUSED,
>                                              int misalignment
>                                              ATTRIBUTE_UNUSED,
>                                              bool is_packed
> diff --git a/gcc/targhooks.h b/gcc/targhooks.h
> index 34c30d4af45..44120676345 100644
> --- a/gcc/targhooks.h
> +++ b/gcc/targhooks.h
> @@ -113,7 +113,6 @@ extern poly_uint64 default_preferred_vector_alignment 
> (const_tree);
>  extern bool default_builtin_vector_alignment_reachable (const_tree, bool);
>  extern bool
>  default_builtin_support_vector_misalignment (machine_mode mode,
> -                                            const_tree,
>                                              int, bool, bool);
>  extern machine_mode default_preferred_simd_mode (scalar_mode mode);
>  extern machine_mode default_split_reduction (machine_mode);
> diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc
> index a31ff93bbd3..56706b965c8 100644
> --- a/gcc/tree-vect-data-refs.cc
> +++ b/gcc/tree-vect-data-refs.cc
> @@ -6522,7 +6522,8 @@ vect_can_force_dr_alignment_p (const_tree decl, 
> poly_uint64 alignment)
>     alignment.
>     If CHECK_ALIGNED_ACCESSES is TRUE, check if the access is supported even
>     it is aligned, i.e., check if it is possible to vectorize it with 
> different
> -   alignment.  If GS_INFO is passed we are dealing with a gather/scatter.  */
> +   alignment.  If IS_GATHER_SCATTER is true we are dealing with a
> +   gather/scatter.  */
>
>  enum dr_alignment_support
>  vect_supportable_dr_alignment (vec_info *vinfo, dr_vec_info *dr_info,
> @@ -6636,11 +6637,12 @@ vect_supportable_dr_alignment (vec_info *vinfo, 
> dr_vec_info *dr_info,
>         }
>      }
>
> -  bool is_packed = false;
> -  tree type = TREE_TYPE (DR_REF (dr));
> -  if (misalignment == DR_MISALIGNMENT_UNKNOWN)
> -    is_packed = not_size_aligned (DR_REF (dr));
> -  if (targetm.vectorize.support_vector_misalignment (mode, type, 
> misalignment,
> +  bool is_packed = not_size_aligned (DR_REF (dr));
> +  if (misalignment == DR_MISALIGNMENT_UNKNOWN
> +      && is_gather_scatter)
> +    misalignment = (get_object_alignment (DR_REF (dr))
> +                   % (GET_MODE_BITSIZE (GET_MODE_INNER (mode)))) / 
> BITS_PER_UNIT;
> +  if (targetm.vectorize.support_vector_misalignment (mode, misalignment,
>                                                      is_packed,
>                                                      is_gather_scatter))
>      return dr_unaligned_supported;
> --
> 2.51.0
>

Reply via email to