http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51938

--- Comment #2 from Marc Glisse <marc.glisse at normalesup dot org> 2012-01-23 
12:51:42 UTC ---
(In reply to comment #1)
> I suspect also worthwhile for integral types.  Note that for real types
> you need -ffinite-math-only - I bet the clang result is wrong for NaNs.

I hadn't thought about it (this code could indeed use -ffinite-math-only), but
it appears I am lucky, the code really is equivalent to if(x<0) f(); as
claimed. Indeed, for a NaN, x>0 and x<0 are false, so sign returns ZERO which
is not NEG. Comparing sign(x) to ZERO would indeed be different than x==0. On
the other hand, ucomisd sets ZF to 1 for QNaN. clang's code appears to be right
on all variations I tried.

> Btw, what's the optimal assembly you expect?

clang generates:

    pxor    %xmm1, %xmm1
    ucomisd    %xmm0, %xmm1
    ja    .LBB1_2
    ret
.LBB1_2:
    xorb    %al, %al
    jmp    f                       # TAILCALL

No idea if that's optimal (it also depends on which branch is most likely), but
one pair of ucomisd+ja is certainly better than 2.

Reply via email to