[llvm] [LV] Use SCEV to check if IV overflow check is known (PR #115705)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 11 14:50:48 PST 2024
================
@@ -2491,17 +2491,19 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
Value *LHS = Builder.CreateSub(MaxUIntTripCount, Count);
Value *Step = CreateStep();
-#ifndef NDEBUG
ScalarEvolution &SE = *PSE.getSE();
const SCEV *TC2OverflowSCEV = SE.applyLoopGuards(SE.getSCEV(LHS), OrigLoop);
- assert(
- !isIndvarOverflowCheckKnownFalse(Cost, VF * UF) &&
- !SE.isKnownPredicate(CmpInst::getInversePredicate(ICmpInst::ICMP_ULT),
- TC2OverflowSCEV, SE.getSCEV(Step)) &&
- "unexpectedly proved overflow check to be known");
-#endif
- // Don't execute the vector loop if (UMax - n) < (VF * UF).
- CheckMinIters = Builder.CreateICmp(ICmpInst::ICMP_ULT, LHS, Step);
+ const SCEV *StepSCEV = SE.getSCEV(Step);
+
+ // Check if (UMax - n) < (VF * UF).
+ if (SE.isKnownPredicate(ICmpInst::ICMP_ULT, TC2OverflowSCEV, StepSCEV)) {
----------------
fhahn wrote:
This is an interesting case. For the loop in the test case, the induction can overflow if `%tc == 0` I think, so `isIndvarOverflowCheckKnownFalse` should return false in general?
I think `getSmallConstantMaxTripCount` already should make use of loop guards in this case, but we cannot compute a tighter maximum because `%tc` may be 0, in which case we would wrap.
https://github.com/llvm/llvm-project/pull/115705
More information about the llvm-commits
mailing list