public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103683] New: Redundant !__builtin_isnan not removed with -fno-signaling-nans
@ 2021-12-13 12:51 tkoenig at gcc dot gnu.org
  2021-12-14  0:05 ` [Bug tree-optimization/103683] " joseph at codesourcery dot com
  0 siblings, 1 reply; 2+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2021-12-13 12:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103683
           Summary: Redundant !__builtin_isnan not removed with
                    -fno-signaling-nans
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkoenig at gcc dot gnu.org
  Target Milestone: ---

If x is a NaN, then x > 1 will fail, so the __builtin_isnan function
could be removed in comparisons like (!__builtin_isnan (x)) && x > 1
lwhen -fno-signaling-nans is in effect.

Test case:

#include <math.h>
#include <stdio.h>

_Bool foo (double x)
{
  return (!__builtin_isnan (x)) && x > 1;
}

_Bool bar (double x)
{
  return x > 1;
}

void chk(double x)
{
  printf ("%f %x %x\n", x, foo(x), bar(x));
}
int main()
{
  chk(-1.0);
  chk(1.0);
  chk(2.9);
  chk(NAN);
  return 0;
}

With "gcc -fno-signaling-nans -S -O3 nan.c", one gets for foo

foo:
        .seh_endprologue
        ucomisd %xmm0, %xmm0
        jp      .L3
        comisd  .LC0(%rip), %xmm0
        seta    %al
        ret

and for bar

bar:
        .seh_endprologue
        comisd  .LC0(%rip), %xmm0
        seta    %al
        ret
        .seh_endproc

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

* [Bug tree-optimization/103683] Redundant !__builtin_isnan not removed with -fno-signaling-nans
  2021-12-13 12:51 [Bug tree-optimization/103683] New: Redundant !__builtin_isnan not removed with -fno-signaling-nans tkoenig at gcc dot gnu.org
@ 2021-12-14  0:05 ` joseph at codesourcery dot com
  0 siblings, 0 replies; 2+ messages in thread
From: joseph at codesourcery dot com @ 2021-12-14  0:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
(x > 1) is expected to raise invalid for a quiet NaN, so the two functions 
are different in the absence of -fno-trapping-math, whether or not 
signaling NaNs are enabled.

((!__builtin_isnan (x)) && x > 1) is equivalent to __builtin_isgreater (x, 
1.0) and could be optimized accordingly for -fno-signaling-nans, however.  
(With signaling NaNs, you have the issue that the first expression doesn't 
raise invalid for a signaling NaN but the second does.)

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

end of thread, other threads:[~2021-12-14  0:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 12:51 [Bug tree-optimization/103683] New: Redundant !__builtin_isnan not removed with -fno-signaling-nans tkoenig at gcc dot gnu.org
2021-12-14  0:05 ` [Bug tree-optimization/103683] " joseph at codesourcery dot com

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