[llvm] [llvm] [InstCombine] fold "icmp eq (X + (V - 1)) & -V, X" to "icmp eq 0, (and X, V - 1)" (PR #152851)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 10 01:20:09 PDT 2025
================
@@ -1320,6 +1320,76 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
return nullptr;
}
+// Fold icmp eq (num + (val - 1)) & -val, num
+// to
+// icmp eq 0, (and num, val - 1)
+// For value being power of two
+Instruction *InstCombinerImpl::foldNextMultiply(ICmpInst &Cmp) {
+ Value *Op0 = Cmp.getOperand(0), *Op1 = Cmp.getOperand(1);
+ Value *Neg, *Add, *Num, *Mask, *Value;
+ CmpInst::Predicate Pred = Cmp.getPredicate();
+ const APInt *NegConst, *MaskConst, *NumCost;
+
+ if (!ICmpInst::isEquality(Pred))
+ return nullptr;
+
+ // Match num + neg
+ if (!match(Op0, m_c_And(m_Value(Add), m_Value(Neg))))
----------------
dtcxzyw wrote:
We need some one-use checks. Can you add some multi-use tests as suggested in https://llvm.org/docs/InstCombineContributorGuide.html#add-multi-use-tests and https://llvm.org/docs/InstCombineContributorGuide.html#multi-use-handling?
https://github.com/llvm/llvm-project/pull/152851
More information about the llvm-commits
mailing list