* [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn.
@ 2023-06-27 5:53 liuhongt
2023-06-27 5:53 ` [PATCH 2/2] Make option mvzeroupper independent of optimization level liuhongt
2023-06-27 6:04 ` [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn Uros Bizjak
0 siblings, 2 replies; 8+ messages in thread
From: liuhongt @ 2023-06-27 5:53 UTC (permalink / raw)
To: gcc-patches; +Cc: ubizjak, crazylht, hjl.tools
Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk?
gcc/ChangeLog:
PR target/82735
* config/i386/i386.cc (ix86_avx_u127_mode_needed): Don't emit
vzeroupper for vzeroupper call_insn.
gcc/testsuite/ChangeLog:
* gcc.target/i386/avx-vzeroupper-30.c: New test.
---
gcc/config/i386/i386.cc | 5 +++--
gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c | 15 +++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 0761965344b..caca74d6dec 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -14489,8 +14489,9 @@ ix86_avx_u128_mode_needed (rtx_insn *insn)
modes wider than 256 bits. It's only safe to issue a
vzeroupper if all SSE registers are clobbered. */
const function_abi &abi = insn_callee_abi (insn);
- if (!hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
- abi.mode_clobbers (V4DImode)))
+ if (vzeroupper_pattern (PATTERN (insn), VOIDmode)
+ || !hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
+ abi.mode_clobbers (V4DImode)))
return AVX_U128_ANY;
return AVX_U128_CLEAN;
diff --git a/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
new file mode 100644
index 00000000000..c1c9baa8fc4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx -mvzeroupper -dp" } */
+
+#include <immintrin.h>
+
+extern __m256 x, y;
+
+void
+foo ()
+{
+ x = y;
+ _mm256_zeroupper ();
+}
+
+/* { dg-final { scan-assembler-times "avx_vzeroupper" 1 } } */
--
2.39.1.388.g2fc9e9ca3c
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] Make option mvzeroupper independent of optimization level.
2023-06-27 5:53 [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn liuhongt
@ 2023-06-27 5:53 ` liuhongt
2023-06-27 6:05 ` Uros Bizjak
2023-06-27 6:04 ` [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn Uros Bizjak
1 sibling, 1 reply; 8+ messages in thread
From: liuhongt @ 2023-06-27 5:53 UTC (permalink / raw)
To: gcc-patches; +Cc: ubizjak, crazylht, hjl.tools
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.
Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
Ok for trunk?
gcc/ChangeLog:
* config/i386/i386-features.cc (pass_insert_vzeroupper:gate):
Move flag_expensive_optimizations && !optimize_size to ..
* config/i386/i386-options.cc (ix86_option_override_internal):
.. this, it makes -mvzeroupper independent of optimization
level, but still keeps the behavior of architecture
tuning(emit_vzeroupper) unchanged.
gcc/testsuite/ChangeLog:
* gcc.target/i386/avx-vzeroupper-29.c: New testcase.
---
gcc/config/i386/i386-features.cc | 3 +--
gcc/config/i386/i386-options.cc | 4 +++-
gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c | 14 ++++++++++++++
3 files changed, 18 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c
diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index 4a3b07ae045..92ae08d442e 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -2489,8 +2489,7 @@ public:
/* opt_pass methods: */
bool gate (function *) final override
{
- return TARGET_AVX && TARGET_VZEROUPPER
- && flag_expensive_optimizations && !optimize_size;
+ return TARGET_AVX && TARGET_VZEROUPPER;
}
unsigned int execute (function *) final override
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index 2cb0bddcd35..f76e7c5947b 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -2727,7 +2727,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 } } */
--
2.39.1.388.g2fc9e9ca3c
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn.
2023-06-27 5:53 [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn liuhongt
2023-06-27 5:53 ` [PATCH 2/2] Make option mvzeroupper independent of optimization level liuhongt
@ 2023-06-27 6:04 ` Uros Bizjak
2023-06-27 6:07 ` Hongtao Liu
1 sibling, 1 reply; 8+ messages in thread
From: Uros Bizjak @ 2023-06-27 6:04 UTC (permalink / raw)
To: liuhongt; +Cc: gcc-patches, crazylht, hjl.tools
On Tue, Jun 27, 2023 at 7:55 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?
>
> gcc/ChangeLog:
>
> PR target/82735
> * config/i386/i386.cc (ix86_avx_u127_mode_needed): Don't emit
> vzeroupper for vzeroupper call_insn.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/avx-vzeroupper-30.c: New test.
> ---
> gcc/config/i386/i386.cc | 5 +++--
> gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c | 15 +++++++++++++++
> 2 files changed, 18 insertions(+), 2 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 0761965344b..caca74d6dec 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -14489,8 +14489,9 @@ ix86_avx_u128_mode_needed (rtx_insn *insn)
> modes wider than 256 bits. It's only safe to issue a
> vzeroupper if all SSE registers are clobbered. */
> const function_abi &abi = insn_callee_abi (insn);
> - if (!hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
> - abi.mode_clobbers (V4DImode)))
> + if (vzeroupper_pattern (PATTERN (insn), VOIDmode)
> + || !hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
> + abi.mode_clobbers (V4DImode)))
> return AVX_U128_ANY;
You also want to check for vzeroall_pattern here.
OK with the above change.
Thanks,
Uros.
>
> return AVX_U128_CLEAN;
> diff --git a/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> new file mode 100644
> index 00000000000..c1c9baa8fc4
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> @@ -0,0 +1,15 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx -mvzeroupper -dp" } */
> +
> +#include <immintrin.h>
> +
> +extern __m256 x, y;
> +
> +void
> +foo ()
> +{
> + x = y;
> + _mm256_zeroupper ();
> +}
> +
> +/* { dg-final { scan-assembler-times "avx_vzeroupper" 1 } } */
> --
> 2.39.1.388.g2fc9e9ca3c
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Make option mvzeroupper independent of optimization level.
2023-06-27 5:53 ` [PATCH 2/2] Make option mvzeroupper independent of optimization level liuhongt
@ 2023-06-27 6:05 ` Uros Bizjak
2023-06-27 6:08 ` Hongtao Liu
0 siblings, 1 reply; 8+ messages in thread
From: Uros Bizjak @ 2023-06-27 6:05 UTC (permalink / raw)
To: liuhongt; +Cc: gcc-patches, crazylht, hjl.tools
On Tue, Jun 27, 2023 at 7:55 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> 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.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk?
>
> gcc/ChangeLog:
>
> * config/i386/i386-features.cc (pass_insert_vzeroupper:gate):
> Move flag_expensive_optimizations && !optimize_size to ..
> * config/i386/i386-options.cc (ix86_option_override_internal):
> .. this, it makes -mvzeroupper independent of optimization
> level, but still keeps the behavior of architecture
> tuning(emit_vzeroupper) unchanged.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/avx-vzeroupper-29.c: New testcase.
OK.
Thanks,
Uros.
> ---
> gcc/config/i386/i386-features.cc | 3 +--
> gcc/config/i386/i386-options.cc | 4 +++-
> gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c | 14 ++++++++++++++
> 3 files changed, 18 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c
>
> diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
> index 4a3b07ae045..92ae08d442e 100644
> --- a/gcc/config/i386/i386-features.cc
> +++ b/gcc/config/i386/i386-features.cc
> @@ -2489,8 +2489,7 @@ public:
> /* opt_pass methods: */
> bool gate (function *) final override
> {
> - return TARGET_AVX && TARGET_VZEROUPPER
> - && flag_expensive_optimizations && !optimize_size;
> + return TARGET_AVX && TARGET_VZEROUPPER;
> }
>
> unsigned int execute (function *) final override
> diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> index 2cb0bddcd35..f76e7c5947b 100644
> --- a/gcc/config/i386/i386-options.cc
> +++ b/gcc/config/i386/i386-options.cc
> @@ -2727,7 +2727,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 } } */
> --
> 2.39.1.388.g2fc9e9ca3c
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn.
2023-06-27 6:04 ` [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn Uros Bizjak
@ 2023-06-27 6:07 ` Hongtao Liu
2023-06-27 6:11 ` Uros Bizjak
0 siblings, 1 reply; 8+ messages in thread
From: Hongtao Liu @ 2023-06-27 6:07 UTC (permalink / raw)
To: Uros Bizjak; +Cc: liuhongt, gcc-patches, hjl.tools
On Tue, Jun 27, 2023 at 2:05 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Tue, Jun 27, 2023 at 7:55 AM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> > Ok for trunk?
> >
> > gcc/ChangeLog:
> >
> > PR target/82735
> > * config/i386/i386.cc (ix86_avx_u127_mode_needed): Don't emit
> > vzeroupper for vzeroupper call_insn.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.target/i386/avx-vzeroupper-30.c: New test.
> > ---
> > gcc/config/i386/i386.cc | 5 +++--
> > gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c | 15 +++++++++++++++
> > 2 files changed, 18 insertions(+), 2 deletions(-)
> > create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> >
> > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > index 0761965344b..caca74d6dec 100644
> > --- a/gcc/config/i386/i386.cc
> > +++ b/gcc/config/i386/i386.cc
> > @@ -14489,8 +14489,9 @@ ix86_avx_u128_mode_needed (rtx_insn *insn)
> > modes wider than 256 bits. It's only safe to issue a
> > vzeroupper if all SSE registers are clobbered. */
> > const function_abi &abi = insn_callee_abi (insn);
> > - if (!hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
> > - abi.mode_clobbers (V4DImode)))
> > + if (vzeroupper_pattern (PATTERN (insn), VOIDmode)
> > + || !hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
> > + abi.mode_clobbers (V4DImode)))
> > return AVX_U128_ANY;
>
> You also want to check for vzeroall_pattern here.
This is inside
if (CALL_P (insn))
vzeroupper is defined as special call_insn, but vzeroall is not.
>
> OK with the above change.
>
> Thanks,
> Uros.
>
> >
> > return AVX_U128_CLEAN;
> > diff --git a/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> > new file mode 100644
> > index 00000000000..c1c9baa8fc4
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> > @@ -0,0 +1,15 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mavx -mvzeroupper -dp" } */
> > +
> > +#include <immintrin.h>
> > +
> > +extern __m256 x, y;
> > +
> > +void
> > +foo ()
> > +{
> > + x = y;
> > + _mm256_zeroupper ();
> > +}
> > +
> > +/* { dg-final { scan-assembler-times "avx_vzeroupper" 1 } } */
> > --
> > 2.39.1.388.g2fc9e9ca3c
> >
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Make option mvzeroupper independent of optimization level.
2023-06-27 6:05 ` Uros Bizjak
@ 2023-06-27 6:08 ` Hongtao Liu
2023-06-27 6:11 ` Uros Bizjak
0 siblings, 1 reply; 8+ messages in thread
From: Hongtao Liu @ 2023-06-27 6:08 UTC (permalink / raw)
To: Uros Bizjak; +Cc: liuhongt, gcc-patches, hjl.tools
On Tue, Jun 27, 2023 at 2:05 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Tue, Jun 27, 2023 at 7:55 AM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > 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.
> >
> > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> > Ok for trunk?
> >
> > gcc/ChangeLog:
> >
> > * config/i386/i386-features.cc (pass_insert_vzeroupper:gate):
> > Move flag_expensive_optimizations && !optimize_size to ..
> > * config/i386/i386-options.cc (ix86_option_override_internal):
> > .. this, it makes -mvzeroupper independent of optimization
> > level, but still keeps the behavior of architecture
> > tuning(emit_vzeroupper) unchanged.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.target/i386/avx-vzeroupper-29.c: New testcase.
>
> OK.
I'd like to backport this patch to GCC10/GCC11/GCC12/GCC13.
>
> Thanks,
> Uros.
>
> > ---
> > gcc/config/i386/i386-features.cc | 3 +--
> > gcc/config/i386/i386-options.cc | 4 +++-
> > gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c | 14 ++++++++++++++
> > 3 files changed, 18 insertions(+), 3 deletions(-)
> > create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c
> >
> > diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
> > index 4a3b07ae045..92ae08d442e 100644
> > --- a/gcc/config/i386/i386-features.cc
> > +++ b/gcc/config/i386/i386-features.cc
> > @@ -2489,8 +2489,7 @@ public:
> > /* opt_pass methods: */
> > bool gate (function *) final override
> > {
> > - return TARGET_AVX && TARGET_VZEROUPPER
> > - && flag_expensive_optimizations && !optimize_size;
> > + return TARGET_AVX && TARGET_VZEROUPPER;
> > }
> >
> > unsigned int execute (function *) final override
> > diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> > index 2cb0bddcd35..f76e7c5947b 100644
> > --- a/gcc/config/i386/i386-options.cc
> > +++ b/gcc/config/i386/i386-options.cc
> > @@ -2727,7 +2727,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 } } */
> > --
> > 2.39.1.388.g2fc9e9ca3c
> >
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn.
2023-06-27 6:07 ` Hongtao Liu
@ 2023-06-27 6:11 ` Uros Bizjak
0 siblings, 0 replies; 8+ messages in thread
From: Uros Bizjak @ 2023-06-27 6:11 UTC (permalink / raw)
To: Hongtao Liu; +Cc: liuhongt, gcc-patches, hjl.tools
On Tue, Jun 27, 2023 at 8:08 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Tue, Jun 27, 2023 at 2:05 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Tue, Jun 27, 2023 at 7:55 AM liuhongt <hongtao.liu@intel.com> wrote:
> > >
> > > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> > > Ok for trunk?
> > >
> > > gcc/ChangeLog:
> > >
> > > PR target/82735
> > > * config/i386/i386.cc (ix86_avx_u127_mode_needed): Don't emit
> > > vzeroupper for vzeroupper call_insn.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * gcc.target/i386/avx-vzeroupper-30.c: New test.
> > > ---
> > > gcc/config/i386/i386.cc | 5 +++--
> > > gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c | 15 +++++++++++++++
> > > 2 files changed, 18 insertions(+), 2 deletions(-)
> > > create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> > >
> > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> > > index 0761965344b..caca74d6dec 100644
> > > --- a/gcc/config/i386/i386.cc
> > > +++ b/gcc/config/i386/i386.cc
> > > @@ -14489,8 +14489,9 @@ ix86_avx_u128_mode_needed (rtx_insn *insn)
> > > modes wider than 256 bits. It's only safe to issue a
> > > vzeroupper if all SSE registers are clobbered. */
> > > const function_abi &abi = insn_callee_abi (insn);
> > > - if (!hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
> > > - abi.mode_clobbers (V4DImode)))
> > > + if (vzeroupper_pattern (PATTERN (insn), VOIDmode)
> > > + || !hard_reg_set_subset_p (reg_class_contents[SSE_REGS],
> > > + abi.mode_clobbers (V4DImode)))
> > > return AVX_U128_ANY;
> >
> > You also want to check for vzeroall_pattern here.
> This is inside
> if (CALL_P (insn))
>
> vzeroupper is defined as special call_insn, but vzeroall is not.
Indeed. Patch is OK as it is then.
Thanks,
Uros.
> >
> > OK with the above change.
> >
> > Thanks,
> > Uros.
> >
> > >
> > > return AVX_U128_CLEAN;
> > > diff --git a/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> > > new file mode 100644
> > > index 00000000000..c1c9baa8fc4
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/i386/avx-vzeroupper-30.c
> > > @@ -0,0 +1,15 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-O2 -mavx -mvzeroupper -dp" } */
> > > +
> > > +#include <immintrin.h>
> > > +
> > > +extern __m256 x, y;
> > > +
> > > +void
> > > +foo ()
> > > +{
> > > + x = y;
> > > + _mm256_zeroupper ();
> > > +}
> > > +
> > > +/* { dg-final { scan-assembler-times "avx_vzeroupper" 1 } } */
> > > --
> > > 2.39.1.388.g2fc9e9ca3c
> > >
>
>
>
> --
> BR,
> Hongtao
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Make option mvzeroupper independent of optimization level.
2023-06-27 6:08 ` Hongtao Liu
@ 2023-06-27 6:11 ` Uros Bizjak
0 siblings, 0 replies; 8+ messages in thread
From: Uros Bizjak @ 2023-06-27 6:11 UTC (permalink / raw)
To: Hongtao Liu; +Cc: liuhongt, gcc-patches, hjl.tools
On Tue, Jun 27, 2023 at 8:09 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Tue, Jun 27, 2023 at 2:05 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Tue, Jun 27, 2023 at 7:55 AM liuhongt <hongtao.liu@intel.com> wrote:
> > >
> > > 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.
> > >
> > > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> > > Ok for trunk?
> > >
> > > gcc/ChangeLog:
> > >
> > > * config/i386/i386-features.cc (pass_insert_vzeroupper:gate):
> > > Move flag_expensive_optimizations && !optimize_size to ..
> > > * config/i386/i386-options.cc (ix86_option_override_internal):
> > > .. this, it makes -mvzeroupper independent of optimization
> > > level, but still keeps the behavior of architecture
> > > tuning(emit_vzeroupper) unchanged.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * gcc.target/i386/avx-vzeroupper-29.c: New testcase.
> >
> > OK.
> I'd like to backport this patch to GCC10/GCC11/GCC12/GCC13.
Also OK.
Thanks,
Uros.
> >
> > Thanks,
> > Uros.
> >
> > > ---
> > > gcc/config/i386/i386-features.cc | 3 +--
> > > gcc/config/i386/i386-options.cc | 4 +++-
> > > gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c | 14 ++++++++++++++
> > > 3 files changed, 18 insertions(+), 3 deletions(-)
> > > create mode 100644 gcc/testsuite/gcc.target/i386/avx-vzeroupper-29.c
> > >
> > > diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
> > > index 4a3b07ae045..92ae08d442e 100644
> > > --- a/gcc/config/i386/i386-features.cc
> > > +++ b/gcc/config/i386/i386-features.cc
> > > @@ -2489,8 +2489,7 @@ public:
> > > /* opt_pass methods: */
> > > bool gate (function *) final override
> > > {
> > > - return TARGET_AVX && TARGET_VZEROUPPER
> > > - && flag_expensive_optimizations && !optimize_size;
> > > + return TARGET_AVX && TARGET_VZEROUPPER;
> > > }
> > >
> > > unsigned int execute (function *) final override
> > > diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> > > index 2cb0bddcd35..f76e7c5947b 100644
> > > --- a/gcc/config/i386/i386-options.cc
> > > +++ b/gcc/config/i386/i386-options.cc
> > > @@ -2727,7 +2727,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 } } */
> > > --
> > > 2.39.1.388.g2fc9e9ca3c
> > >
>
>
>
> --
> BR,
> Hongtao
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-06-27 6:11 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-27 5:53 [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn liuhongt
2023-06-27 5:53 ` [PATCH 2/2] Make option mvzeroupper independent of optimization level liuhongt
2023-06-27 6:05 ` Uros Bizjak
2023-06-27 6:08 ` Hongtao Liu
2023-06-27 6:11 ` Uros Bizjak
2023-06-27 6:04 ` [PATCH 1/2] Don't issue vzeroupper for vzeroupper call_insn Uros Bizjak
2023-06-27 6:07 ` Hongtao Liu
2023-06-27 6:11 ` Uros Bizjak
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).