This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix target/6041
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 29 Mar 2002 15:30:16 -0800
- Subject: fix target/6041
The analysis in the PR is largely confused, because the originator
wound up using glibc's inline assembly the whole time rather than
the compiler builtins. But the conclusion makes sense -- if we can
be certain that emulation is not required, disable the flag that
says that the emulator is broken. This should improve things on
all three bsd's, where this flag is default.
There's also a bug fix in here: the conditionals for three patterns
had typos. This fix is the reason I went ahead and put this on the
branch rather than mainline only.
r~
* config/i386/i386.c (x86_arch_always_fancy_math_387): New.
(override_options): Disable NO_FANCY_MATH_387 if the arch allows.
* config/i386/i386.h (x86_arch_always_fancy_math_387): New.
* config/i386/i386.md (sqrtxf2, sqrtextendsfxf2, sinxf2): Fix
conditional.
* docs/invoke.texi: Update -mno-fancy-math-387 docs.
* gcc.dg/i386-387-1.c, gcc.dg/i386-387-2.c: New.
Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.368.2.6
diff -c -p -d -r1.368.2.6 i386.c
*** config/i386/i386.c 2002/03/27 23:06:37 1.368.2.6
--- config/i386/i386.c 2002/03/29 23:17:27
*************** const int x86_accumulate_outgoing_args =
*** 392,397 ****
--- 392,398 ----
const int x86_prologue_using_move = m_ATHLON | m_PENT4 | m_PPRO;
const int x86_epilogue_using_move = m_ATHLON | m_PENT4 | m_PPRO;
const int x86_decompose_lea = m_PENT4;
+ const int x86_arch_always_fancy_math_387 = m_PENT|m_PPRO|m_ATHLON|m_PENT4;
/* In case the avreage insn count for single function invocation is
lower than this constant, emit fast (but longer) prologue and
*************** override_options ()
*** 1116,1121 ****
--- 1117,1127 ----
wrt NaNs. This lets us use a shorter comparison sequence. */
if (flag_unsafe_math_optimizations)
target_flags &= ~MASK_IEEE_FP;
+
+ /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
+ since the insns won't need emulation. */
+ if (x86_arch_always_fancy_math_387 & (1 << ix86_arch))
+ target_flags &= ~MASK_NO_FANCY_MATH_387;
if (TARGET_64BIT)
{
Index: config/i386/i386.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.h,v
retrieving revision 1.243.2.3
diff -c -p -d -r1.243.2.3 i386.h
*** config/i386/i386.h 2002/03/18 17:47:14 1.243.2.3
--- config/i386/i386.h 2002/03/29 23:17:27
*************** extern const int x86_add_esp_4, x86_add_
*** 222,227 ****
--- 222,228 ----
extern const int x86_partial_reg_dependency, x86_memory_mismatch_stall;
extern const int x86_accumulate_outgoing_args, x86_prologue_using_move;
extern const int x86_epilogue_using_move, x86_decompose_lea;
+ extern const int x86_arch_always_fancy_math_387;
extern int x86_prefetch_sse;
#define TARGET_USE_LEAVE (x86_use_leave & CPUMASK)
Index: config/i386/i386.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.md,v
retrieving revision 1.339.2.2
diff -c -p -d -r1.339.2.2 i386.md
*** config/i386/i386.md 2002/03/20 21:34:36 1.339.2.2
--- config/i386/i386.md 2002/03/29 23:17:27
***************
*** 14709,14715 ****
[(set (match_operand:XF 0 "register_operand" "=f")
(sqrt:XF (float_extend:XF
(match_operand:DF 1 "register_operand" "0"))))]
! "!TARGET_64BIT && TARGET_80387 && TARGET_NO_FANCY_MATH_387"
"fsqrt"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")
--- 14709,14715 ----
[(set (match_operand:XF 0 "register_operand" "=f")
(sqrt:XF (float_extend:XF
(match_operand:DF 1 "register_operand" "0"))))]
! "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387"
"fsqrt"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")
***************
*** 14729,14735 ****
[(set (match_operand:XF 0 "register_operand" "=f")
(sqrt:XF (float_extend:XF
(match_operand:SF 1 "register_operand" "0"))))]
! "!TARGET_64BIT && TARGET_80387 && TARGET_NO_FANCY_MATH_387"
"fsqrt"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")
--- 14729,14735 ----
[(set (match_operand:XF 0 "register_operand" "=f")
(sqrt:XF (float_extend:XF
(match_operand:SF 1 "register_operand" "0"))))]
! "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387"
"fsqrt"
[(set_attr "type" "fpspc")
(set_attr "mode" "XF")
***************
*** 14776,14782 ****
(define_insn "sinxf2"
[(set (match_operand:XF 0 "register_operand" "=f")
(unspec:XF [(match_operand:XF 1 "register_operand" "0")] 1))]
! "!TARGET_64BIT && TARGET_80387 && TARGET_NO_FANCY_MATH_387
&& flag_unsafe_math_optimizations"
"fsin"
[(set_attr "type" "fpspc")
--- 14776,14782 ----
(define_insn "sinxf2"
[(set (match_operand:XF 0 "register_operand" "=f")
(unspec:XF [(match_operand:XF 1 "register_operand" "0")] 1))]
! "!TARGET_64BIT && TARGET_80387 && !TARGET_NO_FANCY_MATH_387
&& flag_unsafe_math_optimizations"
"fsin"
[(set_attr "type" "fpspc")
Index: doc/invoke.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.119.2.7
diff -c -p -d -r1.119.2.7 invoke.texi
*** doc/invoke.texi 2002/03/28 19:45:25 1.119.2.7
--- doc/invoke.texi 2002/03/29 23:17:28
*************** in ordinary CPU registers instead.
*** 7412,7420 ****
@opindex mno-fancy-math-387
Some 387 emulators do not support the @code{sin}, @code{cos} and
@code{sqrt} instructions for the 387. Specify this option to avoid
! generating those instructions. This option is the default on FreeBSD@.
! As of revision 2.6.1, these instructions are not generated unless you
! also use the @option{-funsafe-math-optimizations} switch.
@item -malign-double
@itemx -mno-align-double
--- 7412,7423 ----
@opindex mno-fancy-math-387
Some 387 emulators do not support the @code{sin}, @code{cos} and
@code{sqrt} instructions for the 387. Specify this option to avoid
! generating those instructions. This option is the default on FreeBSD,
! OpenBSD and NetBSD@. This option is overridden when @option{-march}
! indicates that the target cpu will always have an FPU and so the
! instruction will not need emulation. As of revision 2.6.1, these
! instructions are not generated unless you also use the
! @option{-funsafe-math-optimizations} switch.
@item -malign-double
@itemx -mno-align-double
Index: testsuite/gcc.dg/i386-387-1.c
===================================================================
RCS file: i386-387-1.c
diff -N i386-387-1.c
*** /dev/null Tue May 5 13:32:27 1998
--- testsuite/gcc.dg/i386-387-1.c Fri Mar 29 15:17:28 2002
***************
*** 0 ****
--- 1,10 ----
+ /* Verify that -mno-fancy-math-387 works. */
+ /* { dg-do compile { target "i?86-*-*" } } */
+ /* { dg-options "-O -ffast-math -mfpmath=387 -mno-fancy-math-387" } */
+ /* { dg-final { scan-assembler "call\tsin" } } */
+ /* { dg-final { scan-assembler "call\tcos" } } */
+ /* { dg-final { scan-assembler "call\tsqrt" } } */
+
+ double f1(double x) { return __builtin_sin(x); }
+ double f2(double x) { return __builtin_cos(x); }
+ double f3(double x) { return __builtin_sqrt(x); }
Index: testsuite/gcc.dg/i386-387-2.c
===================================================================
RCS file: i386-387-2.c
diff -N i386-387-2.c
*** /dev/null Tue May 5 13:32:27 1998
--- testsuite/gcc.dg/i386-387-2.c Fri Mar 29 15:17:28 2002
***************
*** 0 ****
--- 1,10 ----
+ /* Verify that -march overrides -mno-fancy-math-387. */
+ /* { dg-do compile { target "i?86-*-*" } } */
+ /* { dg-options "-O -ffast-math -mfpmath=387 -march=i686 -mno-fancy-math-387" } */
+ /* { dg-final { scan-assembler "fsin" } } */
+ /* { dg-final { scan-assembler "fcos" } } */
+ /* { dg-final { scan-assembler "fsqrt" } } */
+
+ double f1(double x) { return __builtin_sin(x); }
+ double f2(double x) { return __builtin_cos(x); }
+ double f3(double x) { return __builtin_sqrt(x); }