Issue 177541
Summary Miscompilation in float select transformation
Labels new issue
Assignees
Reporter ariskeirio
    I found a miscompilation in an LLVM IR transformation that rewrites chained `fcmp` + `select` operations. The target IR produces **poison values** in cases where the source code produces well-defined results.

**Example:**

Source IR:

```SQL
define float @src(float %x) {
  %a = fcmp nnan ninf ult float %x, 255.0
  %b = select i1 %a, float 255.0, float %x
  %c = fcmp nnan ugt float %x, 512.0
  %r = select i1 %c, float 512.0, float %b
  ret float %r
}
```

Target IR(optimized from source IR):

https://godbolt.org/z/4YsbM9Y65

```SQL
define float @tgt(float %x) {
  %a.inv = fcmp nnan ninf oge float %x, 2.550000e+02
  %b = select nnan ninf i1 %a.inv, float %x, float 2.550000e+02
  %.inv = fcmp nnan ole float %b, 5.120000e+02
  %r1 = select nnan i1 %.inv, float %b, float 5.120000e+02
  ret float %r1
}
```

Here is the alive2-tv verification

https://alive2.llvm.org/ce/z/CceAMX
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to