https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127544
Bug ID: 127544
Summary: wrong fold of pow (-inf, 0.5) into sqrt with
-fno-math-errno -fno-signed-zeros
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Under the POSIX document, pow(-inf, 0.5) should return +inf.
However, the optimization folds pow into sqrt if y is 0.5, so pow(-inf, 0.5)
returns NaN.
### Reproducer
static uint64_t bits (double d)
{
uint64_t u;
memcpy (&u, &d, sizeof u); /* no strict-aliasing violation */
return u;
}
int main (void)
{
double r_inf = pow (-INFINITY, 0.5);
printf ("pow(-inf,0.5) bits=%016llx\n", (unsigned long long) bits (r_inf));
}
With -O0 -fno-math-errno -fno-signed-zeros, it prints 7ff0000000000000 (+inf
encoding).
However, with -O1/2/3 -fno-math-errno -fno-signed-zeros, it prints
fff8000000000000 (NaN encoding).