https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129304

            Bug ID: 129304
           Summary: [15/16/17 Regression] wrong code at -O1 -ffast-math:
                    match.pd powi/ldexp folds compute the new int exponent
                    with signed overflow (powi (4.0, -2^30-1) becomes
                    +Inf)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 0599jiangyc at gmail dot com
  Target Milestone: ---

The following code:

```c
__attribute__((noipa)) double
f (int i)
{
  return __builtin_powi (4.0, i);
}

int
main (void)
{
  double a = f (-(1 << 30) - 1);
  __builtin_printf ("%g\n", a);
  return a != 0.0;
}
```

Resulted in this output:
```
$ gcc -O2 repro.c && ./a.out
0
$ gcc -O2 -ffast-math repro.c && ./a.out
inf
(also -O1 -ffast-math, and -O0 -ffast-math since the fold also runs there; -O2
without -ffast-math prints 0)
```

Trunk: https://godbolt.org/z/j7cKhz49Y
- Trunk and GCC 15.1 print inf; GCC 14.2 and older print 0.

Reply via email to