This is the mail archive of the gcc@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: fast-math optimization question


On Thu, Oct 9, 2014 at 11:23 AM, Steve Ellcey <sellcey@mips.com> wrote:
> I have a -ffast-math (missing?) optimization question.  I noticed on MIPS
> that if I compiled:
>
>         #include <math.h>
>         extern x;
>         void foo() { x = sin(log(x)); }
>
> GCC will extend 'x' to double precision, call the double precision log and sin
> functions and then truncate the result to single precision.
>
> If instead, I have:
>
>         #include <math.h>
>         extern x;
>         void foo() { x = log(x); x = sin(x); }
>
> Then GCC will call the single precision log and sin functions and not do
> any extensions or truncations.  In addition to avoiding the extend/trunc
> instructions the single precision log and sin functions are presumably
> faster then the double precision ones making the entire code much faster.
>
> Is there a reason why GCC couldn't (under -ffast-math) call the single
> precision routines for the first case?

There is no reason why it could not.  The reason why it does not
currently is because there is no pass which does the demotion and the
only case of demotion that happens is with a simple
(float)function((double)float_val);

Thanks,
Andrew


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