[Bug tree-optimization/126461] New: [13/14/15/16/17 Regression] Wrong fold of -fma (a, b, c) to fnms (a, b, c) when signed zeros are important

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

            Bug ID: 126461
           Summary: [13/14/15/16/17 Regression] Wrong fold of -fma (a, b,
                    c) to fnms (a, b, c) when signed zeros are important
           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)) double
neg_fma (double a, double b, double c)
{
  return -__builtin_fma (a, b, c);
}

__attribute__((noipa)) double
neg_fms (double a, double b, double c)
{
  return -__builtin_fma (a, b, -c);
}

int
main (void)
{
  if (!__builtin_signbit (neg_fma (1.0, 1.0, -1.0)))
    __builtin_abort ();
  if (!__builtin_signbit (neg_fms (2.0, 3.0, 6.0)))
    __builtin_abort ();
  return 0;
}

aborts with GCC and passes with Clang at -O2.
IMO the folds should happen only when !HONOR_SIGNED_ZEROS.
GCC 8 technically got this right (the testcase doesn't abort there)
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.