Skip to content

Commit 91a1dff

Browse files
committed
!fixup address latest comments, thanks
1 parent 6907d58 commit 91a1dff

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,9 @@ class InnerLoopVectorizer {
512512

513513
virtual ~InnerLoopVectorizer() = default;
514514

515-
/// Create new basic blocks needed as entries and exits of the code generated
516-
/// by executing a VPlan. For epilogue vectorization, it will create blocks
517-
/// for the minimum iteration checks and IR basic blocks for the vector and
518-
/// scalar preheaders. Otherwise it will create a basic block for the scalar
519-
/// preheader only.
515+
/// Creates a basic block for the scalar preheader. Both
516+
/// EpilogueVectorizerMainLoop and EpilogueVectorizerEpilogueLoop overwrite
517+
/// the method to create blocks and checks needed for epilogue vectorization.
520518
virtual BasicBlock *createVectorizedLoopSkeleton();
521519

522520
/// Fix the vectorized code, taking care of header phi's, and more.
@@ -2386,8 +2384,8 @@ void InnerLoopVectorizer::createScalarPreheader(StringRef Prefix) {
23862384
LI, nullptr, Twine(Prefix) + "scalar.ph");
23872385
// NOTE: The Plan's scalar preheader VPBB isn't replaced with a VPIRBasicBlock
23882386
// wrapping LoopScalarPreHeader here at the moment, because the Plan's scalar
2389-
// preheader may be unreachable at this point and SCEV expansion may add to it
2390-
// later.
2387+
// preheader may be unreachable at this point. Instead it is replaced in
2388+
// executePlan.
23912389
}
23922390

23932391
/// Return the expanded step for \p ID using \p ExpandedSCEVs to look up SCEV

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -687,30 +687,47 @@ void VPlanTransforms::addMinimumIterationCheck(
687687
VPValue *TripCountVPV = Plan.getTripCount();
688688
const SCEV *TripCount = vputils::getSCEVExprForVPValue(TripCountVPV, SE);
689689
Type *TripCountTy = TripCount->getType();
690-
auto CreateMinTripCount = [&]() -> const SCEV * {
691-
// Create or get max(MinProfitableTripCount, UF * VF) and return it.
690+
auto GetMinTripCount = [&]() -> const SCEV * {
691+
// Compute max(MinProfitableTripCount, UF * VF) and return it.
692692
const SCEV *VFxUF =
693693
SE.getElementCount(TripCountTy, (VF * UF), SCEV::FlagNUW);
694-
const SCEV *MinProfitableTripCountSCEV =
695-
SE.getElementCount(TripCountTy, MinProfitableTripCount, SCEV::FlagNUW);
696-
const SCEV *Max = SE.getUMaxExpr(MinProfitableTripCountSCEV, VFxUF);
697-
if (!VF.isScalable())
698-
return Max;
699-
700694
if (UF * VF.getKnownMinValue() >=
701695
MinProfitableTripCount.getKnownMinValue()) {
702696
// TODO: SCEV should be able to simplify test.
703697
return VFxUF;
704698
}
705-
706-
return Max;
699+
const SCEV *MinProfitableTripCountSCEV =
700+
SE.getElementCount(TripCountTy, MinProfitableTripCount, SCEV::FlagNUW);
701+
return SE.getUMaxExpr(MinProfitableTripCountSCEV, VFxUF);
707702
};
708703

709704
VPBasicBlock *EntryVPBB = Plan.getEntry();
710705
VPBuilder Builder(EntryVPBB);
711706
VPValue *TripCountCheck = Plan.getFalse();
712-
const SCEV *Step = CreateMinTripCount();
713-
if (!TailFolded) {
707+
const SCEV *Step = GetMinTripCount();
708+
if (TailFolded) {
709+
if (CheckNeededWithTailFolding) {
710+
// vscale is not necessarily a power-of-2, which means we cannot guarantee
711+
// an overflow to zero when updating induction variables and so an
712+
// additional overflow check is required before entering the vector loop.
713+
714+
// Get the maximum unsigned value for the type.
715+
VPValue *MaxUIntTripCount = Plan.getOrAddLiveIn(ConstantInt::get(
716+
TripCountTy, cast<IntegerType>(TripCountTy)->getMask()));
717+
VPValue *DistanceToMax = Builder.createNaryOp(
718+
Instruction::Sub, {MaxUIntTripCount, TripCountVPV},
719+
DebugLoc::getUnknown());
720+
721+
// Don't execute the vector loop if (UMax - n) < (VF * UF).
722+
// FIXME: Should only check VF * UF, but currently checks Step=max(VF*UF,
723+
// minProfitableTripCount).
724+
TripCountCheck = Builder.createICmp(ICmpInst::ICMP_ULT, DistanceToMax,
725+
Builder.createExpandSCEV(Step), DL);
726+
} else {
727+
// TripCountCheck = false, folding tail implies positive vector trip
728+
// count.
729+
}
730+
} else {
714731
// TODO: Emit unconditional branch to vector preheader instead of
715732
// conditional branch with known condition.
716733
TripCount = SE.applyLoopGuards(TripCount, OrigLoop);
@@ -727,23 +744,6 @@ void VPlanTransforms::addMinimumIterationCheck(
727744
TripCountCheck = Builder.createICmp(
728745
CmpPred, TripCountVPV, MinTripCountVPV, DL, "min.iters.check");
729746
} // else step known to be < trip count, use TripCountCheck preset to false.
730-
} else if (CheckNeededWithTailFolding) {
731-
// vscale is not necessarily a power-of-2, which means we cannot guarantee
732-
// an overflow to zero when updating induction variables and so an
733-
// additional overflow check is required before entering the vector loop.
734-
735-
// Get the maximum unsigned value for the type.
736-
VPValue *MaxUIntTripCount = Plan.getOrAddLiveIn(ConstantInt::get(
737-
TripCountTy, cast<IntegerType>(TripCountTy)->getMask()));
738-
VPValue *DistanceToMax =
739-
Builder.createNaryOp(Instruction::Sub, {MaxUIntTripCount, TripCountVPV},
740-
DebugLoc::getUnknown());
741-
742-
// Don't execute the vector loop if (UMax - n) < (VF * UF).
743-
// FIXME: Should only check VF * UF, but currently checks Step=max(VF*UF,
744-
// minProfitableTripCount).
745-
TripCountCheck = Builder.createICmp(ICmpInst::ICMP_ULT, DistanceToMax,
746-
Builder.createExpandSCEV(Step), DL);
747747
}
748748
VPInstruction *Term =
749749
Builder.createNaryOp(VPInstruction::BranchOnCond, {TripCountCheck}, DL);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,12 +3507,11 @@ VPlanTransforms::expandSCEVs(VPlan &Plan, ScalarEvolution &SE) {
35073507
ExpSCEV->replaceAllUsesWith(Exp);
35083508
if (Plan.getTripCount() == ExpSCEV)
35093509
Plan.resetTripCount(Exp);
3510-
35113510
InsertPt = std::next(ExpSCEV->getIterator());
35123511
ExpSCEV->eraseFromParent();
35133512
}
35143513
assert(none_of(*Entry, IsaPred<VPExpandSCEVRecipe>) &&
3515-
"VPExpandSCEVRecipes must be be at the beginning of the entry block, "
3514+
"VPExpandSCEVRecipes must be at the beginning of the entry block, "
35163515
"after any VPIRInstructions");
35173516
for (Instruction &I : *EntryBB) {
35183517
if (!Expander.isInsertedInstruction(&I) || isa<PHINode>(I))

0 commit comments

Comments
 (0)