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
  • [Bug tree-optimization/103683]... tkoenig at gcc dot gnu.org via Gcc-bugs

Reply via email to