[llvm] Fold (a % b) lt/ge (b-1) where b is a power of 2 (PR #72504)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 19 01:25:45 PST 2023


================
@@ -6837,6 +6837,25 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
     Changed = true;
   }
 
+  {
+    Value *X, *Y;
+    const APInt *C;
+    ICmpInst::Predicate Pred = I.getPredicate();
+    if ((Pred == ICmpInst::ICMP_SGE || Pred == ICmpInst::ICMP_SLT) &&
+        match(Op0, m_OneUse(m_SRem(m_Value(X), m_Value(Y)))) &&
+        ((match(Op1, m_OneUse(m_c_Add(m_Deferred(Y), m_AllOnes()))) &&
----------------
dtcxzyw wrote:

Could you please also handle negative divisors as @nikic suggested?
https://alive2.llvm.org/ce/z/AJq3Ch


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


More information about the llvm-commits mailing list