https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117235
Bug ID: 117235
Summary: [15 Regression] trapping fp statement can be moved
across another trapping fp statement
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: major
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int f(int a, float b, float c, float d, int x, int y)
{
float e;
float t;
if (a)
{
e = x;
t = c/d;
} else
{
e = y;
t = d/c;
}
return e + t;
}
```
At `-O2 -ftrapping-math`, the conversion from int to fp can moved after the
division.
Noticed while working on improving phiopt.
This was introduced by r15-4503-g8d6d6d537fdc75 .
The simple fix is is_factor_profitable should return false if the statement can
trap and is not the last statement.
Though the more complex one is not check aliveness and then return false if
another statement can trap but I don't think that will be that profitable
really.