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)