Skip to content

Commit d38da8d

Browse files
committed
Move RTChecks check closer to use
1 parent 61e5d8e commit d38da8d

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -582,21 +582,13 @@ class LoopVectorizationPlanner {
582582
/// set the largest included VF to the maximum VF for which no plan could be
583583
/// built. Each VPlan is built starting from a copy of \p InitialPlan, which
584584
/// is a plain CFG VPlan wrapping the original scalar loop.
585-
/// RTChecks is a list of pointer pairs that should be checked for aliasing,
586-
/// combining the resulting predicate with an active lane mask if one is in
587-
/// use.
588585
VPlanPtr tryToBuildVPlanWithVPRecipes(VPlanPtr InitialPlan, VFRange &Range,
589-
LoopVersioning *LVer,
590-
ArrayRef<PointerDiffInfo> RTChecks);
586+
LoopVersioning *LVer);
591587

592588
/// Build VPlans for power-of-2 VF's between \p MinVF and \p MaxVF inclusive,
593589
/// according to the information gathered by Legal when it checked if it is
594590
/// legal to vectorize the loop. This method creates VPlans using VPRecipes.
595-
/// RTChecks is a list of pointer pairs that should be checked for aliasing,
596-
/// combining the resulting predicate with an active lane mask if one is in
597-
/// use.
598-
void buildVPlansWithVPRecipes(ElementCount MinVF, ElementCount MaxVF,
599-
ArrayRef<PointerDiffInfo> RTChecks);
591+
void buildVPlansWithVPRecipes(ElementCount MinVF, ElementCount MaxVF);
600592

601593
// Adjust the recipes for reductions. For in-loop reductions the chain of
602594
// instructions leading from the loop exit instr to the phi need to be

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,7 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
23962396
LoopVectorPreHeader = SplitBlock(TCCheckBlock, TCCheckBlock->getTerminator(),
23972397
static_cast<DominatorTree *>(nullptr), LI,
23982398
nullptr, "vector.ph");
2399+
23992400
BranchInst &BI =
24002401
*BranchInst::Create(Bypass, LoopVectorPreHeader, CheckMinIters);
24012402
if (hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator()))
@@ -6730,12 +6731,6 @@ void LoopVectorizationPlanner::plan(
67306731
if (!MaxFactors) // Cases that should not to be vectorized nor interleaved.
67316732
return;
67326733

6733-
ArrayRef<PointerDiffInfo> DiffChecks;
6734-
auto TFStyle = CM.getTailFoldingStyle();
6735-
if (RTChecks.has_value() &&
6736-
useSafeEltsMask(TFStyle, CM.getRTCheckStyle(TFStyle), TTI))
6737-
DiffChecks = *RTChecks;
6738-
67396734
// Invalidate interleave groups if all blocks of loop will be predicated.
67406735
if (CM.blockNeedsPredicationForAnyReason(OrigLoop->getHeader()) &&
67416736
!useMaskedInterleavedAccesses(TTI)) {
@@ -6768,7 +6763,7 @@ void LoopVectorizationPlanner::plan(
67686763
CM.collectInLoopReductions();
67696764
if (CM.selectUserVectorizationFactor(UserVF)) {
67706765
LLVM_DEBUG(dbgs() << "LV: Using user VF " << UserVF << ".\n");
6771-
buildVPlansWithVPRecipes(UserVF, UserVF, DiffChecks);
6766+
buildVPlansWithVPRecipes(UserVF, UserVF);
67726767
LLVM_DEBUG(printPlans(dbgs()));
67736768
return;
67746769
}
@@ -6792,10 +6787,8 @@ void LoopVectorizationPlanner::plan(
67926787
CM.collectNonVectorizedAndSetWideningDecisions(VF);
67936788
}
67946789

6795-
buildVPlansWithVPRecipes(ElementCount::getFixed(1), MaxFactors.FixedVF,
6796-
DiffChecks);
6797-
buildVPlansWithVPRecipes(ElementCount::getScalable(1), MaxFactors.ScalableVF,
6798-
DiffChecks);
6790+
buildVPlansWithVPRecipes(ElementCount::getFixed(1), MaxFactors.FixedVF);
6791+
buildVPlansWithVPRecipes(ElementCount::getScalable(1), MaxFactors.ScalableVF);
67996792

68006793
LLVM_DEBUG(printPlans(dbgs()));
68016794
}
@@ -8402,9 +8395,8 @@ VPRecipeBuilder::tryToCreatePartialReduction(Instruction *Reduction,
84028395
ScaleFactor, Reduction);
84038396
}
84048397

8405-
void LoopVectorizationPlanner::buildVPlansWithVPRecipes(
8406-
ElementCount MinVF, ElementCount MaxVF,
8407-
ArrayRef<PointerDiffInfo> DiffChecks) {
8398+
void LoopVectorizationPlanner::buildVPlansWithVPRecipes(ElementCount MinVF,
8399+
ElementCount MaxVF) {
84088400
if (ElementCount::isKnownGT(MinVF, MaxVF))
84098401
return;
84108402

@@ -8430,8 +8422,7 @@ void LoopVectorizationPlanner::buildVPlansWithVPRecipes(
84308422
for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) {
84318423
VFRange SubRange = {VF, MaxVFTimes2};
84328424
if (auto Plan = tryToBuildVPlanWithVPRecipes(
8433-
std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer,
8434-
DiffChecks)) {
8425+
std::unique_ptr<VPlan>(VPlan0->duplicate()), SubRange, &LVer)) {
84358426
bool HasScalarVF = Plan->hasScalarVFOnly();
84368427
// Now optimize the initial VPlan.
84378428
if (!HasScalarVF)
@@ -8656,8 +8647,7 @@ static void addExitUsersForFirstOrderRecurrences(VPlan &Plan, VFRange &Range) {
86568647
}
86578648

86588649
VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
8659-
VPlanPtr Plan, VFRange &Range, LoopVersioning *LVer,
8660-
ArrayRef<PointerDiffInfo> DiffChecks) {
8650+
VPlanPtr Plan, VFRange &Range, LoopVersioning *LVer) {
86618651

86628652
using namespace llvm::VPlanPatternMatch;
86638653
SmallPtrSet<const InterleaveGroup<Instruction> *, 1> InterleaveGroups;
@@ -8945,6 +8935,14 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
89458935
bool ForControlFlow = useActiveLaneMaskForControlFlow(Style);
89468936
bool WithoutRuntimeCheck =
89478937
Style == TailFoldingStyle::DataAndControlFlowWithoutRuntimeCheck;
8938+
8939+
ArrayRef<PointerDiffInfo> DiffChecks;
8940+
std::optional<ArrayRef<PointerDiffInfo>> RTChecks =
8941+
CM.Legal->getRuntimePointerChecking()->getDiffChecks();
8942+
if (RTChecks.has_value() &&
8943+
useSafeEltsMask(Style, CM.getRTCheckStyle(Style), TTI))
8944+
DiffChecks = *RTChecks;
8945+
89488946
VPlanTransforms::addActiveLaneMask(*Plan, ForControlFlow,
89498947
WithoutRuntimeCheck, PSE, DiffChecks);
89508948
}

0 commit comments

Comments
 (0)