This is the mail archive of the gcc-help@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: Floating point optimizations


> we are currently investigating some numerical algorithms and the claim
> appeared that a C statement like
>   x = c - (c - a);
> would be easily transformed into
>   x = a;
> by the compiler. Now investigating this with a vanilla GCC 4.1.2 failed
> to support the claim. Compiling the below program with -O3 -ffast-math
> keeps the computation of x. The output shows x is different from a. The
> question is, is there some compiler switch or the like to get GCC to
> make the above transformation? I searched the docs but had the
> impression that all relevant flags should be included in the above two
> (especially ffast-math).

This transformation is indeed included into -ffast-math.  I checked with

$ gcc --version
gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52)

and it does eliminate the calculation.  What does generated assembly code look
like in your case?  Note you may as well check on this code:

double f(double a, double c)
{
  return c - (c - a);
}

HTH
--
Alexander Monakov


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