[llvm] [InstCombine] Fold icmp in select to smin (PR #196823)
Yunbo Ni via llvm-commits
llvm-commits at lists.llvm.org
Sun May 10 11:45:59 PDT 2026
================
----------------
cardigan1008 wrote:
Here is a related miscompilation case: https://alive2.llvm.org/ce/z/--akxj
The patch only checks `isKnownNonNegative(Mask, SQ)`. That precondition is sufficient for the constant arm 0: when `%inl` is nonnegative, `%inl | Mask` is nonnegative, so `smin(%or, 0)` equals 0. However, it is insufficient for the constant arm 1: equivalence requires `%inl | Mask >= 1` whenever the constant arm is selected. The current code does not prove that. A known-nonnegative mask may still be zero, and `%inl` may also be zero on the nonnegative side of the comparison, so `%or` may be 0.
The weakness is not limited to this scalar case. The same issue appears for vector lanes, and a separate Alive2 test showed that or disjoint can introduce another unsoundness by making a poison-generating OR unconditionally used by smin even when the original select chose the constant arm. The minimal concrete defined-value bug above is sufficient to demonstrate that the fix is over-broad for `ConstVal == 1`.
For other similar bugs and more detailed analysis, please refer https://archer.top/artifact/run/196823/run.review.md
> Found with [Archer](https://archer.top/). Please let me know if anything is wrong.
https://github.com/llvm/llvm-project/pull/196823
More information about the llvm-commits
mailing list