[llvm] [InstCombine] fold icmp of select with constants and invertible op (PR #147182)
Acthinks Yang via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 10 19:59:44 PDT 2025
Acthinks wrote:
> We can simply extend `foldICmpEqualityWithOffset` to handle the motivating case.
It seems that we cannot simply extend foldICmpEqualityWithOffset to handle shift operations and bit operations that require Op1 and Op2 to satisfy certain properties at the same time. For example, Shl nsw/nuw, AShr exact. The proof is given below:
https://alive2.llvm.org/ce/z/m9daRe
```
define i1 @src_shl_nsw_eq(i8 %a, i1 %cond) {
%a_shl = shl nsw i8 %a, 3
%sel = select i1 %cond, i8 4, i8 16
%cmp = icmp eq i8 %a_shl, %sel
ret i1 %cmp
}
define i1 @tgt_shl_nsw_eq(i8 %a, i1 %cond) {
%1 = select i1 %cond, i8 0, i8 2
%cmp = icmp eq i8 %a, %1
ret i1 %cmp
}
```
https://github.com/llvm/llvm-project/pull/147182
More information about the llvm-commits
mailing list