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]

Re: [PATCH] Optimize (x+2.0)+3.0 with -ffast-math


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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]