[cfe-dev] clang does not use sincos with -O2 but gcc does

Halfdan Ingvarsson via cfe-dev cfe-dev at lists.llvm.org
Thu May 18 08:12:23 PDT 2017


The answer lies inside of canCombineSinCosLibcall in
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:

....
  // GNU sin/cos functions set errno while sincos does not. Therefore
  // combining sin and cos is only safe if unsafe-fpmath is enabled.
....

unsafe-fpmath is enabled with -ffast-math.

I.e. folding to sincos is unlikely to be standard compliant. It's also the
reason why <cmath> functions can not marked constexpr :-/

IMHO, errno is an anachronism and should never have been included as a part
of <cmath>. I would personally like the base <cmath> functions to be wholly
ignorant of errno, and there to be a separate set of <cmath> functions that
throw the appropriate exceptions for those rare cases where knowledge of
domain errors is important.

I've yet to come across production code that checks errno in any capacity
after calling a math function (language support libraries excepted). I feel
that the errno requirement is a rare case that unfortunately affects the
optimizability of a large portion of code that could benefit from its
absence altogether.

- ½

On 18 May 2017 at 10:20, René J.V. Bertin via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On Thursday May 18 2017 14:55:03 Dennis Luehring wrote:
>
> >clang DOES use sincos if -ffast-math option is given
> >gcc use it even without -ffast-math
>
> To make matters even more complex: on Mac the situation is the opposite,
> that is clang always uses a sincos library function provided by Apple.
>
> >i don't think its the x87 opcode - because then LLVM would inline it -
> and not using a call
>
> That depends, LLVM cannot know how the sincos() function from libm is
> implemented.
>
> R.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170518/ff2f00da/attachment.html>


More information about the cfe-dev mailing list