This is the mail archive of the
`gcc-patches@gcc.gnu.org`
mailing list for the GCC project.

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |

Other format: | [Raw text] |

*From*: Fariborz Jahanian <fjahanian at apple dot com>*To*: Geoff Keating <geoffk at geoffk dot org>*Cc*: Gabriel Dos Reis <gdr at cs dot tamu dot edu>, Dale Johannesen <dalej at apple dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, Roger Sayle <roger at eyesopen dot com>*Date*: Wed, 6 Oct 2004 10:11:50 -0700*Subject*: Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication*References*: <2B2F21A1-16FF-11D9-957B-000A95BA54A6@apple.com> <m28yalosbv.fsf@greed.local> <m3sm8sorfl.fsf@merlin.cs.tamu.edu> <B829D438-1710-11D9-BB5A-000A95B1F520@geoffk.org> <C6712220-1712-11D9-A3AB-000A95D7CD40@apple.com> <028CC984-1718-11D9-BB5A-000A95B1F520@geoffk.org>

On Oct 5, 2004, at 2:46 PM, Geoff Keating wrote:

OK. I am not going to re-design Fariborz's patch for him in an e-mail exchange. It is clear that the explanation of the patch is inadequate to determine whether or not the patch is correct, so the patch is rejected. Fariborz, please re-post the patch with a better explanation, and addressing the other points I mentioned.

test case.

operation (multiplication by Infinity), when compiled for apple-ppc-darwin target.

For different values of "x" this leads to undeserved or absent floating point

exceptions, and breaks some of the elementary math functions in Libm. Occurs

at optimization O1 and higher.

/* test */ static const double C = 0x1.0p1023;

double foo(double x) { return ( ( (x * C) * C ) * C ); }

in precision as well as range. The implementation cannot generally apply the mathematical associative

rules for addition or multiplication, nor the distributive rule, because of roundoff error, even

in the absence of overflowand underflow. Likewise, implementations cannot generally replace decimal

constants in order to rearrange expressions. In the following fragment, rearrangements suggested by

mathematical rules for real numbers are often not valid (see F.8).

double x, y, z;

/*... */

x=(x*y)*z;

//not equivalent to

x*=y*z;

Question remains, under which flag should we place this specific unsafe optiomization?

There has been three suggestions, I will address each, one by one.

1. Do this optimization when flag_trapping_math is 0 (default is 1). "Zero means that floating-point math operations cannot generate a (user-visible) trap". This includes overflow, underflow. This certainly can be the flag to check for. But such an optimization may cause finite results which could be incorrect without causing a trap, for example, a roundoff error.

2. Do this optimization when flag_finite_math_only is 1 (default is 0). "Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or +-Infs". Again, result of such an optimization can be finite but wrong.

"Allow optimizations for floating-point arithmetic that (a) assume

that arguments and results are valid and (b) may violate IEEE or

ANSI standards".

Such an optimization is in violation of Section 5.1.2.3 of ANSI standards

as noted in above.

case PLUS_EXPR: if (FLOAT_TYPE_P (type) && !flag_unsafe_math_optimizations) return false; /* -(A + B) -> (-B) - A. */ ... /* -(A + B) -> (-A) - B. */ ...

other situations to disallow certain optimizations which are in violation of ANSI

standards. This is the flag that I check for in my patch.

ChangeLog:

* tree-ssa-dom.c (associative_fp_binop): New function. (simplify_rhs_and_lookup_avail_expr): Disallow associativity and constant folding of floating point MULT_EXPR/PLUS_EXPR expressions.

**Attachment:
fsf-patch-tree-ssa-dom.txt**

**Attachment:
unsafe-fp-assoc.c**

**Follow-Ups**:

**References**:**Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication***From:*Fariborz Jahanian

**Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication***From:*Geoffrey Keating

**Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication***From:*Gabriel Dos Reis

**Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication***From:*Geoff Keating

**Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication***From:*Dale Johannesen

**Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication***From:*Geoff Keating

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |