https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103559
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
CC| |aldyh at gcc dot gnu.org
--- Comment #5 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Jeremy R. from comment #0)
> For a simple invocation of sqrt, gcc inserts a < 0 check to set math errno
> if needed. E.g.
>
> float f(float x) {
> return sqrt(x);
> }
>
> Is generated as
>
> f(float):
> vxorps xmm1, xmm1, xmm1
> vucomiss xmm1, xmm0
> ja .L10
> vsqrtss xmm0, xmm0, xmm0
> ret
> .L10:
> jmp sqrtf
>
>
> Unfortunately, this check is still present when the GCC is able to prove
> that x is non-negative:
>
> float f(float x) {
> if(x < 0) [[unlikely]] {
> __builtin_unreachable();
> } else {
> return sqrt(x);
> }
> }
x could also be a NAN which I *think* the hardware sqrt won't handle, so a
better test would be:
if (x < 0.0 || __builtin_isnan(x)) [[unlikely]]
__builtin_unreachable ();
or perhaps:
if (!__builtin_isgreater(x, 0.0))
Either way, this is a subset of PR91645 so I'm closing it as a duplicate.
*** This bug has been marked as a duplicate of bug 91645 ***