Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8679,14 +8679,14 @@ void LoopVectorizationPlanner::attachRuntimeChecks(
void LoopVectorizationPlanner::addMinimumIterationCheck(
VPlan &Plan, ElementCount VF, unsigned UF,
ElementCount MinProfitableTripCount) const {
const uint32_t *BranchWeigths =
const uint32_t *BranchWeights =
hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator())
? &MinItersBypassWeights[0]
: nullptr;
VPlanTransforms::addMinimumIterationCheck(
Plan, VF, UF, MinProfitableTripCount,
CM.requiresScalarEpilogue(VF.isVector()), CM.foldTailByMasking(),
/*CheckNeededWithTailFolding=*/false, OrigLoop, BranchWeigths,
OrigLoop, BranchWeights,
OrigLoop->getLoopPredecessor()->getTerminator()->getDebugLoc(), PSE);
}

Expand Down
32 changes: 5 additions & 27 deletions llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,8 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond,
void VPlanTransforms::addMinimumIterationCheck(
VPlan &Plan, ElementCount VF, unsigned UF,
ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue,
bool TailFolded, bool CheckNeededWithTailFolding, Loop *OrigLoop,
const uint32_t *MinItersBypassWeights, DebugLoc DL,
PredicatedScalarEvolution &PSE) {
bool TailFolded, Loop *OrigLoop, const uint32_t *MinItersBypassWeights,
DebugLoc DL, PredicatedScalarEvolution &PSE) {
// Generate code to check if the loop's trip count is less than VF * UF, or
// equal to it in case a scalar epilogue is required; this implies that the
// vector trip count is zero. This check also covers the case where adding one
Expand Down Expand Up @@ -1071,30 +1070,9 @@ void VPlanTransforms::addMinimumIterationCheck(
VPBuilder Builder(EntryVPBB);
VPValue *TripCountCheck = Plan.getFalse();
const SCEV *Step = GetMinTripCount();
if (TailFolded) {
if (CheckNeededWithTailFolding) {
// vscale is not necessarily a power-of-2, which means we cannot guarantee
// an overflow to zero when updating induction variables and so an
// additional overflow check is required before entering the vector loop.

VPValue *StepVPV = Builder.createExpandSCEV(Step);

// Get the maximum unsigned value for the type.
VPValue *MaxUIntTripCount =
Plan.getConstantInt(cast<IntegerType>(TripCountTy)->getMask());
VPValue *DistanceToMax =
Builder.createSub(MaxUIntTripCount, TripCountVPV);

// Don't execute the vector loop if (UMax - n) < (VF * UF).
// FIXME: Should only check VF * UF, but currently checks Step=max(VF*UF,
// minProfitableTripCount).
TripCountCheck =
Builder.createICmp(ICmpInst::ICMP_ULT, DistanceToMax, StepVPV, DL);
} else {
// TripCountCheck = false, folding tail implies positive vector trip
// count.
}
} else {
// TripCountCheck = false, folding tail implies positive vector trip
// count.
if (!TailFolded) {
// TODO: Emit unconditional branch to vector preheader instead of
// conditional branch with known condition.
TripCount = SE.applyLoopGuards(TripCount, OrigLoop);
Expand Down
12 changes: 5 additions & 7 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ struct VPlanTransforms {
bool TailFolded);

// Create a check to \p Plan to see if the vector loop should be executed.
static void
addMinimumIterationCheck(VPlan &Plan, ElementCount VF, unsigned UF,
ElementCount MinProfitableTripCount,
bool RequiresScalarEpilogue, bool TailFolded,
bool CheckNeededWithTailFolding, Loop *OrigLoop,
const uint32_t *MinItersBypassWeights, DebugLoc DL,
PredicatedScalarEvolution &PSE);
static void addMinimumIterationCheck(
VPlan &Plan, ElementCount VF, unsigned UF,
ElementCount MinProfitableTripCount, bool RequiresScalarEpilogue,
bool TailFolded, Loop *OrigLoop, const uint32_t *MinItersBypassWeights,
DebugLoc DL, PredicatedScalarEvolution &PSE);

/// Add a check to \p Plan to see if the epilogue vector loop should be
/// executed.
Expand Down
Loading