Re: [PATCH] vect: Pass mode to gather/scatter tests

2021-11-12 Thread Richard Biener via Gcc-patches
On November 12, 2021 6:53:04 PM GMT+01:00, Richard Sandiford via Gcc-patches 
 wrote:
>vect_check_gather_scatter had a binary “does this target support
>internal gather/scatter functions” test.  This dates from the time when
>we only handled gathers and scatters via direct target support, with
>x86_64 using built-in functions and aarch64 using IFNs.  But now that we
>can emulate gathers, we need to check whether the gather for a particular
>mode is going to be emulated or not.
>
>Without this, enabling SVE regresses emulated Advanced SIMD gather
>sequences in cases where SVE isn't used.
>
>Livermore kernel 15 can now be vectorised with Advanced SIMD when
>SVE is enabled.
>
>Regstrapped on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Ok. 

Richard. 

>Richard
>
>
>gcc/
>   * genopinit.c (main): Turn supports_vec_gather_load and
>   supports_vec_scatter_store into signed char arrays and remove
>   supports_vec_gather_load_cached and supports_vec_scatter_store_cached.
>   * optabs-query.c (supports_vec_convert_optab_p): Add a mode parameter.
>   If the mode is not VOIDmode, test only for that mode.
>   (supports_vec_gather_load_p): Likewise.
>   (supports_vec_scatter_store_p): Likewise.
>   * optabs-query.h (supports_vec_gather_load_p): Likewise.
>   (supports_vec_scatter_store_p): Likewise.
>   * tree-vect-data-refs.c (vect_check_gather_scatter): Pass the
>   vector mode to supports_vec_gather_load_p and
>   supports_vec_scatter_store_p.
>
>gcc/testsuite/
>   * gfortran.dg/vect/vect-8.f90: Bump number of vectorized loops
>   to 25 for SVE.
>   * gcc.target/aarch64/sve/gather_load_10.c: New test.
>---
> gcc/genopinit.c   | 11 ++--
> gcc/optabs-query.c| 55 +--
> gcc/optabs-query.h|  4 +-
> .../gcc.target/aarch64/sve/gather_load_10.c   | 18 ++
> gcc/testsuite/gfortran.dg/vect/vect-8.f90 |  3 +-
> gcc/tree-vect-data-refs.c |  4 +-
> 6 files changed, 56 insertions(+), 39 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/gather_load_10.c
>
>diff --git a/gcc/genopinit.c b/gcc/genopinit.c
>index 195ddf74fa2..c6be748079d 100644
>--- a/gcc/genopinit.c
>+++ b/gcc/genopinit.c
>@@ -313,12 +313,11 @@ main (int argc, const char **argv)
>  "  /* Patterns that are used by optabs that are enabled for this 
> target.  */\n"
>  "  bool pat_enable[NUM_OPTAB_PATTERNS];\n"
>  "\n"
>- "  /* Cache if the target supports vec_gather_load for at least one 
>vector\n"
>- " mode.  */\n"
>- "  bool supports_vec_gather_load;\n"
>- "  bool supports_vec_gather_load_cached;\n"
>- "  bool supports_vec_scatter_store;\n"
>- "  bool supports_vec_scatter_store_cached;\n"
>+ "  /* Index VOIDmode caches if the target supports vec_gather_load 
>for any\n"
>+ " vector mode.  Every other index X caches specifically for mode 
>X.\n"
>+ " 1 means yes, -1 means no.  */\n"
>+ "  signed char supports_vec_gather_load[NUM_MACHINE_MODES];\n"
>+ "  signed char supports_vec_scatter_store[NUM_MACHINE_MODES];\n"
>  "};\n"
>  "extern void init_all_optabs (struct target_optabs *);\n"
>  "\n"
>diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c
>index a6dd0fed610..1c0778cba55 100644
>--- a/gcc/optabs-query.c
>+++ b/gcc/optabs-query.c
>@@ -712,13 +712,16 @@ lshift_cheap_p (bool speed_p)
>   return cheap[speed_p];
> }
> 
>-/* Return true if vector conversion optab OP supports at least one mode,
>-   given that the second mode is always an integer vector.  */
>+/* If MODE is not VOIDmode, return true if vector conversion optab OP supports
>+   that mode, given that the second mode is always an integer vector.
>+   If MODE is VOIDmode, return true if OP supports any vector mode.  */
> 
> static bool
>-supports_vec_convert_optab_p (optab op)
>+supports_vec_convert_optab_p (optab op, machine_mode mode)
> {
>-  for (int i = 0; i < NUM_MACHINE_MODES; ++i)
>+  int start = mode == VOIDmode ? 0 : mode;
>+  int end = mode == VOIDmode ? MAX_MACHINE_MODE : mode;
>+  for (int i = start; i <= end; ++i)
> if (VECTOR_MODE_P ((machine_mode) i))
>   for (int j = MIN_MODE_VECTOR_INT; j < MAX_MODE_VECTOR_INT; ++j)
>   if (convert_optab_handler (op, (machine_mode) i,
>@@ -728,39 +731,35 @@ supports_vec_convert_optab_p (optab op)
>   return false;
> }
> 
>-/* Return true if vec_gather_load is available for at least one vector
>-   mode.  */
>+/* If MODE is not VOIDmode, return true if vec_gather_load is available for
>+   that mode.  If MODE is VOIDmode, return true if gather_load is available
>+   for at least one vector mode.  */
> 
> bool
>-supports_vec_gather_load_p ()
>+supports_vec_gather_load_p (machine_mode mode)
> {
>-  if (this_fn_optabs->supports_vec_gather_load_cached)
>-return this_fn_optabs->suppor

[PATCH] vect: Pass mode to gather/scatter tests

2021-11-12 Thread Richard Sandiford via Gcc-patches
vect_check_gather_scatter had a binary “does this target support
internal gather/scatter functions” test.  This dates from the time when
we only handled gathers and scatters via direct target support, with
x86_64 using built-in functions and aarch64 using IFNs.  But now that we
can emulate gathers, we need to check whether the gather for a particular
mode is going to be emulated or not.

Without this, enabling SVE regresses emulated Advanced SIMD gather
sequences in cases where SVE isn't used.

Livermore kernel 15 can now be vectorised with Advanced SIMD when
SVE is enabled.

Regstrapped on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


gcc/
* genopinit.c (main): Turn supports_vec_gather_load and
supports_vec_scatter_store into signed char arrays and remove
supports_vec_gather_load_cached and supports_vec_scatter_store_cached.
* optabs-query.c (supports_vec_convert_optab_p): Add a mode parameter.
If the mode is not VOIDmode, test only for that mode.
(supports_vec_gather_load_p): Likewise.
(supports_vec_scatter_store_p): Likewise.
* optabs-query.h (supports_vec_gather_load_p): Likewise.
(supports_vec_scatter_store_p): Likewise.
* tree-vect-data-refs.c (vect_check_gather_scatter): Pass the
vector mode to supports_vec_gather_load_p and
supports_vec_scatter_store_p.

gcc/testsuite/
* gfortran.dg/vect/vect-8.f90: Bump number of vectorized loops
to 25 for SVE.
* gcc.target/aarch64/sve/gather_load_10.c: New test.
---
 gcc/genopinit.c   | 11 ++--
 gcc/optabs-query.c| 55 +--
 gcc/optabs-query.h|  4 +-
 .../gcc.target/aarch64/sve/gather_load_10.c   | 18 ++
 gcc/testsuite/gfortran.dg/vect/vect-8.f90 |  3 +-
 gcc/tree-vect-data-refs.c |  4 +-
 6 files changed, 56 insertions(+), 39 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/gather_load_10.c

diff --git a/gcc/genopinit.c b/gcc/genopinit.c
index 195ddf74fa2..c6be748079d 100644
--- a/gcc/genopinit.c
+++ b/gcc/genopinit.c
@@ -313,12 +313,11 @@ main (int argc, const char **argv)
   "  /* Patterns that are used by optabs that are enabled for this 
target.  */\n"
   "  bool pat_enable[NUM_OPTAB_PATTERNS];\n"
   "\n"
-  "  /* Cache if the target supports vec_gather_load for at least one 
vector\n"
-  " mode.  */\n"
-  "  bool supports_vec_gather_load;\n"
-  "  bool supports_vec_gather_load_cached;\n"
-  "  bool supports_vec_scatter_store;\n"
-  "  bool supports_vec_scatter_store_cached;\n"
+  "  /* Index VOIDmode caches if the target supports vec_gather_load 
for any\n"
+  " vector mode.  Every other index X caches specifically for mode 
X.\n"
+  " 1 means yes, -1 means no.  */\n"
+  "  signed char supports_vec_gather_load[NUM_MACHINE_MODES];\n"
+  "  signed char supports_vec_scatter_store[NUM_MACHINE_MODES];\n"
   "};\n"
   "extern void init_all_optabs (struct target_optabs *);\n"
   "\n"
diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c
index a6dd0fed610..1c0778cba55 100644
--- a/gcc/optabs-query.c
+++ b/gcc/optabs-query.c
@@ -712,13 +712,16 @@ lshift_cheap_p (bool speed_p)
   return cheap[speed_p];
 }
 
-/* Return true if vector conversion optab OP supports at least one mode,
-   given that the second mode is always an integer vector.  */
+/* If MODE is not VOIDmode, return true if vector conversion optab OP supports
+   that mode, given that the second mode is always an integer vector.
+   If MODE is VOIDmode, return true if OP supports any vector mode.  */
 
 static bool
-supports_vec_convert_optab_p (optab op)
+supports_vec_convert_optab_p (optab op, machine_mode mode)
 {
-  for (int i = 0; i < NUM_MACHINE_MODES; ++i)
+  int start = mode == VOIDmode ? 0 : mode;
+  int end = mode == VOIDmode ? MAX_MACHINE_MODE : mode;
+  for (int i = start; i <= end; ++i)
 if (VECTOR_MODE_P ((machine_mode) i))
   for (int j = MIN_MODE_VECTOR_INT; j < MAX_MODE_VECTOR_INT; ++j)
if (convert_optab_handler (op, (machine_mode) i,
@@ -728,39 +731,35 @@ supports_vec_convert_optab_p (optab op)
   return false;
 }
 
-/* Return true if vec_gather_load is available for at least one vector
-   mode.  */
+/* If MODE is not VOIDmode, return true if vec_gather_load is available for
+   that mode.  If MODE is VOIDmode, return true if gather_load is available
+   for at least one vector mode.  */
 
 bool
-supports_vec_gather_load_p ()
+supports_vec_gather_load_p (machine_mode mode)
 {
-  if (this_fn_optabs->supports_vec_gather_load_cached)
-return this_fn_optabs->supports_vec_gather_load;
+  if (!this_fn_optabs->supports_vec_gather_load[mode])
+this_fn_optabs->supports_vec_gather_load[mode]
+  = (supports_vec_convert_optab_p (gather_load_opt