This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] -ffinite-math-only A-A
- From: Christian BRUEL <christian dot bruel at st dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 22 Aug 2007 09:26:28 +0200
- Subject: [PATCH] -ffinite-math-only A-A
Hello,
I believe that ieee floating point A-A can be optimized to 0 under
-ffinite-math-only.
so on i686 the code
float
foo(float x)
{
return (x-x);
}
now compiles with -O2 -ffinite-math-only into
foo:
pushl %ebp
popl %ebp
fldz
ret
instead of
foo:
pushl %ebp
movl %esp, %ebp
flds 8(%ebp)
popl %ebp
fsub %st(0), %st
Additional note :
The sequence (x-x) is common and is also used in the newlib to generate
NaN with (x-x)/(x-x). So do_divide in real.c is now able to recognize
0/0 and emit a NaN constant instead of 1.0 (fixing a bug in sh4 newlib
build where -ffinite-math-only is set by default).
2007-07-16 Christian Bruel <christian.bruel@st.com>
* fold-const.c (fold_binary): Optimize A-A->0 if -ffinite-math-only.
* simplify_rtx (simplify_binary_operation_1): Likewise.
boostraped and regtested on i686-pc-linux-gnu
regtested on sh-superh-elf (defaults -ffinite-math-only)
Best Regards,
Christian
Index: fold-const.c
===================================================================
--- fold-const.c (revision 127666)
+++ fold-const.c (working copy)
@@ -10152,7 +10152,8 @@
if ((! FLOAT_TYPE_P (type)
|| (flag_unsafe_math_optimizations
&& !HONOR_NANS (TYPE_MODE (type))
- && !HONOR_INFINITIES (TYPE_MODE (type))))
+ && !HONOR_INFINITIES (TYPE_MODE (type)))
+ || flag_finite_math_only)
&& operand_equal_p (arg0, arg1, 0))
return fold_convert (type, integer_zero_node);
Index: simplify-rtx.c
===================================================================
--- simplify-rtx.c (revision 127666)
+++ simplify-rtx.c (working copy)
@@ -1776,7 +1776,8 @@
&& (! FLOAT_MODE_P (mode)
|| (flag_unsafe_math_optimizations
&& !HONOR_NANS (mode)
- && !HONOR_INFINITIES (mode))))
+ && !HONOR_INFINITIES (mode))
+ || flag_finite_math_only))
return CONST0_RTX (mode);
/* Change subtraction from zero into negation. (0 - x) is the