[llvm] [LV] Use SCEV to check if minimum iteration check is known. (PR #111310)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 14:03:05 PDT 2024
================
@@ -2438,12 +2438,29 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
};
TailFoldingStyle Style = Cost->getTailFoldingStyle();
- if (Style == TailFoldingStyle::None)
- CheckMinIters =
- Builder.CreateICmp(P, Count, CreateStep(), "min.iters.check");
- else if (VF.isScalable() &&
- !isIndvarOverflowCheckKnownFalse(Cost, VF, UF) &&
- Style != TailFoldingStyle::DataAndControlFlowWithoutRuntimeCheck) {
+ if (Style == TailFoldingStyle::None) {
+ Value *Step = CreateStep();
+ ScalarEvolution &SE = *PSE.getSE();
+ // TODO: Emit unconditional branch to vector preheader instead of
+ // conditional branch with known condition.
+ const SCEV *TripCountSCEV = SE.applyLoopGuards(SE.getSCEV(Count), OrigLoop);
+ // Check if the trip count is < the step.
+ if (SE.isKnownPredicate(P, TripCountSCEV, SE.getSCEV(Step))) {
+ // TODO: Ensure step is at most the trip count when determining max VF and
+ // UF, w/o tail folding.
+ CheckMinIters = Builder.getTrue();
+ } else if (!SE.isKnownPredicate(CmpInst::getInversePredicate(P),
+ TripCountSCEV, SE.getSCEV(Step))) {
+ // Generate the minimum iteration check only if we cannot prove the
+ // check is known to be true, or known to be false
+ CheckMinIters = Builder.CreateICmp(P, Count, Step, "min.iters.check");
+
+ // else step is known to be smaller than trip count, use CheckMinIters
+ // preset to false.
+ }
----------------
fhahn wrote:
adjusted, thanks!
https://github.com/llvm/llvm-project/pull/111310
More information about the llvm-commits
mailing list