llvm / llvm/llvm-project

Miscompilation in float select transformation

Open
#177,541 1 comment 0 reactions 0 assignees View on GitHub
floating-point llvm:instcombine miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.