Skip to content

Commit ef217a0

Browse files
committed
[VPlan] Introduce and use getVectorPreheader (NFC).
Introduce a dedicated function to retrieve the vector preheader. This ensures the correct block is used, even if the skeleton is exetended.
1 parent bf8f5cc commit ef217a0

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ Value *VPTransformState::get(VPValue *Def, bool NeedsScalar) {
275275
// Place the code for broadcasting invariant variables in the new preheader.
276276
IRBuilder<>::InsertPointGuard Guard(Builder);
277277
if (SafeToHoist) {
278-
BasicBlock *LoopVectorPreHeader = CFG.VPBB2IRBB[cast<VPBasicBlock>(
279-
Plan->getVectorLoopRegion()->getSinglePredecessor())];
278+
BasicBlock *LoopVectorPreHeader =
279+
CFG.VPBB2IRBB[Plan->getVectorPreheader()];
280280
if (LoopVectorPreHeader)
281281
Builder.SetInsertPoint(LoopVectorPreHeader->getTerminator());
282282
}

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,6 +3812,11 @@ class VPlan {
38123812
return cast<VPRegionBlock>(getEntry()->getSingleSuccessor());
38133813
}
38143814

3815+
/// Returns the preheader of the vector loop region.
3816+
VPBasicBlock *getVectorPreheader() {
3817+
return cast<VPBasicBlock>(getVectorLoopRegion()->getSinglePredecessor());
3818+
}
3819+
38153820
/// Returns the canonical induction recipe of the vector loop.
38163821
VPCanonicalIVPHIRecipe *getCanonicalIV() {
38173822
VPBasicBlock *EntryVPBB = getVectorLoopRegion()->getEntryBasicBlock();

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10731073

10741074
/// Move loop-invariant recipes out of the vector loop region in \p Plan.
10751075
static void licm(VPlan &Plan) {
1076-
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
1077-
VPBasicBlock *Preheader =
1078-
cast<VPBasicBlock>(LoopRegion->getSinglePredecessor());
1076+
VPBasicBlock *Preheader = Plan.getVectorPreheader();
10791077

10801078
// Return true if we do not know how to (mechanically) hoist a given recipe
10811079
// out of a loop region. Does not address legality concerns such as aliasing
@@ -1089,6 +1087,7 @@ static void licm(VPlan &Plan) {
10891087
// Hoist any loop invariant recipes from the vector loop region to the
10901088
// preheader. Preform a shallow traversal of the vector loop region, to
10911089
// exclude recipes in replicate regions.
1090+
VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
10921091
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
10931092
vp_depth_first_shallow(LoopRegion->getEntry()))) {
10941093
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
@@ -1133,7 +1132,7 @@ void VPlanTransforms::truncateToMinimalBitwidths(
11331132
DenseMap<VPValue *, VPWidenCastRecipe *> ProcessedTruncs;
11341133
Type *CanonicalIVType = Plan.getCanonicalIV()->getScalarType();
11351134
VPTypeAnalysis TypeInfo(CanonicalIVType);
1136-
VPBasicBlock *PH = Plan.getEntry();
1135+
VPBasicBlock *PH = Plan.getVectorPreheader();
11371136
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
11381137
vp_depth_first_deep(Plan.getVectorLoopRegion()))) {
11391138
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
@@ -1317,7 +1316,7 @@ static VPActiveLaneMaskPHIRecipe *addVPLaneMaskPhiAndUpdateExitBranch(
13171316
// We can't use StartV directly in the ActiveLaneMask VPInstruction, since
13181317
// we have to take unrolling into account. Each part needs to start at
13191318
// Part * VF
1320-
auto *VecPreheader = cast<VPBasicBlock>(TopRegion->getSinglePredecessor());
1319+
auto *VecPreheader = Plan.getVectorPreheader();
13211320
VPBuilder Builder(VecPreheader);
13221321

13231322
// Create the ActiveLaneMask instruction using the correct start values.

0 commit comments

Comments
 (0)