[llvm] [InstCombine]: Eliminate redundant modulus for urem (PR #157644)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 05:40:53 PDT 2025
================
@@ -2473,6 +2473,14 @@ Instruction *InstCombinerImpl::visitURem(BinaryOperator &I) {
}
}
+ Value *A;
+ Value *B;
+ // urem(urem(A, B), Op1) -> urem(A, Op1)
+ if (match(Op0, m_URem(m_Value(A), m_Value(B)))) {
----------------
RKSimon wrote:
We use the assume to tell alive2 a known constraint on the values of mod0 and mod1.
For the InstCombine fold we need to prove the constraint is correct so we can perform the fold.
We can either limit this to cases where Op1 and B are both scalar integer constants, in which case we just need to check that BCst.urem(Op1Cst) == 0.
Or we can try to be fancy, and use knownbits to prove more general cases:
```
KnownBits KnownB = computeKnownBits(B);
KnownBits KnownOp1 = computeKnownBits(Op1);
KnownBits::urem(B, Op1).isZero()
```
https://github.com/llvm/llvm-project/pull/157644
More information about the llvm-commits
mailing list