| Issue |
233564
|
| Summary |
Remove `fabs` when the sign of NaN cannot be observed.
|
| Labels |
llvm:instcombine,
missed-optimization,
floating-point
|
| Assignees |
|
| Reporter |
ZERICO2005
|
```c
bool src(float x) {
float square_x = x * x;
float fabs_square_x = fabsf(square_x);
return fabs_square_x < 1.0f;
}
```
`square_x` may have a negative signbit if `x` is NaN. However, `fcmp` does not observe the signbit of NaN, so we can omit the `fabsf` here. Currently, `fabsf` is only omitted if `square_x` is proven to not be NaN.
GCC appears to perform this fold already, but that is because it assumes that `signbit(x * x)` is always false, even for `NaN`. This is invalid under LLVM's LangRef semantics.
Godbolt: https://godbolt.org/z/a3qxzhh8o
Alive2: https://alive2.llvm.org/ce/z/wZNjeo
TODO:
- If `x` is positive or NaN, we can remove a call to `fabs` if we can prove that the signbit of NaN does not matter.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs