[llvm] [InstCombine]: Eliminate redundant modulus for urem (PR #157644)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 9 05:46:40 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)))) {
----------------
nikic wrote:

> 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.

The motivating case is on constants, let's use this option.

https://github.com/llvm/llvm-project/pull/157644


More information about the llvm-commits mailing list