[llvm] [InstCombine] Treat sdiv as udiv in foldICmpDivConstant when both operands are non-negative (PR #188731)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 22:06:11 PDT 2026
lijinpei-amd wrote:
> Why isn't the sdiv being converted to udiv by this code in InstCombineMulDivRem.cpp
>
> ```
> if (KnownDividend.isNonNegative()) {
> // If both operands are unsigned, turn this into a udiv.
> if (isKnownNonNegative(Op1, SQ.getWithInstruction(&I))) {
> auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.getName());
> BO->setIsExact(I.isExact());
> return BO;
> }
> ```
Op0 needs to be known to be positive for this opt to take effect, however, there is a 15 instr distance limit when scanning for assume. https://github.com/llvm/llvm-project/blob/2c0a67d6d77c9be3184bfa1a658a9fdb861adaa1/llvm/lib/Analysis/ValueTracking.cpp#L687
https://github.com/llvm/llvm-project/pull/188731
More information about the llvm-commits
mailing list