]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: Pass stmt_vec_info to TARGET_SIMD_CLONE_USABLE [PR96342]
authorAndre Vieira <andre.simoesdiasvieira@arm.com>
Wed, 11 Dec 2024 11:50:22 +0000 (11:50 +0000)
committerTamar Christina <tamar.christina@arm.com>
Wed, 11 Dec 2024 11:58:02 +0000 (11:58 +0000)
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:

PR target/96342
* 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.
* 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.
* doc/tm.texi: Regenerate

Co-authored-by: Victor Do Nascimento <victor.donascimento@arm.com>
Co-authored-by: Tamar Christina <tamar.christina@arm.com>
gcc/config/aarch64/aarch64.cc
gcc/config/gcn/gcn.cc
gcc/config/i386/i386.cc
gcc/doc/tm.texi
gcc/target.def
gcc/tree-vect-stmts.cc

index 4d1b3cca0c42e053764933391be7b0e21f79999e..77a2a6bfa3a3a6cd678ceb820d310f44cacfe581 100644 (file)
@@ -29490,12 +29490,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:
index d017f22d1bc40908bd66d9d1b927e36ac5be7ff8..634171a0a93b9aa10f5bc06569e077ba45ef16f0 100644 (file)
@@ -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
index 62f758b32ef5eaf2a40e5bd1e0288b9b8727b512..ca763e1eb334d47e3ddfceb3b3fda8e5cfa40b8d 100644 (file)
@@ -25721,7 +25721,7 @@ 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)
     {
index 7e8e02e3f423752a5333d888c780df2aef84b666..d7170f452068c1d012390b0a3d6c27053c0dd625 100644 (file)
@@ -6531,11 +6531,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)
index 5ee33bf0cf91b6e93ba2580496f2e7ced510ea64..8cf29c57eaee1f41a00afc6ae2e84ac9f8cc4aba 100644 (file)
@@ -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)
 
index 4759c274f3ccbb111a907576539b2a8efb7726a3..497a31322accba8672b82dee00f5403b40dca22b 100644 (file)
@@ -4297,7 +4297,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;