This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize (x+2.0)+3.0 with -ffast-math
- From: Geoff Keating <geoffk at geoffk dot org>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: 11 Aug 2003 10:35:03 -0700
- Subject: Re: [PATCH] Optimize (x+2.0)+3.0 with -ffast-math
- References: <Pine.LNX.4.44.0308101333370.19866-100000@www.eyesopen.com>
Roger Sayle <roger@eyesopen.com> writes:
> The properties of floating point arithmetic mean that its unsafe to
> take advantage of associative operators. For this reason, GCC doesn't
> attempt to optimize (x*2.0)*3.0 or (x+2.0)+3.0 by default.
>
> With -ffast-math, however, we're allowed to apply more aggressive
> optimizations that may produce slightly different results under some
> exceptional inputs values. Under these conditions, GCC does convert
> (x*2.0)*3.0 into x*6.0, but currently won't transform (x+2.0)+3.0
> into x+5.0. The patch below tweaks the flag_unsafe_math_optimizations
> test to allow us to take advantage of other associative floating point
> operators than just MULT_EXPR, such as MIN_EXPR and MAX_EXPR.
>
> For comparison, SGI's Pro64 compilers allow reassociation of both
> addition and multiplication with their equivalent of -ffast-math.
>
> The following patch has been tested on i686-pc-linux-gnu with a full
> "make bootstrap", all languages except treelang, and regression tested
> with a top-level "make -k check" with no new failures.
>
> Ok for mainline?
>
>
> 2003-08-10 Roger Sayle <roger@eyesopen.com>
>
> * fold-const.c (fold): Optimize any associative floating point
> operator with -funsafe-math-optimizations, not just MULT_EXPR.
This is OK.
--
- Geoffrey Keating <geoffk@geoffk.org>