[Bug tree-optimization/126473] New: Wrong fold of signbit(x) -> x<0 for NaNs

"ktkachov at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.