Skip to content

Commit 599e690

Browse files
committed
!fixup address latest comments, thanks!
1 parent 4ddc87a commit 599e690

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,28 +2429,29 @@ InnerLoopVectorizer::getOrCreateVectorTripCount(BasicBlock *InsertBlock) {
24292429
return VectorTripCount;
24302430
}
24312431

2432-
/// Helper to connect both the vector and scalar preheaders to the vector
2433-
/// preheader's predecessor. This is used when adjusting \p Plan during skeleton
2432+
/// Helper to connect both the vector and scalar preheaders to the Plan's
2433+
/// entry. This is used when adjusting \p Plan during skeleton
24342434
/// creation, i.e. adjusting the plan after introducing an initial runtime
24352435
/// check.
24362436
static void connectScalarPreheaderInVPlan(VPlan &Plan) {
24372437
VPBlockBase *VectorPH = Plan.getVectorPreheader();
24382438
VPBlockBase *ScalarPH = Plan.getScalarPreheader();
2439-
VPBlockBase *PredVPB = VectorPH->getSinglePredecessor();
2440-
VPBlockUtils::disconnectBlocks(Plan.getEntry(), VectorPH);
2441-
VPBlockUtils::connectBlocks(PredVPB, ScalarPH);
2442-
VPBlockUtils::connectBlocks(PredVPB, VectorPH);
2439+
VPBlockBase *PredVPB = Plan.getEntry();
2440+
VPBlockUtils::connectBlocks(PredVPB, ScalarPH, -1, 0);
2441+
VPBlockUtils::connectBlocks(PredVPB, VectorPH, 0, -1);
24432442
}
24442443

2445-
static void connectCheckBlockInVPlan(VPlan &Plan, BasicBlock *CheckIRBB) {
2444+
/// Introduces a new VPIRBasicBlock for \p CheckIRBB to \p Plan between the
2445+
/// vector preheader and its predecessor, also connecting to the scalar
2446+
/// preheader.
2447+
static void introduceCheckBlockInVPlan(VPlan &Plan, BasicBlock *CheckIRBB) {
24462448
VPBlockBase *ScalarPH = Plan.getScalarPreheader();
24472449
VPBlockBase *VectorPH = Plan.getVectorPreheader();
2448-
VPBlockBase *PredVPB = VectorPH->getSinglePredecessor();
2449-
VPBlockUtils::disconnectBlocks(PredVPB, VectorPH);
2450+
VPBlockBase *PreVectorPH = VectorPH->getSinglePredecessor();
24502451
VPIRBasicBlock *CheckVPIRBB = VPIRBasicBlock::fromBasicBlock(CheckIRBB);
2451-
VPBlockUtils::connectBlocks(PredVPB, CheckVPIRBB);
2452+
VPBlockUtils::connectBlocks(PreVectorPH, CheckVPIRBB, -1, 1);
24522453
VPBlockUtils::connectBlocks(CheckVPIRBB, ScalarPH);
2453-
VPBlockUtils::connectBlocks(CheckVPIRBB, VectorPH);
2454+
VPBlockUtils::connectBlocks(CheckVPIRBB, VectorPH, 0, -1);
24542455
}
24552456

24562457
void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
@@ -2537,14 +2538,14 @@ void InnerLoopVectorizer::emitIterationCountCheck(BasicBlock *Bypass) {
25372538
DT->getNode(Bypass)->getIDom()) &&
25382539
"TC check is expected to dominate Bypass");
25392540

2540-
// Update dominator for Bypass & LoopExit (if needed).
25412541
BranchInst &BI =
25422542
*BranchInst::Create(Bypass, LoopVectorPreHeader, CheckMinIters);
25432543
if (hasBranchWeightMD(*OrigLoop->getLoopLatch()->getTerminator()))
25442544
setBranchWeights(BI, MinItersBypassWeights, /*IsExpected=*/false);
25452545
ReplaceInstWithInst(TCCheckBlock->getTerminator(), &BI);
25462546
LoopBypassBlocks.push_back(TCCheckBlock);
25472547

2548+
// TODO: Wrap LoopVectorPreHeader in VPIRBasicBlock here.
25482549
connectScalarPreheaderInVPlan(Plan);
25492550
}
25502551

@@ -2563,7 +2564,7 @@ BasicBlock *InnerLoopVectorizer::emitSCEVChecks(BasicBlock *Bypass) {
25632564
LoopBypassBlocks.push_back(SCEVCheckBlock);
25642565
AddedSafetyChecks = true;
25652566

2566-
connectCheckBlockInVPlan(Plan, SCEVCheckBlock);
2567+
introduceCheckBlockInVPlan(Plan, SCEVCheckBlock);
25672568
return SCEVCheckBlock;
25682569
}
25692570

@@ -2600,7 +2601,7 @@ BasicBlock *InnerLoopVectorizer::emitMemRuntimeChecks(BasicBlock *Bypass) {
26002601

26012602
AddedSafetyChecks = true;
26022603

2603-
connectCheckBlockInVPlan(Plan, MemCheckBlock);
2604+
introduceCheckBlockInVPlan(Plan, MemCheckBlock);
26042605
return MemCheckBlock;
26052606
}
26062607

@@ -7909,7 +7910,7 @@ EpilogueVectorizerMainLoop::emitIterationCountCheck(BasicBlock *Bypass,
79097910
if (PredVPB->getNumSuccessors() == 1)
79107911
connectScalarPreheaderInVPlan(Plan);
79117912
else
7912-
connectCheckBlockInVPlan(Plan, TCCheckBlock);
7913+
introduceCheckBlockInVPlan(Plan, TCCheckBlock);
79137914
return TCCheckBlock;
79147915
}
79157916

@@ -7946,10 +7947,9 @@ EpilogueVectorizerEpilogueLoop::createEpilogueVectorizedLoopSkeleton(
79467947
if (EPI.SCEVSafetyCheck)
79477948
EPI.SCEVSafetyCheck->getTerminator()->replaceUsesOfWith(
79487949
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7949-
if (EPI.MemSafetyCheck) {
7950+
if (EPI.MemSafetyCheck)
79507951
EPI.MemSafetyCheck->getTerminator()->replaceUsesOfWith(
79517952
VecEpilogueIterationCountCheck, LoopScalarPreHeader);
7952-
}
79537953

79547954
DT->changeImmediateDominator(LoopScalarPreHeader,
79557955
EPI.EpilogueIterationCountCheck);

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ class VPIRInstruction : public VPRecipeBase {
14101410
InstructionCost computeCost(ElementCount VF,
14111411
VPCostContext &Ctx) const override;
14121412

1413-
Instruction &getInstruction() { return I; }
1413+
Instruction &getInstruction() const { return I; }
14141414

14151415
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
14161416
/// Print the recipe.
@@ -4098,13 +4098,21 @@ class VPBlockUtils {
40984098
/// the successors of \p From and \p From to the predecessors of \p To. Both
40994099
/// VPBlockBases must have the same parent, which can be null. Both
41004100
/// VPBlockBases can be already connected to other VPBlockBases.
4101-
static void connectBlocks(VPBlockBase *From, VPBlockBase *To) {
4101+
static void connectBlocks(VPBlockBase *From, VPBlockBase *To,
4102+
unsigned PredIdx = -1u, unsigned SuccIdx = -1u) {
41024103
assert((From->getParent() == To->getParent()) &&
41034104
"Can't connect two block with different parents");
4104-
assert(From->getNumSuccessors() < 2 &&
4105+
assert((SuccIdx != -1u || From->getNumSuccessors() < 2) &&
41054106
"Blocks can't have more than two successors.");
4106-
From->appendSuccessor(To);
4107-
To->appendPredecessor(From);
4107+
if (SuccIdx == -1u)
4108+
From->appendSuccessor(To);
4109+
else
4110+
From->getSuccessors()[SuccIdx] = To;
4111+
4112+
if (PredIdx == -1u)
4113+
To->appendPredecessor(From);
4114+
else
4115+
To->getPredecessors()[PredIdx] = From;
41084116
}
41094117

41104118
/// Disconnect VPBlockBases \p From and \p To bi-directionally. Remove \p To

0 commit comments

Comments
 (0)