This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFA] Further HONOR_[S]NANS improvements.
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 01 Aug 2002 21:19:17 +0200
- Subject: [RFA] Further HONOR_[S]NANS improvements.
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
The attached patch applies some HONOR_[S]NANS where
flag_unsafe_math_optimizations ruled. Bootstrapped, make -k check and
installed on i686-pc-linux-gnu. Please note the first hunk, as I'm trying
to make sense out of a rather casual comment.
Unfortunately, the research that went into this patch also pointed out to
me that we will never optimize x + 0, x * 0, and 0 / x on the basis of
flag_finite_math_only alone. See simplify-rtx.c:899
case PLUS:
/* Maybe simplify x + 0 to x. The two expressions are equivalent
when x is NaN, infinite, or finite and non-zero. They aren't
when x is -0 and the rounding mode is not towards -infinity,
since (-0) + 0 is then 0. */
if (!HONOR_SIGNED_ZEROS (mode) && trueop1 == CONST0_RTX (mode))
return op0;
and simplify-rtx.c:1167
/* Maybe simplify x * 0 to 0. The reduction is not valid if
x is NaN, since x * 0 is then also NaN. Nor is it valid
when the mode has signed zeros, since multiplying a negative
number by 0 will give -0, not 0. */
if (!HONOR_NANS (mode)
&& !HONOR_SIGNED_ZEROS (mode)
&& trueop1 == CONST0_RTX (mode)
&& ! side_effects_p (op0))
return op1;
GRRR ! &^$%#$#$@*^%*^%*&^*^$$#^^*&%R%$$% !!!!
Obviously, I'm not going to invent yet another
this-optimization-is-not-prohibited-in-Fortran flag.
Can't these decisions be enforced via language hooks ?
Thanks for any insight offered.
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
2002-08-01 Toon Moene <toon@moene.indiv.nluug.nl>
* simplify-rtx.c (simplify_binary_operation): x * 1 is allowed
when not honoring signalling NaNx.
(simplify_ternary_operation): a == b has a definite value
when not honoring NaNs.
*** simplify-rtx.c.orig Sun Jul 28 16:20:31 2002
--- simplify-rtx.c Thu Aug 1 13:27:33 2002
*************** simplify_binary_operation (code, mode, o
*** 1170,1177 ****
return op1;
! /* In IEEE floating point, x*1 is not equivalent to x for nans.
! However, ANSI says we can drop signals,
! so we can do this anyway. */
! if (trueop1 == CONST1_RTX (mode))
return op0;
--- 1170,1177 ----
return op1;
! /* In IEEE floating point, x*1 is not equivalent to x for
! signalling NaNs. */
! if (!HONOR_SNANS (mode)
! && trueop1 == CONST1_RTX (mode))
return op0;
*************** simplify_ternary_operation (code, mode,
*** 2194,2203 ****
/* Convert a == b ? b : a to "a". */
if (GET_CODE (op0) == NE && ! side_effects_p (op0)
! && (! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
&& rtx_equal_p (XEXP (op0, 0), op1)
&& rtx_equal_p (XEXP (op0, 1), op2))
return op1;
else if (GET_CODE (op0) == EQ && ! side_effects_p (op0)
! && (! FLOAT_MODE_P (mode) || flag_unsafe_math_optimizations)
&& rtx_equal_p (XEXP (op0, 1), op1)
&& rtx_equal_p (XEXP (op0, 0), op2))
--- 2194,2203 ----
/* Convert a == b ? b : a to "a". */
if (GET_CODE (op0) == NE && ! side_effects_p (op0)
! && !HONOR_NANS (mode)
&& rtx_equal_p (XEXP (op0, 0), op1)
&& rtx_equal_p (XEXP (op0, 1), op2))
return op1;
else if (GET_CODE (op0) == EQ && ! side_effects_p (op0)
! && !HONOR_NANS (mode)
&& rtx_equal_p (XEXP (op0, 1), op1)
&& rtx_equal_p (XEXP (op0, 0), op2))