Skip to content

Commit a121ebf

Browse files
fhahngithub-actions[bot]
authored andcommitted
Automerge: [VPlan] Replace VPBB for vector.ph during skeleton creation (NFC)
Shift replacement of regular VPBB for vector.ph with the VPIRBB wrapping the created IR block directly to skeleton creation, to be consistent with how the scalar preheader is handled.
2 parents a4ae6ce + 48bfaa4 commit a121ebf

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ class InnerLoopVectorizer {
511511
MinProfitableTripCount(MinProfitableTripCount), UF(UnrollFactor),
512512
Builder(PSE.getSE()->getContext()), Cost(CM), BFI(BFI), PSI(PSI),
513513
RTChecks(RTChecks), Plan(Plan),
514-
VectorPHVPB(Plan.getVectorLoopRegion()->getSinglePredecessor()) {}
514+
VectorPHVPBB(cast<VPBasicBlock>(
515+
Plan.getVectorLoopRegion()->getSinglePredecessor())) {}
515516

516517
virtual ~InnerLoopVectorizer() = default;
517518

@@ -645,7 +646,7 @@ class InnerLoopVectorizer {
645646

646647
/// The vector preheader block of \p Plan, used as target for check blocks
647648
/// introduced during skeleton creation.
648-
VPBlockBase *VectorPHVPB;
649+
VPBasicBlock *VectorPHVPBB;
649650
};
650651

651652
/// Encapsulate information regarding vectorization of a loop and its epilogue.
@@ -2277,11 +2278,11 @@ void InnerLoopVectorizer::introduceCheckBlockInVPlan(BasicBlock *CheckIRBB) {
22772278
// Note: The block with the minimum trip-count check is already connected
22782279
// during earlier VPlan construction.
22792280
VPBlockBase *ScalarPH = Plan.getScalarPreheader();
2280-
VPBlockBase *PreVectorPH = VectorPHVPB->getSinglePredecessor();
2281+
VPBlockBase *PreVectorPH = VectorPHVPBB->getSinglePredecessor();
22812282
assert(PreVectorPH->getNumSuccessors() == 2 && "Expected 2 successors");
22822283
assert(PreVectorPH->getSuccessors()[0] == ScalarPH && "Unexpected successor");
22832284
VPIRBasicBlock *CheckVPIRBB = Plan.createVPIRBasicBlock(CheckIRBB);
2284-
VPBlockUtils::insertOnEdge(PreVectorPH, VectorPHVPB, CheckVPIRBB);
2285+
VPBlockUtils::insertOnEdge(PreVectorPH, VectorPHVPBB, CheckVPIRBB);
22852286
PreVectorPH = CheckVPIRBB;
22862287
VPBlockUtils::connectBlocks(PreVectorPH, ScalarPH);
22872288
PreVectorPH->swapSuccessors();
@@ -2388,7 +2389,8 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
23882389
/// VPBB are moved to the end of the newly created VPIRBasicBlock. VPBB must
23892390
/// have a single predecessor, which is rewired to the new VPIRBasicBlock. All
23902391
/// successors of VPBB, if any, are rewired to the new VPIRBasicBlock.
2391-
static void replaceVPBBWithIRVPBB(VPBasicBlock *VPBB, BasicBlock *IRBB) {
2392+
static VPIRBasicBlock *replaceVPBBWithIRVPBB(VPBasicBlock *VPBB,
2393+
BasicBlock *IRBB) {
23922394
VPIRBasicBlock *IRVPBB = VPBB->getPlan()->createVPIRBasicBlock(IRBB);
23932395
auto IP = IRVPBB->begin();
23942396
for (auto &R : make_early_inc_range(VPBB->phis()))
@@ -2400,6 +2402,7 @@ static void replaceVPBBWithIRVPBB(VPBasicBlock *VPBB, BasicBlock *IRBB) {
24002402

24012403
VPBlockUtils::reassociateBlocks(VPBB, IRVPBB);
24022404
// VPBB is now dead and will be cleaned up when the plan gets destroyed.
2405+
return IRVPBB;
24032406
}
24042407

24052408
void InnerLoopVectorizer::createVectorLoopSkeleton(StringRef Prefix) {
@@ -2503,6 +2506,7 @@ BasicBlock *InnerLoopVectorizer::createVectorizedLoopSkeleton() {
25032506
emitIterationCountCheck(LoopScalarPreHeader);
25042507

25052508
replaceVPBBWithIRVPBB(Plan.getScalarPreheader(), LoopScalarPreHeader);
2509+
replaceVPBBWithIRVPBB(VectorPHVPBB, LoopVectorPreHeader);
25062510
return LoopVectorPreHeader;
25072511
}
25082512

@@ -7363,9 +7367,6 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73637367
//
73647368
//===------------------------------------------------===//
73657369

7366-
// 2. Copy and widen instructions from the old loop into the new loop.
7367-
replaceVPBBWithIRVPBB(VectorPH, State.CFG.PrevBB);
7368-
73697370
// Move check blocks to their final position.
73707371
// TODO: Move as part of VPIRBB execute and update impacted tests.
73717372
if (BasicBlock *MemCheckBlock = ILV.RTChecks.getMemRuntimeChecks().second)
@@ -7521,12 +7522,13 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
75217522
LoopVectorPreHeader = SplitBlock(TCCheckBlock, TCCheckBlock->getTerminator(),
75227523
static_cast<DominatorTree *>(nullptr), LI,
75237524
nullptr, "vector.ph");
7524-
75257525
if (ForEpilogue) {
75267526
// Save the trip count so we don't have to regenerate it in the
75277527
// vec.epilog.iter.check. This is safe to do because the trip count
75287528
// generated here dominates the vector epilog iter check.
75297529
EPI.TripCount = Count;
7530+
} else {
7531+
VectorPHVPBB = replaceVPBBWithIRVPBB(VectorPHVPBB, LoopVectorPreHeader);
75307532
}
75317533

75327534
BranchInst &BI =
@@ -7560,6 +7562,8 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton() {
75607562
BasicBlock *VecEpilogueIterationCountCheck =
75617563
SplitBlock(LoopVectorPreHeader, LoopVectorPreHeader->begin(), DT, LI,
75627564
nullptr, "vec.epilog.iter.check", true);
7565+
VectorPHVPBB = replaceVPBBWithIRVPBB(VectorPHVPBB, LoopVectorPreHeader);
7566+
75637567
emitMinimumVectorEpilogueIterCountCheck(LoopScalarPreHeader,
75647568
VecEpilogueIterationCountCheck);
75657569
AdditionalBypassBlock = VecEpilogueIterationCountCheck;

0 commit comments

Comments
 (0)