Issue 234426
Summary [InstSimplify] Miscompilation where copysign with a negated sign operand is folded
Labels new issue
Assignees
Reporter sairam2661
    **Fuzzer Generated Test**

**Reproducer**
https://alive2.llvm.org/ce/z/G5ZjoH

**Test Commit**
[e633c7da8ff144a11b3d875956fbaea06b969070](https://github.com/llvm/llvm-project/commit/e633c7da8ff144a11b3d875956fbaea06b969070)

**Description**
`simplifyBinaryIntrinsic` folds `copysign(%x, fsub -0.0, %x)` to the `fsub` as if it were `fneg %x`, but `fsub` may quiet a NaN: for a signaling NaN `%x`, the target may return a quiet NaN.

**Steps to reproduce**
- Minimized test case (src), `input.ll`

```llvm
define half @f(half %x) {
  %negx = fsub half -0.0, %x
  %r = call half @llvm.copysign.f16(half %x, half %negx)
  ret half %r
}

declare half @llvm.copysign.f16(half, half)
```

- InstSimplify output (tgt), `output.ll`

```llvm
define half @f(half %x) {
  %negx = fsub half -0.000000e+00, %x
  ret half %negx
}

declare half @llvm.copysign.f16(half, half)
```

**Output**

```
define half @f(half %x) {
#0:
  %negx = fsub half 0x8000, %x
  %r = copysign half %x, %negx
 ret half %r
}
=>
define half @f(half %x) {
#0:
  %negx = fsub half 0x8000, %x
  ret half %negx
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
half %x = #xfc02 (SNaN)

Source:
half %negx = #xfe00 (QNaN)
half %r = #xfc02 (SNaN)

Target:
half %negx = #xfe02 (QNaN)
Source value: #xfc02 (SNaN)
Target value: #xfe02 (QNaN)

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

Reply via email to