public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-11478] Make option mvzeroupper independent of optimization level.
@ 2023-06-28  3:37 hongtao Liu
  0 siblings, 0 replies; only message in thread
From: hongtao Liu @ 2023-06-28  3:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8cf948e6d9ab19d54ec0d27357d0c2907a244474

commit r10-11478-g8cf948e6d9ab19d54ec0d27357d0c2907a244474
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Jun 26 09:50:25 2023 +0800

    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.

Diff:
---
 gcc/config/i386/i386-features.c                   |  8 ++------
 gcc/config/i386/i386-options.c                    |  4 +++-
 gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c | 14 ++++++++++++++
 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 } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-28  3:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28  3:37 [gcc r10-11478] Make option mvzeroupper independent of optimization level hongtao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).