[llvm] [InstCombine] Fold (X - X%C) u>= C to X u>= C (PR #214381)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 8 11:54:33 PDT 2026


================
@@ -3024,6 +3024,15 @@ Instruction *InstCombinerImpl::foldICmpSubConstant(ICmpInst &Cmp,
   ICmpInst::Predicate Pred = Cmp.getPredicate();
   Type *Ty = Sub->getType();
 
+  // D: (X - (X urem D)) is D*(X/D), a multiple of D, so it is >= D exactly when
+  // X >= D.
+  //   (icmp ugt (sub X, (urem X, D)), D-1) --> (icmp ugt X, D-1)
----------------
dtcxzyw wrote:

It should work for any C in `[0, D - 1)`: https://alive2.llvm.org/ce/z/_sUmC2


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


More information about the llvm-commits mailing list