On Thu, Aug 14, 2025 at 9:22 AM H.J. Lu <hjl.to...@gmail.com> wrote:
>
> commit 9804b23198b39f85a7258be556c5e8aed44b9efc
> Author: H.J. Lu <hjl.to...@gmail.com>
> Date:   Sun Apr 13 11:38:24 2025 -0700
>
>     x86: Add preserve_none and update no_caller_saved_registers attributes
>
> allowed MMX/80387 instructions in functions with no_caller_saved_registers
> attribute by accident.  Update ix86_set_current_function to properly
> check if MMX and 80387 are enabled.
>
> gcc/
>
>         PR target/121540
>         * config/i386/i386-options.cc (ix86_set_current_function):
>         Properly check if MMX and 80387 are enabled.
>
> gcc/testsuite/
>
>         PR target/121540
>         * gcc.target/i386/no-callee-saved-19a.c (dg-options): Add
>         "-mno-avx -mno-mmx -mno-80387"
>         * gcc.target/i386/no-callee-saved-19b.c: Likewise.
>         * gcc.target/i386/no-callee-saved-19c.c: Likewise.
>         * gcc.target/i386/no-callee-saved-19d.c: Likewise.
>         * gcc.target/i386/no-callee-saved-19e.c: Likewise.
>         * gcc.target/i386/pr121208-1a.c: Likewise.
>         * gcc.target/i386/pr121208-1b.c: Likewise.
>         * gcc.target/i386/pr121540-1.c: New test.
>         * gcc.target/i386/pr121540-2.c: Likewise.
>
> Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
> ---
>  gcc/config/i386/i386-options.cc                 | 17 ++++++++---------
>  .../gcc.target/i386/no-callee-saved-19a.c       |  2 +-
>  .../gcc.target/i386/no-callee-saved-19b.c       |  2 +-
>  .../gcc.target/i386/no-callee-saved-19c.c       |  2 +-
>  .../gcc.target/i386/no-callee-saved-19d.c       |  2 +-
>  .../gcc.target/i386/no-callee-saved-19e.c       |  2 +-
>  gcc/testsuite/gcc.target/i386/pr121208-1a.c     |  2 +-
>  gcc/testsuite/gcc.target/i386/pr121208-1b.c     |  2 +-
>  gcc/testsuite/gcc.target/i386/pr121540-1.c      |  8 ++++++++
>  gcc/testsuite/gcc.target/i386/pr121540-2.c      |  8 ++++++++
>  10 files changed, 31 insertions(+), 16 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr121540-1.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr121540-2.c
>
> diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> index 09a35ef6298..f96c76727e2 100644
> --- a/gcc/config/i386/i386-options.cc
> +++ b/gcc/config/i386/i386-options.cc
> @@ -3547,7 +3547,7 @@ ix86_set_current_function (tree fndecl)
>        /* Don't allow AVX, AVX512, MMX nor x87 instructions since they
>          may change processor state.  Don't allow SSE instructions in
>          exception/interrupt service routines.  */
> -      const char *isa;
> +      const char *isa = NULL;
>        if (TARGET_SSE)
>         {
>           if (TARGET_AVX512F)
> @@ -3556,15 +3556,14 @@ ix86_set_current_function (tree fndecl)
>             isa = "AVX";
>           else if (cfun->machine->func_type != TYPE_NORMAL)
>             isa = "SSE";
> -         else
> -           isa = NULL;
>         }
> -      else if (TARGET_MMX)
> -       isa = "MMX/3Dnow";
> -      else if (TARGET_80387)
> -       isa = "80387";
> -      else
> -       isa = NULL;
> +      if (isa == NULL)
> +       {
> +         if (TARGET_MMX)
> +           isa = "MMX/3Dnow";
> +         else if (TARGET_80387)
> +           isa = "80387";
> +       }

Maybe this is more readable?

diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index 09a35ef6298..136c0f2e966 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -3556,6 +3556,10 @@ ix86_set_current_function (tree fndecl)
            isa = "AVX";
          else if (cfun->machine->func_type != TYPE_NORMAL)
            isa = "SSE";
+         else if (TARGET_MMX)
+           isa = "MMX/3Dnow";
+         else if (TARGET_80387)
+           isa = "80387";
          else
            isa = NULL;
        }

>        if (isa != NULL)
>         {
>           if (cfun->machine->func_type != TYPE_NORMAL)
> diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-19a.c 
> b/gcc/testsuite/gcc.target/i386/no-callee-saved-19a.c
> index 12f35cfa8bb..3ba578df8c2 100644
> --- a/gcc/testsuite/gcc.target/i386/no-callee-saved-19a.c
> +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19a.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile { target { *-*-linux* && lp64 } } } */
> -/* { dg-options "-O2 -fno-pic -mtune=generic -msse2 -mno-apxf 
> -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
> +/* { dg-options "-O2 -fno-pic -mtune=generic -msse2 -mno-avx -mno-mmx 
> -mno-80387 -mno-apxf -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
>  /* Keep labels and directives ('.cfi_startproc', '.cfi_endproc').  */
>  /* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} 
>  } } */
>
> diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-19b.c 
> b/gcc/testsuite/gcc.target/i386/no-callee-saved-19b.c
> index c9343a65470..dc38936a61a 100644
> --- a/gcc/testsuite/gcc.target/i386/no-callee-saved-19b.c
> +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19b.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile { target { *-*-linux* && maybe_x32 } } } */
> -/* { dg-options "-O2 -mx32 -fno-pic -mtune=generic -msse2 -mno-apxf 
> -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
> +/* { dg-options "-O2 -mx32 -fno-pic -mtune=generic -msse2 -mno-avx -mno-mmx 
> -mno-80387 -mno-apxf -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
>  /* Keep labels and directives ('.cfi_startproc', '.cfi_endproc').  */
>  /* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} 
>  } } */
>
> diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-19c.c 
> b/gcc/testsuite/gcc.target/i386/no-callee-saved-19c.c
> index 05aca9f4b11..e7f247b723c 100644
> --- a/gcc/testsuite/gcc.target/i386/no-callee-saved-19c.c
> +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19c.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile { target { *-*-linux* && ia32 } } } */
> -/* { dg-options "-O2 -fno-pic -mtune=generic -msse2 
> -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
> +/* { dg-options "-O2 -fno-pic -mtune=generic -msse2 -mno-avx -mno-mmx 
> -mno-80387 -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
>  /* Keep labels and directives ('.cfi_startproc', '.cfi_endproc').  */
>  /* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} 
>  } } */
>
> diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-19d.c 
> b/gcc/testsuite/gcc.target/i386/no-callee-saved-19d.c
> index b3caa3d81b2..4657e170350 100644
> --- a/gcc/testsuite/gcc.target/i386/no-callee-saved-19d.c
> +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19d.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile { target { *-*-linux* && lp64 } } } */
> -/* { dg-options "-O2 -fno-pic -mtune=generic -msse2 -mapxf 
> -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
> +/* { dg-options "-O2 -fno-pic -mtune=generic -msse2 -mno-avx -mno-mmx 
> -mno-80387 -mapxf -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
>  /* Keep labels and directives ('.cfi_startproc', '.cfi_endproc').  */
>  /* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} 
>  } } */
>
> diff --git a/gcc/testsuite/gcc.target/i386/no-callee-saved-19e.c 
> b/gcc/testsuite/gcc.target/i386/no-callee-saved-19e.c
> index 3fcb41ff196..8e0bbe82eae 100644
> --- a/gcc/testsuite/gcc.target/i386/no-callee-saved-19e.c
> +++ b/gcc/testsuite/gcc.target/i386/no-callee-saved-19e.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile { target { *-*-linux* && maybe_x32 } } } */
> -/* { dg-options "-O2 -mx32 -fno-pic -mtune=generic -msse2 -mapxf 
> -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
> +/* { dg-options "-O2 -mx32 -fno-pic -mtune=generic -msse2 -mno-avx -mno-mmx 
> -mno-80387 -mapxf -mtune-ctrl=prologue_using_move,epilogue_using_move" } */
>  /* Keep labels and directives ('.cfi_startproc', '.cfi_endproc').  */
>  /* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} 
>  } } */
>
> diff --git a/gcc/testsuite/gcc.target/i386/pr121208-1a.c 
> b/gcc/testsuite/gcc.target/i386/pr121208-1a.c
> index cb8bd0bc8d2..f799bc81d4d 100644
> --- a/gcc/testsuite/gcc.target/i386/pr121208-1a.c
> +++ b/gcc/testsuite/gcc.target/i386/pr121208-1a.c
> @@ -1,5 +1,5 @@
>  /* { dg-do compile { target *-*-linux* } } */
> -/* { dg-options "-O2 -fPIC -mno-80387 -mtls-dialect=gnu" } */
> +/* { dg-options "-O2 -fPIC -mno-avx -mno-mmx -mno-80387 -mtls-dialect=gnu" } 
> */
>
>  extern __thread int bar;
>  extern void func (void);
> diff --git a/gcc/testsuite/gcc.target/i386/pr121208-1b.c 
> b/gcc/testsuite/gcc.target/i386/pr121208-1b.c
> index 037e9a0899c..ba37abccfc0 100644
> --- a/gcc/testsuite/gcc.target/i386/pr121208-1b.c
> +++ b/gcc/testsuite/gcc.target/i386/pr121208-1b.c
> @@ -1,4 +1,4 @@
>  /* { dg-do compile { target *-*-linux* } } */
> -/* { dg-options "-O2 -fPIC -mno-80387 -mtls-dialect=gnu2" } */
> +/* { dg-options "-O2 -fPIC -mno-avx -mno-mmx -mno-80387 -mtls-dialect=gnu2" 
> } */
>
>  #include "pr121208-1a.c"
> diff --git a/gcc/testsuite/gcc.target/i386/pr121540-1.c 
> b/gcc/testsuite/gcc.target/i386/pr121540-1.c
> new file mode 100644
> index 00000000000..dee9c279d39
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr121540-1.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=x86-64" } */
> +
> +void
> + __attribute__ ((no_caller_saved_registers))
> +fn (void)
> +{ /* { dg-message "sorry, unimplemented: MMX/3Dnow instructions aren't 
> allowed" } */
> +}
> diff --git a/gcc/testsuite/gcc.target/i386/pr121540-2.c 
> b/gcc/testsuite/gcc.target/i386/pr121540-2.c
> new file mode 100644
> index 00000000000..15a3f40af33
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr121540-2.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=x86-64 -mno-mmx" } */
> +
> +void
> + __attribute__ ((no_caller_saved_registers))
> +fn (void)
> +{ /* { dg-message "sorry, unimplemented: 80387 instructions aren't allowed" 
> } */
> +}
> --
> 2.50.1
>


-- 
BR,
Hongtao

Reply via email to