[llvm] [InstCombine]: Eliminate redundant modulus for urem (PR #157644)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 08:09:35 PDT 2025
================
@@ -2473,6 +2473,16 @@ Instruction *InstCombinerImpl::visitURem(BinaryOperator &I) {
}
}
+ Value *A;
+ const APInt *Op1Cst, *BCst;
+ // urem(urem(A, BCst), Op1Cst) -> urem(A, Op1Cst)
+ // iff urem(BCst, Op1Cst) == 0
+ if (match(Op0, m_URem(m_Value(A), m_APInt(BCst))) &&
----------------
nikic wrote:
Looks like we need a one-use check on the inner urem. Otherwise we often end up breaking up div+rem patterns, and also performing the urem on a wider type.
https://github.com/llvm/llvm-project/pull/157644
More information about the llvm-commits
mailing list