[llvm] [InstCombine] Fix flag propagation in `foldSelectIntoOp` (PR #162003)
Yunbo Ni via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 27 04:21:38 PST 2025
cardigan1008 wrote:
@dtcxzyw There seems to be an uncovered edge case for `fdiv` in this fix.
The current logic assumes that if a `select` has both `ninf` and `nnan`, then the operands of the folded operation must be finite. While this assumption holds for `fadd`, `fsub`, and `fmul`, it does not hold for `fdiv`.
For example:
```
A = 1.0, B = +Inf
A / B = 0.0 (finite, non-NaN)
```
In the original IR, a `select ninf nnan` returning this result is valid. However, after the transformation, InstCombine produces: A / (select ninf nnan cond, B, 1.0)
If `cond` is true, the inner `select` returns `B = +Inf`, and due to the propagated `ninf`, this becomes poison. This introduces poison that was not present in the original program.
alive2: https://alive2.llvm.org/ce/z/e7be8f
https://github.com/llvm/llvm-project/pull/162003
More information about the llvm-commits
mailing list