[llvm] [LV] Add extra check for signed oveflow for SDiv/SRem (PR #170818)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 8 00:00:06 PST 2025
================
@@ -2878,11 +2878,22 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {
TheLoop->isLoopInvariant(cast<StoreInst>(I)->getValueOperand()));
}
case Instruction::UDiv:
- case Instruction::SDiv:
- case Instruction::SRem:
case Instruction::URem:
// If the divisor is loop-invariant no predication is needed.
return !Legal->isInvariant(I->getOperand(1));
+ case Instruction::SDiv:
+ case Instruction::SRem: {
+ auto *LHS = I->getOperand(0);
+ auto *RHS = I->getOperand(1);
+ // If RHS is loop-invariant, signed-division overflow is possible
+ // when LHS can be INT_MIN.
+ ScalarEvolution &SE = *PSE.getSE();
+ IntegerType *LHSTy = dyn_cast<IntegerType>(LHS->getType());
+ llvm::ConstantRange LHSRange = SE.getSignedRange(SE.getSCEV(LHS));
----------------
lukel97 wrote:
Can this be simplified to `SE.getSignedRangeMin(SE.getSCEV(LHS)).isMinSignedValue()`?
https://github.com/llvm/llvm-project/pull/170818
More information about the llvm-commits
mailing list