summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuhongt <hongtao.liu@intel.com>2023-06-26 09:50:25 +0800
committerliuhongt <hongtao.liu@intel.com>2023-06-28 10:44:14 +0800
commit8cf948e6d9ab19d54ec0d27357d0c2907a244474 (patch)
treee07461fdac1d24fd34c0862c6ef1edf6391beb56
parente1f02cecd0bf90190ddd769b46cd01b8f2bbd3d3 (diff)
Make option mvzeroupper independent of optimization level.
pass_insert_vzeroupper is under condition TARGET_AVX && TARGET_VZEROUPPER && flag_expensive_optimizations && !optimize_size But the document of mvzeroupper doesn't mention the insertion required -O2 and above, it may confuse users when they explicitly use -Os -mvzeroupper. ------------ mvzeroupper Target Mask(VZEROUPPER) Save Generate vzeroupper instruction before a transfer of control flow out of the function. ------------ The patch moves flag_expensive_optimizations && !optimize_size to ix86_option_override_internal. It makes -mvzeroupper independent of optimization level, but still keeps the behavior of architecture tuning(emit_vzeroupper) unchanged. gcc/ChangeLog: * config/i386/i386-features.c (pass_insert_vzeroupper:gate): Move flag_expensive_optimizations && !optimize_size to .. * config/i386/i386-options.c (ix86_option_override_internal): .. this, it makes -mvzeroupper independent of optimization level, but still keeps the behavior of architecture tuning(emit_vzeroupper) unchanged. (rest_of_handle_insert_vzeroupper): Remove flag_expensive_optimizations && !optimize_size. gcc/testsuite/ChangeLog: * gcc.target/i386/avx-vzeroupper-29.c: New testcase.
-rw-r--r--gcc/config/i386/i386-features.c8
-rw-r--r--gcc/config/i386/i386-options.c4
-rw-r--r--gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c14
3 files changed, 19 insertions, 7 deletions
diff --git a/gcc/config/i386/i386-features.c b/gcc/config/i386/i386-features.c
index 329f4c36a9a..a5e0c21ec1a 100644
--- a/gcc/config/i386/i386-features.c
+++ b/gcc/config/i386/i386-features.c
@@ -1825,9 +1825,7 @@ ix86_add_reg_usage_to_vzerouppers (void)
static unsigned int
rest_of_handle_insert_vzeroupper (void)
{
- if (TARGET_VZEROUPPER
- && flag_expensive_optimizations
- && !optimize_size)
+ if (TARGET_VZEROUPPER)
{
/* vzeroupper instructions are inserted immediately after reload to
account for possible spills from 256bit or 512bit registers. The pass
@@ -1871,9 +1869,7 @@ public:
virtual bool gate (function *)
{
return TARGET_AVX
- && ((TARGET_VZEROUPPER
- && flag_expensive_optimizations
- && !optimize_size)
+ && (TARGET_VZEROUPPER
|| cfun->machine->has_explicit_vzeroupper);
}
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 7bb644b67b4..3510ad5f5d7 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -2715,7 +2715,9 @@ ix86_option_override_internal (bool main_args_p,
sorry ("%<-mcall-ms2sysv-xlogues%> isn%'t currently supported with SEH");
if (!(opts_set->x_target_flags & MASK_VZEROUPPER)
- && TARGET_EMIT_VZEROUPPER)
+ && TARGET_EMIT_VZEROUPPER
+ && flag_expensive_optimizations
+ && !optimize_size)
opts->x_target_flags |= MASK_VZEROUPPER;
if (!(opts_set->x_target_flags & MASK_STV))
opts->x_target_flags |= MASK_STV;
diff --git a/gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c
new file mode 100644
index 00000000000..4af637757f7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O0 -mavx -mtune=generic -mvzeroupper -dp" } */
+
+#include <immintrin.h>
+
+extern __m256 x, y;
+
+void
+foo ()
+{
+ x = y;
+}
+
+/* { dg-final { scan-assembler-times "avx_vzeroupper" 1 } } */