On Mon, Aug 24, 2026 at 10:10 AM Sun, Qin <[email protected]> wrote:
>
> When compiling with `-msoft-float -mfpmath=387`, `-msoft-float` turns off 387.
> With neither FPMATH_SSE nor FPMATH_387 enabled, no unit can do FP arithmetics.
> The i386-options.cc omits this kind of check, so ICE is triggered. We need
> to add check in i386-options.cc to cover FPMATH_387 scenario when FPMATH_SSE
> is false.
>
> gcc/ChangeLog:
>
>         PR target/119300
>         * config/i386/i386-options.cc (ix86_option_override_internal): Add 
> check for
>         FPMATH_SSE == 0 scenario to enable 387 (if available).
>
> gcc/testsuite/ChangeLog:
>
>         PR target/119300
>         * gcc.target/i386/pr119300.c: New test.

OK with a dg-options addition, described below.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386-options.cc          | 13 +++++++++++++
>  gcc/testsuite/gcc.target/i386/pr119300.c | 10 ++++++++++
>  2 files changed, 23 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr119300.c
>
> diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> index 480862c7134..67c73d2ec6a 100644
> --- a/gcc/config/i386/i386-options.cc
> +++ b/gcc/config/i386/i386-options.cc
> @@ -2823,6 +2823,19 @@ ix86_option_override_internal (bool main_args_p,
>               opts->x_ix86_fpmath = FPMATH_SSE;
>             }
>         }
> +      else if (opts->x_ix86_fpmath & FPMATH_387)
> +       {
> +         if (!TARGET_80387_P (opts->x_target_flags))
> +           {
> +             if (TARGET_SSE_P (opts->x_ix86_isa_flags))
> +               {
> +                 warning (0, "387 instruction set disabled, using SSE 
> arithmetics");
> +                 opts->x_ix86_fpmath = FPMATH_SSE;
> +               }
> +             else
> +               error ("387 and SSE instruction sets disabled, no FP math 
> units");
> +           }
> +       }
>      }
>    /* For all chips supporting SSE2, -mfpmath=sse performs better than
>       fpmath=387.  The second is however default at many targets since the
> diff --git a/gcc/testsuite/gcc.target/i386/pr119300.c 
> b/gcc/testsuite/gcc.target/i386/pr119300.c
> new file mode 100644
> index 00000000000..a2490219e5f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr119300.c
> @@ -0,0 +1,10 @@
> +/* { dg-do compile } */
> +/* { dg-options "-msoft-float -mfpmath=387" } */

Please add explicit -msse to dg-options to also cover 32-bit targets
that don't eable SSE by default.

> +
> +float
> +foo (float f)
> +{
> +  return __builtin_ia32_rsqrtf (f);
> +}
> +
> +/* { dg-warning "387 instruction set disabled, using SSE arithmetics" "" { 
> target *-*-* } 0 } */
> --
> 2.25.1
>

Reply via email to