public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jzwinck at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug other/63387] New: Optimize pairs of isnan() calls into a single isunordered()
Date: Sat, 27 Sep 2014 03:11:00 -0000	[thread overview]
Message-ID: <bug-63387-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63387

            Bug ID: 63387
           Summary: Optimize pairs of isnan() calls into a single
                    isunordered()
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jzwinck at gmail dot com

Whenever a program does (isnan(x) || isnan(y)), GCC 4.7 and 4.9 in the best
case emits code like this on x86-64:

  ucomisd %xmm0, %xmm0 ; set parity flag if x is NAN
  setp    %dl          ; copy parity flag to %edx
  ucomisd %xmm1, %xmm1 ; set parity flag if y is NAN
  setp    %al          ; copy parity flag to %eax
  orl     %edx, %eax   ; OR one byte of each result into a full-width register

This is suboptimal because ucomisd already has the effect of checking if
*either* of its operands is NAN, so this code is equivalent:

  xorl    %eax, %eax
  ucomisd %xmm1, %xmm0
  setp    %al

And indeed that's what you get if you help GCC along by calling isunordered(x,
y) instead.  But no one thinks to do that, because isnan() is much more widely
used and it isn't an obvious thing at the source level to change pairs of
isnan() calls to isunordered().  So the optimizer should do it.

Someone already suggested that in GCC 5 it might be as simple as this (which
seems correct and safe to me):

  (simplify (or (unordered @0 @0) (unordered @1 @1)) (unordered @0 @1))

A discussion of this issue is here:
http://stackoverflow.com/questions/26053934/is-it-feasible-to-add-this-optimization-to-gcc


             reply	other threads:[~2014-09-27  3:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-27  3:11 jzwinck at gmail dot com [this message]
2014-09-27  6:35 ` [Bug other/63387] " glisse at gcc dot gnu.org
2014-09-29 10:52 ` rguenth at gcc dot gnu.org
2014-10-10  8:39 ` glisse at gcc dot gnu.org
2015-04-13 13:32 ` burnus at gcc dot gnu.org
2015-04-13 17:26 ` joseph at codesourcery dot com
2015-04-14  8:49 ` glisse at gcc dot gnu.org
2015-04-14  9:15 ` 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-63387-4@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).