Re: Fwd: GCC Optimization for expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2008-11-30 11:35:45 -0800, Tim Prince wrote:
> gfortran is permitted to extract common factors this way, but it will
> recognize only a few of them from the original version.  The C standard
> doesn't permit automatic optimization of common factors.

The C standard permits such kind of optimization unless contraction
of floating expressions is disabled. This can have bad side effects,
though. I only know that GCC can automatically contract a multiply
and an add to a FMA, on targets where the FMA is available (even
when contraction is disabled -- but this is a bug). C code can also
exploit that, but you should know what you're doing. BTW, I've shown
an example of a bad side effect due to the contraction to a FMA:

  http://www.vinc17.org/research/fptest.en.html#contract2fma

> This points up an exception to the common factors optimization rule:
> x + x2*x should not be written as x*(1 + x2), as this would not save
> an operation,

When a FMA is available, you may even waste an operation with
x * (1 + x2), depending on the context.

> and would reduce accuracy for the desirable case where the x
> term is larger than the trailing terms.  (x+x) is preferred to x*2, but
> optimizers should be capable of making these choices automatically.

This also depends on the context (still the FMA...).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux