| Issue |
233580
|
| Summary |
[InstCombine] Remove `fabs` when the sign of zero cannot be observed.
|
| Labels |
llvm:instcombine,
missed-optimization,
floating-point
|
| Assignees |
|
| Reporter |
ZERICO2005
|
Godbolt: https://godbolt.org/z/W6dYaMP5e
Alive2: (using `half`/`f16`) https://alive2.llvm.org/ce/z/k82xMh
Some operations, such as `fcmp`, `fadd %x, non-zero` (ignoring input denormal flushing), and `fptosi` treat a zero of either sign identically. If the result of `sqrt` is not NaN, then the value will either be positive, `+0.0`, or `-0.0`, so `fabs` would only apply to `-0.0` here.
```c
bool src_1(float x, float y) {
if (!(x >= 0.0f)) __builtin_unreachable();
if (!(y >= 0.0f)) __builtin_unreachable();
return fabsf(sqrtf(x)) == fabsf(sqrtf(y));
}
float src_2(float x) {
if (!(x >= 0.0f)) __builtin_unreachable();
return fabsf(sqrtf(x)) + 1.0f;
}
int src_3(float x) {
if (!(x >= 0.0f)) __builtin_unreachable();
return (int)fabsf(sqrtf(x));
}
```
Considerations:
- How would this interact with operations marked as `nsz`?
See also:
- https://github.com/llvm/llvm-project/issues/233564
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs