[llvm] [InstCombine] Fold `ceil(X / (2 ^ C)) == 0` -> `X == 0` (PR #143683)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 13 23:28:40 PDT 2025
================
@@ -1298,6 +1298,21 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
// eq/ne (mul X, Y)) with (icmp eq/ne X/Y) and if X/Y is known non-zero that
// will fold to a constant elsewhere.
}
+
+ // icmp eq/ne ((X >> C) | (X & mask(C) != 0)), 0 -> icmp eq/ne X, 0
+ if (ICmpInst::isEquality(Pred)) {
+ Value *X;
+ const APInt *C1, *C2;
+ if (match(Cmp.getOperand(0),
+ m_OneUse(m_c_Or(
----------------
dtcxzyw wrote:
The one-use check is unnecessary. BTW, if the NUW add is used in other places, it will not be converted into `X | Y ==/!= 0`. Please make sure your PR addresses the original issue.
https://github.com/llvm/llvm-project/pull/143683
More information about the llvm-commits
mailing list