| Issue |
234713
|
| Summary |
[InstCombine] Miscompilation where a float class test of a negation ignores nsz on a negation with other uses
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
sairam2661
|
**Fuzzer Generated Test**
**Reproducer**
https://alive2.llvm.org/ce/z/qQLhHG
**Test Commit**
[e633c7da8ff144a11b3d875956fbaea06b969070](https://github.com/llvm/llvm-project/commit/e633c7da8ff144a11b3d875956fbaea06b969070)
**Description**
InstCombine (`foldIntrinsicIsFPClass`) already tests `%x` against the negated mask.
But it does not test`fneg` properly, where an `fneg nsz` of `+0.0` may return `+0.0`, and when that `fneg` also has another use (here a store) the target can store `+0.0` and still report `-0.0`.
**Steps to reproduce**
- Minimized test case (src), `input.ll`
```llvm
define i1 @f(float %x, ptr %ptr) {
%n = fneg nsz float %x
store float %n, ptr %ptr
%c = call i1 @llvm.is.fpclass.f32(float %n, i32 32)
ret i1 %c
}
```
- InstCombine output (tgt), `output.ll`
```llvm
define i1 @f(float %x, ptr %ptr) {
%n = fneg nsz float %x
store float %n, ptr %ptr, align 4
%c = call i1 @llvm.is.fpclass.f32(float %x, /* (pzero) */ i32 64)
ret i1 %c
}
declare i1 @llvm.is.fpclass.f32(float, i32 immarg)
```
**Output**
```txt
define i1 @f(float %x, ptr %ptr) {
#0:
%n = fneg nsz float %x
store float %n, ptr %ptr, align 4
%c = is.fpclass float %n, i32 32
ret i1 %c
}
=>
define i1 @f(float %x, ptr %ptr) {
#0:
%n = fneg nsz float %x
store float %n, ptr %ptr, align 4
%c = is.fpclass float %x, i32 64
ret i1 %c
}
Transformation doesn't verify!
ERROR: Mismatch in memory
Example:
float %x = #x00000000 (+0.0)
ptr %ptr = pointer(non-local, block_id=1, offset=0) / Address=#x04
Source:
float %n = #x80000000 (-0.0)
i1 %c = #x1 (1)
SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 4 alloc type: 0 alive: false address: #x00
Block 1 > size: 8 align: 4 alloc type: 4 alive: true address: #x04
Target:
float %n = #x00000000 (+0.0)
i1 %c = #x1 (1)
TARGET MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 > size: 0 align: 4 alloc type: 0 alive: false address: #x00
Block 1 > size: 8 align: 4 alloc type: 4 alive: true address: #x04
Mismatch in pointer(non-local, block_id=1, offset=0)
Source value: #x80000000
Target value: #x00000000
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