This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Floating point optimizations
- From: Alexander Monakov <monoid at ispras dot ru>
- To: Christian Keil <c dot keil at tu-harburg dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 3 Apr 2008 21:27:18 +0400
- Subject: Re: Floating point optimizations
- References: <47F50A75.6070801@tu-harburg.de>
> 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