| Issue |
234695
|
| Summary |
[InstCombine] Miscompilation where copysign with a negative sign becomes a negation that keeps no-signed-zeros
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
sairam2661
|
**Fuzzer Generated Test**
**Test Commit**
[e633c7da8ff144a11b3d875956fbaea06b969070](https://github.com/llvm/llvm-project/commit/e633c7da8ff144a11b3d875956fbaea06b969070)
**Description**
`visitCallInst` rewrites `copysign nsz (%x, -1.0)` as `fneg (fabs %x)` and copies `nsz` onto the `fneg`: for `%x = +0.0`, the target may return +0.0 where the source returns -0.0.
This appears to be a real issue based on discussion in #180906, #202453.
**Steps to reproduce**
- Minimized test case (src), `input.ll`
```llvm
define half @f(half %x) {
%r = call nsz half @llvm.copysign.f16(half %x, half -1.0)
ret half %r
}
declare half @llvm.copysign.f16(half, half)
```
- InstCombine output (tgt), `output.ll`
```llvm
define half @f(half %x) {
%1 = call nsz half @llvm.fabs.f16(half %x)
%r = fneg nsz half %1
ret half %r
}
declare half @llvm.copysign.f16(half, half)
declare half @llvm.fabs.f16(half)
```
**Output**
```txt
define half @f(half %x) {
#0:
%r = copysign nsz half %x, 0xbc00
ret half %r
}
=>
define half @f(half %x) {
#0:
%#1 = fabs nsz half %x
%r = fneg nsz half %#1
ret half %r
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
half %x = #x0000 (+0.0)
Source:
half %r = #x8000 (-0.0)
Target:
half %#1 = #x0000 (+0.0)
half %r = #x0000 (+0.0)
Source value: #x8000 (-0.0)
Target value: #x0000 (+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