[llvm] [llvm] [InstCombine] fold "icmp eq (X + (V - 1)) & -V, X" to "icmp eq (and X, V - 1), 0" (PR #152851)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 13 12:58:06 PDT 2025
================
@@ -1320,6 +1320,40 @@ 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::foldIsMultipleOfAPowerOfTwo(ICmpInst &Cmp) {
+ Value *Neg, *Num, *Mask;
+ CmpPredicate Pred;
+ const APInt *NegConst, *MaskConst;
+
+ if (!match(&Cmp, m_c_ICmp(Pred, m_Value(Num),
+ m_OneUse(m_c_And(m_OneUse(m_c_Add(m_Deferred(Num),
+ m_Value(Mask))),
----------------
nikic wrote:
Oh right, we can't use m_SpecificInt with a value captured in the same match.
https://github.com/llvm/llvm-project/pull/152851
More information about the llvm-commits
mailing list