aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/i386
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2021-11-15 18:52:56 -0800
committerH.J. Lu <hjl.tools@gmail.com>2021-12-03 09:57:06 -0800
commit654cd743c88a28fb292f7c2cf5f4b10e4047e7d9 (patch)
tree722cd27e76fe5cf1dde2a4870a5a1fae1cfff565 /gcc/config/i386
parent987baa7444a96ac769ba520cfa4f5a64ee647103 (diff)
downloadgcc-654cd743c88a28fb292f7c2cf5f4b10e4047e7d9.zip
gcc-654cd743c88a28fb292f7c2cf5f4b10e4047e7d9.tar.gz
gcc-654cd743c88a28fb292f7c2cf5f4b10e4047e7d9.tar.bz2
x86: Add -mmove-max=bits and -mstore-max=bits
Add -mmove-max=bits and -mstore-max=bits to enable 256-bit/512-bit move and store, independent of -mprefer-vector-width=bits: 1. Add X86_TUNE_AVX512_MOVE_BY_PIECES and X86_TUNE_AVX512_STORE_BY_PIECES which are enabled for Intel Sapphire Rapids processor. 2. Add -mmove-max=bits to set the maximum number of bits can be moved from memory to memory efficiently. The default value is derived from X86_TUNE_AVX512_MOVE_BY_PIECES, X86_TUNE_AVX256_MOVE_BY_PIECES, and the preferred vector width. 3. Add -mstore-max=bits to set the maximum number of bits can be stored to memory efficiently. The default value is derived from X86_TUNE_AVX512_STORE_BY_PIECES, X86_TUNE_AVX256_STORE_BY_PIECES and the preferred vector width. gcc/ PR target/103269 * config/i386/i386-expand.c (ix86_expand_builtin): Pass PVW_NONE and PVW_NONE to ix86_target_string. * config/i386/i386-options.c (ix86_target_string): Add arguments for move_max and store_max. (ix86_target_string::add_vector_width): New lambda. (ix86_debug_options): Pass ix86_move_max and ix86_store_max to ix86_target_string. (ix86_function_specific_print): Pass ptr->x_ix86_move_max and ptr->x_ix86_store_max to ix86_target_string. (ix86_valid_target_attribute_tree): Handle x_ix86_move_max and x_ix86_store_max. (ix86_option_override_internal): Set the default x_ix86_move_max and x_ix86_store_max. * config/i386/i386-options.h (ix86_target_string): Add prefer_vector_width and prefer_vector_width. * config/i386/i386.h (TARGET_AVX256_MOVE_BY_PIECES): Removed. (TARGET_AVX256_STORE_BY_PIECES): Likewise. (MOVE_MAX): Use 64 if ix86_move_max or ix86_store_max == PVW_AVX512. Use 32 if ix86_move_max or ix86_store_max >= PVW_AVX256. (STORE_MAX_PIECES): Use 64 if ix86_store_max == PVW_AVX512. Use 32 if ix86_store_max >= PVW_AVX256. * config/i386/i386.opt: Add -mmove-max=bits and -mstore-max=bits. * config/i386/x86-tune.def (X86_TUNE_AVX512_MOVE_BY_PIECES): New. (X86_TUNE_AVX512_STORE_BY_PIECES): Likewise. * doc/invoke.texi: Document -mmove-max=bits and -mstore-max=bits. gcc/testsuite/ PR target/103269 * gcc.target/i386/pieces-memcpy-17.c: New test. * gcc.target/i386/pieces-memcpy-18.c: Likewise. * gcc.target/i386/pieces-memcpy-19.c: Likewise. * gcc.target/i386/pieces-memcpy-20.c: Likewise. * gcc.target/i386/pieces-memcpy-21.c: Likewise. * gcc.target/i386/pieces-memset-45.c: Likewise. * gcc.target/i386/pieces-memset-46.c: Likewise. * gcc.target/i386/pieces-memset-47.c: Likewise. * gcc.target/i386/pieces-memset-48.c: Likewise. * gcc.target/i386/pieces-memset-49.c: Likewise.
Diffstat (limited to 'gcc/config/i386')
-rw-r--r--gcc/config/i386/i386-expand.c1
-rw-r--r--gcc/config/i386/i386-options.c75
-rw-r--r--gcc/config/i386/i386-options.h6
-rw-r--r--gcc/config/i386/i386.h18
-rw-r--r--gcc/config/i386/i386.opt8
-rw-r--r--gcc/config/i386/x86-tune.def10
6 files changed, 100 insertions, 18 deletions
diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 068c5c2..2bbb28e 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -12305,6 +12305,7 @@ ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
char *opts = ix86_target_string (bisa, bisa2, 0, 0, NULL, NULL,
(enum fpmath_unit) 0,
(enum prefer_vector_width) 0,
+ PVW_NONE, PVW_NONE,
false, add_abi_p);
if (!opts)
error ("%qE needs unknown isa option", fndecl);
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index f971e03..53bd55a 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -364,6 +364,8 @@ ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
const char *arch, const char *tune,
enum fpmath_unit fpmath,
enum prefer_vector_width pvw,
+ enum prefer_vector_width move_max,
+ enum prefer_vector_width store_max,
bool add_nl_p, bool add_abi_p)
{
/* Flag options. */
@@ -542,10 +544,10 @@ ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
}
}
- /* Add -mprefer-vector-width= option. */
- if (pvw)
+ auto add_vector_width = [&opts, &num] (prefer_vector_width pvw,
+ const char *cmd)
{
- opts[num][0] = "-mprefer-vector-width=";
+ opts[num][0] = cmd;
switch ((int) pvw)
{
case PVW_AVX128:
@@ -563,7 +565,19 @@ ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
default:
gcc_unreachable ();
}
- }
+ };
+
+ /* Add -mprefer-vector-width= option. */
+ if (pvw)
+ add_vector_width (pvw, "-mprefer-vector-width=");
+
+ /* Add -mmove-max= option. */
+ if (move_max)
+ add_vector_width (move_max, "-mmove-max=");
+
+ /* Add -mstore-max= option. */
+ if (store_max)
+ add_vector_width (store_max, "-mstore-max=");
/* Any options? */
if (num == 0)
@@ -630,6 +644,7 @@ ix86_debug_options (void)
target_flags, ix86_target_flags,
ix86_arch_string, ix86_tune_string,
ix86_fpmath, prefer_vector_width_type,
+ ix86_move_max, ix86_store_max,
true, true);
if (opts)
@@ -892,7 +907,9 @@ ix86_function_specific_print (FILE *file, int indent,
= ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_ix86_isa_flags2,
ptr->x_target_flags, ptr->x_ix86_target_flags,
NULL, NULL, ptr->x_ix86_fpmath,
- ptr->x_prefer_vector_width_type, false, true);
+ ptr->x_prefer_vector_width_type,
+ ptr->x_ix86_move_max, ptr->x_ix86_store_max,
+ false, true);
gcc_assert (ptr->arch < PROCESSOR_max);
fprintf (file, "%*sarch = %d (%s)\n",
@@ -1318,6 +1335,10 @@ ix86_valid_target_attribute_tree (tree fndecl, tree args,
const char *orig_tune_string = opts->x_ix86_tune_string;
enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath;
enum prefer_vector_width orig_pvw_set = opts_set->x_prefer_vector_width_type;
+ enum prefer_vector_width orig_ix86_move_max_set
+ = opts_set->x_ix86_move_max;
+ enum prefer_vector_width orig_ix86_store_max_set
+ = opts_set->x_ix86_store_max;
int orig_tune_defaulted = ix86_tune_defaulted;
int orig_arch_specified = ix86_arch_specified;
char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL };
@@ -1393,6 +1414,8 @@ ix86_valid_target_attribute_tree (tree fndecl, tree args,
opts->x_ix86_tune_string = orig_tune_string;
opts_set->x_ix86_fpmath = orig_fpmath_set;
opts_set->x_prefer_vector_width_type = orig_pvw_set;
+ opts_set->x_ix86_move_max = orig_ix86_move_max_set;
+ opts_set->x_ix86_store_max = orig_ix86_store_max_set;
opts->x_ix86_excess_precision = orig_ix86_excess_precision;
opts->x_ix86_unsafe_math_optimizations
= orig_ix86_unsafe_math_optimizations;
@@ -2691,6 +2714,48 @@ ix86_option_override_internal (bool main_args_p,
&& (opts_set->x_prefer_vector_width_type == PVW_NONE))
opts->x_prefer_vector_width_type = PVW_AVX256;
+ if (opts_set->x_ix86_move_max == PVW_NONE)
+ {
+ /* Set the maximum number of bits can be moved from memory to
+ memory efficiently. */
+ if (ix86_tune_features[X86_TUNE_AVX512_MOVE_BY_PIECES])
+ opts->x_ix86_move_max = PVW_AVX512;
+ else if (ix86_tune_features[X86_TUNE_AVX256_MOVE_BY_PIECES])
+ opts->x_ix86_move_max = PVW_AVX256;
+ else
+ {
+ opts->x_ix86_move_max = opts->x_prefer_vector_width_type;
+ if (opts_set->x_ix86_move_max == PVW_NONE)
+ {
+ if (TARGET_AVX512F_P (opts->x_ix86_isa_flags))
+ opts->x_ix86_move_max = PVW_AVX512;
+ else
+ opts->x_ix86_move_max = PVW_AVX128;
+ }
+ }
+ }
+
+ if (opts_set->x_ix86_store_max == PVW_NONE)
+ {
+ /* Set the maximum number of bits can be stored to memory
+ efficiently. */
+ if (ix86_tune_features[X86_TUNE_AVX512_STORE_BY_PIECES])
+ opts->x_ix86_store_max = PVW_AVX512;
+ else if (ix86_tune_features[X86_TUNE_AVX256_STORE_BY_PIECES])
+ opts->x_ix86_store_max = PVW_AVX256;
+ else
+ {
+ opts->x_ix86_store_max = opts->x_prefer_vector_width_type;
+ if (opts_set->x_ix86_store_max == PVW_NONE)
+ {
+ if (TARGET_AVX512F_P (opts->x_ix86_isa_flags))
+ opts->x_ix86_store_max = PVW_AVX512;
+ else
+ opts->x_ix86_store_max = PVW_AVX128;
+ }
+ }
+ }
+
if (opts->x_ix86_recip_name)
{
char *p = ASTRDUP (opts->x_ix86_recip_name);
diff --git a/gcc/config/i386/i386-options.h b/gcc/config/i386/i386-options.h
index cdaca26..e218e24 100644
--- a/gcc/config/i386/i386-options.h
+++ b/gcc/config/i386/i386-options.h
@@ -26,8 +26,10 @@ char *ix86_target_string (HOST_WIDE_INT isa, HOST_WIDE_INT isa2,
int flags, int flags2,
const char *arch, const char *tune,
enum fpmath_unit fpmath,
- enum prefer_vector_width pvw, bool add_nl_p,
- bool add_abi_p);
+ enum prefer_vector_width pvw,
+ enum prefer_vector_width move_max,
+ enum prefer_vector_width store_max,
+ bool add_nl_p, bool add_abi_p);
extern enum attr_cpu ix86_schedule;
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 2fda1e0..4f70085 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -408,10 +408,6 @@ extern unsigned char ix86_tune_features[X86_TUNE_LAST];
ix86_tune_features[X86_TUNE_AVOID_LEA_FOR_ADDR]
#define TARGET_SOFTWARE_PREFETCHING_BENEFICIAL \
ix86_tune_features[X86_TUNE_SOFTWARE_PREFETCHING_BENEFICIAL]
-#define TARGET_AVX256_MOVE_BY_PIECES \
- ix86_tune_features[X86_TUNE_AVX256_MOVE_BY_PIECES]
-#define TARGET_AVX256_STORE_BY_PIECES \
- ix86_tune_features[X86_TUNE_AVX256_STORE_BY_PIECES]
#define TARGET_AVX256_SPLIT_REGS \
ix86_tune_features[X86_TUNE_AVX256_SPLIT_REGS]
#define TARGET_GENERAL_REGS_SSE_SPILL \
@@ -1807,12 +1803,13 @@ typedef struct ix86_args {
MOVE_MAX_PIECES defaults to MOVE_MAX. */
#define MOVE_MAX \
- ((TARGET_AVX512F && !TARGET_PREFER_AVX256) \
+ ((TARGET_AVX512F \
+ && (ix86_move_max == PVW_AVX512 \
+ || ix86_store_max == PVW_AVX512)) \
? 64 \
: ((TARGET_AVX \
- && !TARGET_PREFER_AVX128 \
- && (TARGET_AVX256_MOVE_BY_PIECES \
- || TARGET_AVX256_STORE_BY_PIECES)) \
+ && (ix86_move_max >= PVW_AVX256 \
+ || ix86_store_max >= PVW_AVX256)) \
? 32 \
: ((TARGET_SSE2 \
&& TARGET_SSE_UNALIGNED_LOAD_OPTIMAL \
@@ -1825,11 +1822,10 @@ typedef struct ix86_args {
store_by_pieces of 16/32/64 bytes. */
#define STORE_MAX_PIECES \
(TARGET_INTER_UNIT_MOVES_TO_VEC \
- ? ((TARGET_AVX512F && !TARGET_PREFER_AVX256) \
+ ? ((TARGET_AVX512F && ix86_store_max == PVW_AVX512) \
? 64 \
: ((TARGET_AVX \
- && !TARGET_PREFER_AVX128 \
- && TARGET_AVX256_STORE_BY_PIECES) \
+ && ix86_store_max >= PVW_AVX256) \
? 32 \
: ((TARGET_SSE2 \
&& TARGET_SSE_UNALIGNED_STORE_OPTIMAL) \
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 3e67c53..e1af3e4 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -624,6 +624,14 @@ Enum(prefer_vector_width) String(256) Value(PVW_AVX256)
EnumValue
Enum(prefer_vector_width) String(512) Value(PVW_AVX512)
+mmove-max=
+Target RejectNegative Joined Var(ix86_move_max) Enum(prefer_vector_width) Init(PVW_NONE) Save
+Maximum number of bits that can be moved from memory to memory efficiently.
+
+mstore-max=
+Target RejectNegative Joined Var(ix86_store_max) Enum(prefer_vector_width) Init(PVW_NONE) Save
+Maximum number of bits that can be stored to memory efficiently.
+
;; ISA support
m32
diff --git a/gcc/config/i386/x86-tune.def b/gcc/config/i386/x86-tune.def
index dab4b3d..20cb662 100644
--- a/gcc/config/i386/x86-tune.def
+++ b/gcc/config/i386/x86-tune.def
@@ -512,6 +512,16 @@ DEF_TUNE (X86_TUNE_AVX256_MOVE_BY_PIECES, "avx256_move_by_pieces",
DEF_TUNE (X86_TUNE_AVX256_STORE_BY_PIECES, "avx256_store_by_pieces",
m_CORE_AVX512)
+/* X86_TUNE_AVX512_MOVE_BY_PIECES: Optimize move_by_pieces with 512-bit
+ AVX instructions. */
+DEF_TUNE (X86_TUNE_AVX512_MOVE_BY_PIECES, "avx512_move_by_pieces",
+ m_SAPPHIRERAPIDS)
+
+/* X86_TUNE_AVX512_STORE_BY_PIECES: Optimize store_by_pieces with 512-bit
+ AVX instructions. */
+DEF_TUNE (X86_TUNE_AVX512_STORE_BY_PIECES, "avx512_store_by_pieces",
+ m_SAPPHIRERAPIDS)
+
/*****************************************************************************/
/*****************************************************************************/
/* Historical relics: tuning flags that helps a specific old CPU designs */