[llvm] [InstCombine] Div ceil optimizations (PR #190175)

Takashi Idobe via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 5 13:19:38 PDT 2026


================
@@ -1523,6 +1523,68 @@ static Instruction *foldBoxMultiply(BinaryOperator &I) {
   return nullptr;
 }
 
+// Return true if X + (Y-1) is provably non-wrapping in X's type
+static bool checkDivCeilNUW(Value *X, Value *Y, BinaryOperator &I,
----------------
Takashiidobe wrote:

X + Y / Y is fine but it is conservative by one value (the X + Y - 1 where X + Y would wrap) case. Is my logic wrong here where X + Y - 1 is too loose and it would be better as X + Y / Y?

I would also prefer the helper, how would I say X + Y - 1 doesn't overflow unsigned with `willNotOverflowUnsignedAdd`?

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


More information about the llvm-commits mailing list