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):
        Warn and use SSE arithmetics when -mfpmath=387 is set, 387 is turned
        off but SSE is available.

gcc/testsuite/ChangeLog:

        PR target/119300
        * gcc.target/i386/pr119300.c: New test.
        * gcc.target/i386/pr126148.c: Use -mno-sse instead of -mfpmath=387
        to disable SSE math.
---
Changes in v3:
  Removed the error() when 387 and SSE instruction set are both enabled,
  because the error made g++.target/i386/pr88998.C fail. That test clears
  both units.
  Adjusted gcc.target/i386/pr126148.c to use -mno-sse instead of -mfpmath=387,
  because -mno-80387 -mfpmath=387 will result in a SSE-available path with our
  fix now. -mno-80387 -mno-sse can keep the FP disabled condition.

 gcc/config/i386/i386-options.cc          |  7 +++++++
 gcc/testsuite/gcc.target/i386/pr119300.c | 10 ++++++++++
 gcc/testsuite/gcc.target/i386/pr126148.c |  2 +-
 3 files changed, 18 insertions(+), 1 deletion(-)
 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 6bb5e1a08d9..e7f06154103 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -2793,6 +2793,13 @@ ix86_option_override_internal (bool main_args_p,
              opts->x_ix86_fpmath = FPMATH_SSE;
            }
        }
+      else if ((opts->x_ix86_fpmath & FPMATH_387)
+              && !TARGET_80387_P (opts->x_target_flags)
+              && TARGET_SSE_P (opts->x_ix86_isa_flags))
+       {
+         warning (0, "387 instruction set disabled, using SSE arithmetics");
+         opts->x_ix86_fpmath = FPMATH_SSE;
+       }
     }
   /* 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..e5611cdd00e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr119300.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-msoft-float -mfpmath=387 -msse" } */
+
+float
+foo (float f)
+{
+  return __builtin_ia32_rsqrtf (f);
+}
+
+/* { dg-warning "387 instruction set disabled, using SSE arithmetics" "" { 
target *-*-* } 0 } */
diff --git a/gcc/testsuite/gcc.target/i386/pr126148.c 
b/gcc/testsuite/gcc.target/i386/pr126148.c
index f706d303c4d..ab4009dd6a8 100644
--- a/gcc/testsuite/gcc.target/i386/pr126148.c
+++ b/gcc/testsuite/gcc.target/i386/pr126148.c
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2 -ffast-math -mapxf -mno-80387 -mfpmath=387" } */
+/* { dg-options "-O2 -ffast-math -mapxf -mno-80387 -mno-sse" } */
 
 int foo (int a, double b) {
   if (a || b)
-- 
2.25.1

Reply via email to