| Issue |
234369
|
| Summary |
[InstSimplify] `fabs(...)` of known non-negative values are folded to the `select`/`phi`, which may return -0.0
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
sairam2661
|
**Fuzzer Generated Test**
**Reproducer**
https://alive2.llvm.org/ce/z/zMoEMz
**Test Commit**
[e633c7da8ff144a11b3d875956fbaea06b969070](https://github.com/llvm/llvm-project/commit/e633c7da8ff144a11b3d875956fbaea06b969070)
**Description**
`simplifyUnaryIntrinsic` drops `fabs` of a `select`/`phi` of non-negative values, but `nsz` on the `select`/`phi` lets it return -0.0: for `x = y = +0.0`, the target returns -0.0. This is the same root cause as #151303 and #185920 but the open fixes (#186315, #207623) do not cover `select`/`phi`.
**Steps to reproduce**
- Minimized test case, `input.ll`
```llvm
define float @f(float nofpclass(nan ninf nzero nsub nnorm) %x, float nofpclass(nan ninf nzero nsub nnorm) %y, i1 %c) {
%v = select nsz i1 %c, float %x, float %y
%r = call float @llvm.fabs.f32(float %v)
ret float %r
}
```
**Output**
```llvm
----------------------------------------
define float @f(float nofpclass(63) %x, float nofpclass(63) %y, i1 %c) {
#0:
%v = select nsz i1 %c, float nofpclass(63) %x, float nofpclass(63) %y
%r = fabs float %v
ret float %r
}
=>
define float @f(float nofpclass(63) %x, float nofpclass(63) %y, i1 %c) {
#0:
%v = select nsz i1 %c, float nofpclass(63) %x, float nofpclass(63) %y
ret float %v
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
float nofpclass(63) %x = #x00000000 (+0.0)
float nofpclass(63) %y = #x00000000 (+0.0)
i1 %c = #x0 (0)
Source:
float %v = #x00000000 (+0.0)
float %r = #x00000000 (+0.0)
Target:
float %v = #x80000000 (-0.0)
Source value: #x00000000 (+0.0)
Target value: #x80000000 (-0.0)
Summary:
0 correct transformations
1 incorrect transformations
0 failed-to-prove transformations
0 Alive2 errors
```
**CC**: @regehr
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs