[llvm] [InstCombine] Fix miscompilation for `select` + `FCmp` (PR #177872)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 21 04:53:56 PST 2026


dtcxzyw wrote:

Intersecting flags still doesn't work for a slightly modified reproducer: https://alive2.llvm.org/ce/z/gT485h
```

----------------------------------------
define float @src(float noundef %x) {
entry:
  %a = fcmp nnan ninf ult float noundef %x, 255.000000
  %b = select i1 %a, float 255.000000, float noundef %x
  %c = fcmp nnan ugt float noundef %x, 512.000000
  %r = select ninf i1 %c, float 512.000000, float %b
  ret float %r
}
=>
define float @tgt(float noundef %x) {
entry:
  %a.inv = fcmp nnan ninf oge float noundef %x, 255.000000
  %b = select nnan ninf i1 %a.inv, float noundef %x, float 255.000000
  %.inv = fcmp ole float %b, 512.000000
  %r = select i1 %.inv, float %b, float 512.000000
  ret float %r
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

NOTE: The counterexample is unique.

Example:
float noundef %x = #x7f800000 (+oo)

Source:
i1 %a = poison
float %b = poison
i1 %c = #x1 (1)
float %r = #x44000000 (512)

Target:
i1 %a.inv = poison
float %b = poison
i1 %.inv = poison
float %r = poison
Source value: #x44000000 (512)
Target value: poison
```



https://github.com/llvm/llvm-project/pull/177872


More information about the llvm-commits mailing list