Issue 234417
Summary [InstCombine] Miscompilation where a select pulled out of a float operation takes the operation's fast-math flags
Labels new issue
Assignees
Reporter sairam2661
    **Fuzzer Generated Test**

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

**Description**
`SimplifySelectsFeedingBinaryOp` puts the binop's `nsz` on the new `select`: for equal nonzero `%x` and `%y`, 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(i1 %c, half %x, half %y) {
  %a = select i1 %c, half %x, half 0xH7C00
 %b = select i1 %c, half %y, half 0xH7C00
  %r = fsub nsz half %a, %b
  ret half %r
}
```

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

```llvm
define half @f(i1 %c, half %x, half %y) {
  %1 = fsub nsz half %x, %y
  %r = select nsz i1 %c, half %1, half +qnan
  ret half %r
}
```

**Output**

```llvm
define half @f(i1 %c, half %x, half %y) {
#0:
  %a = select i1 %c, half %x, half 0x7c00
  %b = select i1 %c, half %y, half 0x7c00
  %r = fsub nsz half %a, %b
  ret half %r
}
=>
define half @f(i1 %c, half %x, half %y) {
#0:
  %#1 = fsub nsz half %x, %y
  %r = select nsz i1 %c, half %#1, half 0x7e00
  ret half %r
}
Transformation doesn't verify!

ERROR: Value mismatch

Example:
i1 %c = #x1 (1)
half %x = #x0002 (0.000000119209?)
half %y = #x0002 (0.000000119209?)

Source:
half %a = #x0002 (0.000000119209?)
half %b = #x0002 (0.000000119209?)
half %r = #x0000 (+0.0)

Target:
half %#1 = #x0000 (+0.0)
half %r = #x8000 (-0.0)
Source value: #x0000 (+0.0)
Target value: #x8000 (-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

Reply via email to