[Bug rtl-optimization/126521] New: Wrong RTL ifcvt with abs

"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=126521

            Bug ID: 126521
           Summary: Wrong RTL ifcvt with abs
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

__attribute__((noipa)) double
g (double a)
{
  double x;
  if (a < 0.0)
    x = a;
  else
    x = -a;
  return x;
}

static unsigned long long
bits (double d)
{
  unsigned long long u;
  __builtin_memcpy (&u, &d, 8);
  return u;
}

static double
from_bits (unsigned long long u)
{
  double d;
  __builtin_memcpy (&d, &u, 8);
  return d;
}

int
main (void)
{
  double mnan = from_bits (0xfff8000000000000ULL);  /* -NaN */
  double pnan = from_bits (0x7ff8000000000000ULL);  /* +NaN */

  /* a < 0.0 is false for either NaN, so both take the else arm and the
     result is the operand with its sign bit flipped.  */
  if (bits (g (mnan)) != 0x7ff8000000000000ULL)
    __builtin_abort ();
  if (bits (g (pnan)) != 0xfff8000000000000ULL)
    __builtin_abort ();

  /* Ordinary values must still work.  */
  if (g (-2.0) != -2.0 || g (3.0) != -3.0)
    __builtin_abort ();

  return 0;
}

aborts on aarch64 with -O2  -fno-signed-zeros -fno-ssa-phiopt but passes at -O0
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.