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

            Bug ID: 126473
           Summary: Wrong fold of signbit(x) -> x<0 for NaNs
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

__attribute__((noipa)) int
sb (double x)
{
  return __builtin_signbit (x) != 0;
}

__attribute__((noipa)) double
mknan (void)
{
  return -__builtin_nan ("");
}

int
main (void)
{
  if (sb (mknan ()) != 1)
    __builtin_abort ();
  if (sb (-0.0) != 1)
    __builtin_abort ();
  return 0;
}

aborts with -O1 -fno-signed-zeros.
signbit of a negative NaN is 1, while `x < 0` is false for any NaN because
every ordered comparison with a NaN is false

Reply via email to