[llvm] [InstCombine] Fold udiv by constant into icmp and add when maximum quotient is small (PR #209321)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 11:17:13 PDT 2026


AZero13 wrote:

> > If I'm reading this right, this is an extension of the existing CVP transform at
> > https://github.com/llvm/llvm-project/blob/cf7e84e3f48a58f97af0abce7fd24fdb4b1f5797/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp#L822
> > 
> > for the MaxQ==2 case? Should we extend that transform instead of adding it to InstCombine as well?
> 
> CVP's expandUDivOrURem works even when the divisor is a variable, as long as its range bounds the dividend (e.g. X < 3Y). The InstCombine patch is strictly limited to constant divisors.

Also, this operation is best done in instcombine where we can merge with other optimizations and also, doing this before loop vectorization would be nice too.

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


More information about the llvm-commits mailing list