On Tue, 5 Nov 2024, Victor Do Nascimento wrote:
> This patch adds stmt_vec_info to TARGET_SIMD_CLONE_USABLE to make sure the
> target can reject a simd_clone based on the vector mode it is using.
> This is needed because for VLS SVE vectorization the vectorizer accepts
> Advanced SIMD simd clones when vectorizing using SVE types because the
> simdlens
> might match. This will cause type errors later on.
>
> Other targets do not currently need to use this argument.
>
> gcc/ChangeLog:
>
> * target.def (TARGET_SIMD_CLONE_USABLE): Add argument.
> * tree-vect-stmts.cc (vectorizable_simd_clone_call): Pass stmt_info to
> call TARGET_SIMD_CLONE_USABLE.
Pass vector mode ... here and in the cover letter. Note tm.texi as
regenerated.
Otherwise this is OK now.
Richard.
> * config/aarch64/aarch64.cc (aarch64_simd_clone_usable): Add argument
> and use it to reject the use of SVE simd clones with Advanced SIMD
> modes.
> * config/gcn/gcn.cc (gcn_simd_clone_usable): Add unused argument.
> * config/i386/i386.cc (ix86_simd_clone_usable): Likewise.
> ---
> gcc/config/aarch64/aarch64.cc | 4 ++--
> gcc/config/gcn/gcn.cc | 3 ++-
> gcc/config/i386/i386.cc | 3 ++-
> gcc/doc/tm.texi | 8 ++++----
> gcc/target.def | 8 ++++----
> gcc/tree-vect-stmts.cc | 9 ++++++++-
> 6 files changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
> index a6cc00e74ab..1e51d0e3604 100644
> --- a/gcc/config/aarch64/aarch64.cc
> +++ b/gcc/config/aarch64/aarch64.cc
> @@ -29189,12 +29189,12 @@ aarch64_simd_clone_adjust (struct cgraph_node *node)
> /* Implement TARGET_SIMD_CLONE_USABLE. */
>
> static int
> -aarch64_simd_clone_usable (struct cgraph_node *node)
> +aarch64_simd_clone_usable (struct cgraph_node *node, machine_mode
> vector_mode)
> {
> switch (node->simdclone->vecsize_mangle)
> {
> case 'n':
> - if (!TARGET_SIMD)
> + if (!TARGET_SIMD || aarch64_sve_mode_p (vector_mode))
> return -1;
> return 0;
> default:
> diff --git a/gcc/config/gcn/gcn.cc b/gcc/config/gcn/gcn.cc
> index d078392eeaf..04cbc770509 100644
> --- a/gcc/config/gcn/gcn.cc
> +++ b/gcc/config/gcn/gcn.cc
> @@ -5653,7 +5653,8 @@ gcn_simd_clone_adjust (struct cgraph_node *ARG_UNUSED
> (node))
> /* Implement TARGET_SIMD_CLONE_USABLE. */
>
> static int
> -gcn_simd_clone_usable (struct cgraph_node *ARG_UNUSED (node))
> +gcn_simd_clone_usable (struct cgraph_node *ARG_UNUSED (node),
> + machine_mode ARG_UNUSED (vector_mode))
> {
> /* We don't need to do anything here because
> gcn_simd_clone_compute_vecsize_and_simdlen currently only returns one
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 473e4cbf10e..eef12f8c9f0 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -25555,7 +25555,8 @@ ix86_simd_clone_compute_vecsize_and_simdlen (struct
> cgraph_node *node,
> slightly less desirable, etc.). */
>
> static int
> -ix86_simd_clone_usable (struct cgraph_node *node)
> +ix86_simd_clone_usable (struct cgraph_node *node,
> + machine_mode)
> {
> switch (node->simdclone->vecsize_mangle)
> {
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index 4deb3d2c283..e3a85882b83 100644
> --- a/gcc/doc/tm.texi
> +++ b/gcc/doc/tm.texi
> @@ -6523,11 +6523,11 @@ This hook should add implicit
> @code{attribute(target("..."))} attribute
> to SIMD clone @var{node} if needed.
> @end deftypefn
>
> -@deftypefn {Target Hook} int TARGET_SIMD_CLONE_USABLE (struct cgraph_node
> *@var{})
> +@deftypefn {Target Hook} int TARGET_SIMD_CLONE_USABLE (struct cgraph_node
> *@var{}, @var{machine_mode})
> This hook should return -1 if SIMD clone @var{node} shouldn't be used
> -in vectorized loops in current function, or non-negative number if it is
> -usable. In that case, the smaller the number is, the more desirable it is
> -to use it.
> +in vectorized loops in current function with @var{vector_mode}, or
> +non-negative number if it is usable. In that case, the smaller the number
> +is, the more desirable it is to use it.
> @end deftypefn
>
> @deftypefn {Target Hook} int TARGET_SIMT_VF (void)
> diff --git a/gcc/target.def b/gcc/target.def
> index 523ae7ec9aa..ad8a713c14a 100644
> --- a/gcc/target.def
> +++ b/gcc/target.def
> @@ -1645,10 +1645,10 @@ void, (struct cgraph_node *), NULL)
> DEFHOOK
> (usable,
> "This hook should return -1 if SIMD clone @var{node} shouldn't be used\n\
> -in vectorized loops in current function, or non-negative number if it is\n\
> -usable. In that case, the smaller the number is, the more desirable it is\n\
> -to use it.",
> -int, (struct cgraph_node *), NULL)
> +in vectorized loops in current function with @var{vector_mode}, or\n\
> +non-negative number if it is usable. In that case, the smaller the number\n\
> +is, the more desirable it is to use it.",
> +int, (struct cgraph_node *, machine_mode), NULL)
>
> HOOK_VECTOR_END (simd_clone)
>
> diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> index 4a824d16955..2d0da6f0a0e 100644
> --- a/gcc/tree-vect-stmts.cc
> +++ b/gcc/tree-vect-stmts.cc
> @@ -4155,7 +4155,14 @@ vectorizable_simd_clone_call (vec_info *vinfo,
> stmt_vec_info stmt_info,
> this_badness += floor_log2 (num_calls) * 4096;
> if (n->simdclone->inbranch)
> this_badness += 8192;
> - int target_badness = targetm.simd_clone.usable (n);
> +
> + /* If STMT_VINFO_VECTYPE has not been set yet pass the general vector
> + mode, which for targets that use it will determine what ISA we can
> + vectorize this code with. */
> + machine_mode vector_mode = vinfo->vector_mode;
> + if (vectype)
> + vector_mode = TYPE_MODE (vectype);
> + int target_badness = targetm.simd_clone.usable (n, vector_mode);
> if (target_badness < 0)
> continue;
> this_badness += target_badness * 512;
>
--
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)