[llvm] [InstCombine] Add fold `(x * z) % (y * z) == 0` -> `x % y == 0` (PR #171655)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 23 05:37:57 PST 2025
================
@@ -2735,6 +2735,61 @@ Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
return new ICmpInst(ICmpInst::ICMP_UGT, And, ConstantInt::get(Ty, SignMask));
}
+/// Fold icmp {eq, ne} ({us}rem (mul n{us}w XZ, YZ)), 0 ->
+/// icmp {eq, ne} ({us}rem (mul n{us}w X, Y)), 0
+Instruction *InstCombinerImpl::foldICmpRemConstant(ICmpInst &Cmp,
+ BinaryOperator *Rem,
+ const APInt &C) {
+ assert((Rem->getOpcode() == Instruction::SRem ||
+ Rem->getOpcode() == Instruction::URem) &&
+ "foldICmpRemConstant is only for srem/urem.");
+
+ if (!C.isZero() || !Rem->hasOneUse())
+ return nullptr;
+
+ const ICmpInst::Predicate Pred = Cmp.getPredicate();
+ if (Pred != ICmpInst::ICMP_EQ && Pred != ICmpInst::ICMP_NE)
----------------
nikic wrote:
Use `Cmp.isEquality()` instead.
https://github.com/llvm/llvm-project/pull/171655
More information about the llvm-commits
mailing list