public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/63387] New: Optimize pairs of isnan() calls into a single isunordered()
@ 2014-09-27  3:11 jzwinck at gmail dot com
  2014-09-27  6:35 ` [Bug other/63387] " glisse at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jzwinck at gmail dot com @ 2014-09-27  3:11 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-04-14  9:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-27  3:11 [Bug other/63387] New: Optimize pairs of isnan() calls into a single isunordered() jzwinck at gmail dot com
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

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).