public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marc.glisse at normalesup dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/51938] missed optimization: 2 comparisons
Date: Mon, 23 Jan 2012 13:07:00 -0000	[thread overview]
Message-ID: <bug-51938-4-7lAXLgUcNj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51938-4@http.gcc.gnu.org/bugzilla/>

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.


  parent reply	other threads:[~2012-01-23 12:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-21 22:54 [Bug tree-optimization/51938] New: " marc.glisse at normalesup dot org
2012-01-23 10:29 ` [Bug rtl-optimization/51938] " rguenth at gcc dot gnu.org
2012-01-23 13:07 ` marc.glisse at normalesup dot org [this message]
2012-06-06 21:23 ` glisse at gcc dot gnu.org
2012-06-07 14:54 ` [Bug tree-optimization/51938] " marc.glisse at normalesup dot org
2012-06-08 13:07 ` glisse at gcc dot gnu.org
2012-06-08 19:49 ` glisse at gcc dot gnu.org
2012-06-08 20:03 ` glisse at gcc dot gnu.org
2012-06-09 21:36 ` glisse at gcc dot gnu.org
2012-08-06 16:39 ` glisse at gcc dot gnu.org
2012-08-06 16:53 ` glisse at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-51938-4-7lAXLgUcNj@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).