Skip to content

Commit efc4b83

Browse files
committed
!fixup address latest comments, thanks!
1 parent 6a872d7 commit efc4b83

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9337,10 +9337,10 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93379337
VPBasicBlock::iterator MBIP = MiddleVPBB->getFirstNonPhi();
93389338
VPBlockBase *PrevVPBB = nullptr;
93399339
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
9340-
// Skip VPBBs not corresponding to any input IR basic blocks.
9341-
if (!HCFGBuilder.getIRBBForVPB(VPBB)) {
9342-
assert(VPBB == LoopRegion->getExiting() &&
9343-
"only the latch block shouldn't have a corresponding IRBB");
9340+
// Handle VPBBs down to the latch.
9341+
if (VPBB == LoopRegion->getExiting()) {
9342+
assert(!HCFGBuilder.getIRBBForVPB(VPBB) &&
9343+
"the latch block shouldn't have a corresponding IRBB");
93449344
VPBlockUtils::connectBlocks(PrevVPBB, VPBB);
93459345
break;
93469346
}
@@ -9358,15 +9358,18 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93589358
// Convert input VPInstructions to widened recipes.
93599359
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
93609360
auto *SingleDef = cast<VPSingleDefRecipe>(&R);
9361+
auto *UnderlyingValue = SingleDef->getUnderlyingValue();
93619362
// Skip recipes that do not need transforming, including canonical IV,
93629363
// wide canonical IV and VPInstructions without underlying values. The
9363-
// latter is added by masking.
9364-
if (isa<VPCanonicalIVPHIRecipe>(SingleDef) ||
9365-
isa<VPWidenCanonicalIVRecipe>(SingleDef) ||
9366-
(isa<VPInstruction>(&R) && !SingleDef->getUnderlyingValue()))
9364+
// latter are added above by masking.
9365+
// FIXME: Migrate code relying on the underlying instruction from VPlan0 to construct recipes below to not use the underlying instruction.
9366+
if (isa<VPCanonicalIVPHIRecipe, VPWidenCanonicalIVRecipe>(SingleDef) ||
9367+
(isa<VPInstruction>(&R) && !UnderlyingValue))
93679368
continue;
9368-
assert(isa<VPWidenPHIRecipe>(&R) || (isa<VPInstruction>(SingleDef) &&
9369-
SingleDef->getUnderlyingValue()) &&
9369+
9370+
// FIXME: VPlan0, which models a copy of the original scalar loop, should not use VPWidenPHIRecipe to model the phis.
9371+
assert((isa<VPWidenPHIRecipe>(SingleDef) || isa<VPInstruction>(SingleDef)) &&
9372+
UnderlyingValue &&
93709373
"unsupported recipe");
93719374

93729375
if (match(&R, m_BranchOnCond(m_VPValue())) ||
@@ -9378,11 +9381,12 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
93789381

93799382
// TODO: Gradually replace uses of underlying instruction by analyses on
93809383
// VPlan.
9381-
Instruction *Instr = SingleDef->getUnderlyingInstr();
9384+
Instruction *Instr = cast<Instruction>(UnderlyingValue);
93829385
Builder.setInsertPoint(SingleDef);
93839386
SmallVector<VPValue *, 4> Operands;
93849387
auto *Phi = dyn_cast<PHINode>(Instr);
93859388
if (Phi && Phi->getParent() == HeaderBB) {
9389+
// The backedge value will be added in fixHeaderPhis later.
93869390
Operands.push_back(Plan->getOrAddLiveIn(
93879391
Phi->getIncomingValueForBlock(OrigLoop->getLoopPreheader())));
93889392
} else {
@@ -9414,11 +9418,11 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94149418

94159419
RecipeBuilder.setRecipe(Instr, Recipe);
94169420
if (isa<VPWidenIntOrFpInductionRecipe>(Recipe) && isa<TruncInst>(Instr)) {
9417-
// Optimized a truncate truncates to VPWidenIntOrFpInductionRecipe Move
9418-
// it to the phi section in the header.
9421+
// Optimized a truncate to VPWidenIntOrFpInductionRecipe. It needs to be moved to the phi section in the header.
94199422
Recipe->insertBefore(*HeaderVPBB, HeaderVPBB->getFirstNonPhi());
9420-
} else
9423+
} else {
94219424
Builder.insert(Recipe);
9425+
}
94229426
if (Recipe->getNumDefinedValues() == 1)
94239427
SingleDef->replaceAllUsesWith(Recipe->getVPSingleValue());
94249428
else
@@ -9429,8 +9433,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
94299433

94309434
// Flatten the CFG in the loop. Masks for blocks have already been generated
94319435
// and added to recipes as needed. To do so, first disconnect VPBB from its
9432-
// predecessors and successors. Then connect VPBB to the previously visited
9433-
// VPBB.
9436+
// successors. Then connect VPBB to the previously visited$ VPBB.
94349437
for (auto *Succ : to_vector(VPBB->getSuccessors()))
94359438
VPBlockUtils::disconnectBlocks(VPBB, Succ);
94369439
if (PrevVPBB)

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,14 @@ static bool hasConditionalTerminator(const VPBasicBlock *VPBB) {
589589
}
590590

591591
const VPRecipeBase *R = &VPBB->back();
592+
bool IsSwitch = isa<VPInstruction>(R) &&
593+
cast<VPInstruction>(R)->getOpcode() == Instruction::Switch;
592594
bool IsCondBranch = isa<VPBranchOnMaskRecipe>(R) ||
593595
match(R, m_BranchOnCond(m_VPValue())) ||
594596
match(R, m_BranchOnCount(m_VPValue(), m_VPValue()));
595-
bool IsSwitch = isa<VPInstruction>(R) &&
596-
cast<VPInstruction>(R)->getOpcode() == Instruction::Switch;
597597
(void)IsCondBranch;
598598
(void)IsSwitch;
599-
600-
if (VPBB->getNumSuccessors() >= 2 ||
599+
if (VPBB->getNumSuccessors() == 2 ||
601600
(VPBB->isExiting() && !VPBB->getParent()->isReplicator())) {
602601
assert((IsCondBranch || IsSwitch) &&
603602
"block with multiple successors not terminated by "
@@ -606,6 +605,13 @@ static bool hasConditionalTerminator(const VPBasicBlock *VPBB) {
606605
return true;
607606
}
608607

608+
if (VPBB->getNumSuccessors() > 2) {
609+
assert(IsSwitch &&
610+
"block with more than 2 successors not terminated by "
611+
"a switch recipe");
612+
return true;
613+
}
614+
609615
assert(
610616
!IsCondBranch &&
611617
"block with 0 or 1 successors terminated by conditional branch recipe");

0 commit comments

Comments
 (0)