[PATCH] x86: Use XMM31 for scratch SSE register

Uros Bizjak ubizjak@gmail.com
Tue Aug 3 08:43:46 GMT 2021


On Tue, Aug 3, 2021 at 10:15 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Tue, Aug 3, 2021 at 4:03 PM Uros Bizjak via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > On Mon, Aug 2, 2021 at 7:47 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > In 64-bit mode, use XMM31 for scratch SSE register to avoid vzeroupper
> > > if possible.
> > >
> > > gcc/
> > >
> > >         * config/i386/i386.c (ix86_gen_scratch_sse_rtx): In 64-bit mode,
> > >         try XMM31 to avoid vzeroupper.
> > >
> > > gcc/testsuite/
> > >
> > >         * gcc.target/i386/avx-vzeroupper-14.c: Pass -mno-avx512f to
> > >         disable XMM31.
> > >         * gcc.target/i386/avx-vzeroupper-15.c: Likewise.
> > >         * gcc.target/i386/pr82941-1.c: Updated.  Check for vzeroupper.
> > >         * gcc.target/i386/pr82942-1.c: Likewise.
> > >         * gcc.target/i386/pr82990-1.c: Likewise.
> > >         * gcc.target/i386/pr82990-3.c: Likewise.
> > >         * gcc.target/i386/pr82990-5.c: Likewise.
> > >         * gcc.target/i386/pr100865-4b.c: Likewise.
> > >         * gcc.target/i386/pr100865-6b.c: Likewise.
> > >         * gcc.target/i386/pr100865-7b.c: Likewise.
> > >         * gcc.target/i386/pr100865-10b.c: Likewise.
> > >         * gcc.target/i386/pr100865-8b.c: Updated.
> > >         * gcc.target/i386/pr100865-9b.c: Likewise.
> > >         * gcc.target/i386/pr100865-11b.c: Likewise.
> > >         * gcc.target/i386/pr100865-12b.c: Likewise.
> > > ---
> > >  gcc/config/i386/i386.c                         | 18 +++++++++++++++---
> > >  .../gcc.target/i386/avx-vzeroupper-14.c        |  2 +-
> > >  .../gcc.target/i386/avx-vzeroupper-15.c        |  2 +-
> > >  gcc/testsuite/gcc.target/i386/pr100865-10b.c   |  1 +
> > >  gcc/testsuite/gcc.target/i386/pr100865-11b.c   |  2 +-
> > >  gcc/testsuite/gcc.target/i386/pr100865-12b.c   |  2 +-
> > >  gcc/testsuite/gcc.target/i386/pr100865-4b.c    |  2 ++
> > >  gcc/testsuite/gcc.target/i386/pr100865-6b.c    |  5 ++++-
> > >  gcc/testsuite/gcc.target/i386/pr100865-7b.c    |  5 ++++-
> > >  gcc/testsuite/gcc.target/i386/pr100865-8b.c    |  2 +-
> > >  gcc/testsuite/gcc.target/i386/pr100865-9b.c    |  2 +-
> > >  gcc/testsuite/gcc.target/i386/pr82941-1.c      |  3 ++-
> > >  gcc/testsuite/gcc.target/i386/pr82942-1.c      |  3 ++-
> > >  gcc/testsuite/gcc.target/i386/pr82990-1.c      |  3 ++-
> > >  gcc/testsuite/gcc.target/i386/pr82990-3.c      |  3 ++-
> > >  gcc/testsuite/gcc.target/i386/pr82990-5.c      |  3 ++-
> > >  16 files changed, 42 insertions(+), 16 deletions(-)
> > >
> > > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> > > index 842eb0e6786..ec0690876b7 100644
> > > --- a/gcc/config/i386/i386.c
> > > +++ b/gcc/config/i386/i386.c
> > > @@ -23335,9 +23335,21 @@ rtx
> > >  ix86_gen_scratch_sse_rtx (machine_mode mode)
> > >  {
> > >    if (TARGET_SSE && !lra_in_progress)
> > > -    return gen_rtx_REG (mode, (TARGET_64BIT
> > > -                              ? LAST_REX_SSE_REG
> > > -                              : LAST_SSE_REG));
> > > +    {
> > > +      unsigned int regno;
> > > +      if (TARGET_64BIT)
> > > +       {
> > > +         /* In 64-bit mode, use XMM31 to avoid vzeroupper and always
> > > +            use XMM31 for CSE.  */
> > > +         if (ix86_hard_regno_mode_ok (LAST_EXT_REX_SSE_REG, mode))
> > > +           regno = LAST_EXT_REX_SSE_REG;
> > > +         else
> > > +           regno = LAST_REX_SSE_REG;
> > > +       }
> > > +      else
> > > +       regno = LAST_SSE_REG;
> >
> > Assuming that ix86_hard_regno_mode_ok always returns false for XMM31
> > in 64bit mode, we can do:
> >
> > /* Use XMM31 if available to avoid vzeroupper.  */
> > if (ix86_hard_regno_mode_ok (LAST_EXT_REX_SSE_REG, mode))
> >   regno = LAST_EXST_REX_SSE_REG;
> > else if (TARGET_64BIT)
> >   regno = LAST_EXT_REX_SSE_REG;

> why? w/o avx512 xmm31 is not available.

Oh, a typo, this should read LAST_REX_SSE_REG.

Uros.


More information about the Gcc-patches mailing list