Skip to content

Commit 5cb0851

Browse files
committed
!fixup address comments
1 parent 9212f96 commit 5cb0851

File tree

4 files changed

+283
-122
lines changed

4 files changed

+283
-122
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8845,35 +8845,34 @@ static SetVector<VPIRInstruction *> collectUsersInExitBlocks(
88458845
continue;
88468846
auto *ExitVPBB = cast<VPIRBasicBlock>(VPB);
88478847
BasicBlock *ExitBB = ExitVPBB->getIRBasicBlock();
8848-
BasicBlock *ExitingBB = find_singleton<BasicBlock>(
8849-
to_vector(predecessors(ExitBB)),
8850-
[OrigLoop](BasicBlock *Pred, bool AllowRepeats) {
8851-
return OrigLoop->contains(Pred) ? Pred : nullptr;
8852-
});
88538848
for (VPRecipeBase &R : *ExitVPBB) {
88548849
auto *ExitIRI = dyn_cast<VPIRInstruction>(&R);
88558850
if (!ExitIRI)
88568851
continue;
88578852
auto *ExitPhi = dyn_cast<PHINode>(&ExitIRI->getInstruction());
88588853
if (!ExitPhi)
88598854
break;
8860-
Value *IncomingValue = ExitPhi->getIncomingValueForBlock(ExitingBB);
8861-
VPValue *V = Builder.getVPValueOrAddLiveIn(IncomingValue);
8862-
// Exit values for inductions are computed and updated outside of VPlan
8863-
// and independent of induction recipes.
8864-
// TODO: Compute induction exit values in VPlan.
8865-
if ((isa<VPWidenIntOrFpInductionRecipe>(V) &&
8866-
!cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst()) ||
8867-
isa<VPWidenPointerInductionRecipe>(V) ||
8868-
(isa<Instruction>(IncomingValue) &&
8869-
OrigLoop->contains(cast<Instruction>(IncomingValue)) &&
8870-
any_of(IncomingValue->users(), [&Inductions](User *U) {
8871-
auto *P = dyn_cast<PHINode>(U);
8872-
return P && Inductions.contains(P);
8873-
})))
8874-
continue;
8875-
ExitUsersToFix.insert(ExitIRI);
8876-
ExitIRI->addOperand(V);
8855+
for (BasicBlock *ExitingBB : predecessors(ExitBB)) {
8856+
if (!OrigLoop->contains(ExitingBB))
8857+
continue;
8858+
Value *IncomingValue = ExitPhi->getIncomingValueForBlock(ExitingBB);
8859+
VPValue *V = Builder.getVPValueOrAddLiveIn(IncomingValue);
8860+
// Exit values for inductions are computed and updated outside of VPlan
8861+
// and independent of induction recipes.
8862+
// TODO: Compute induction exit values in VPlan.
8863+
if ((isa<VPWidenIntOrFpInductionRecipe>(V) &&
8864+
!cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst()) ||
8865+
isa<VPWidenPointerInductionRecipe>(V) ||
8866+
(isa<Instruction>(IncomingValue) &&
8867+
OrigLoop->contains(cast<Instruction>(IncomingValue)) &&
8868+
any_of(IncomingValue->users(), [&Inductions](User *U) {
8869+
auto *P = dyn_cast<PHINode>(U);
8870+
return P && Inductions.contains(P);
8871+
})))
8872+
continue;
8873+
ExitUsersToFix.insert(ExitIRI);
8874+
ExitIRI->addOperand(V);
8875+
}
88778876
}
88788877
}
88798878
return ExitUsersToFix;
@@ -8887,23 +8886,26 @@ addUsersInExitBlocks(VPlan &Plan,
88878886
if (ExitUsersToFix.empty())
88888887
return;
88898888

8890-
auto *MiddleVPBB = Plan.getMiddleBlock();
8891-
VPBuilder B(MiddleVPBB, MiddleVPBB->getFirstNonPhi());
8892-
88938889
// Introduce extract for exiting values and update the VPIRInstructions
88948890
// modeling the corresponding LCSSA phis.
88958891
for (VPIRInstruction *ExitIRI : ExitUsersToFix) {
8892+
88968893
VPValue *V = ExitIRI->getOperand(0);
88978894
// Pass live-in values used by exit phis directly through to their users in
88988895
// the exit block.
88998896
if (V->isLiveIn())
89008897
continue;
89018898

8902-
LLVMContext &Ctx = ExitIRI->getInstruction().getContext();
8903-
VPValue *Ext = B.createNaryOp(VPInstruction::ExtractFromEnd,
8904-
{V, Plan.getOrAddLiveIn(ConstantInt::get(
8905-
IntegerType::get(Ctx, 32), 1))});
8906-
ExitIRI->setOperand(0, Ext);
8899+
for (VPBlockBase *PredVPB : ExitIRI->getParent()->getPredecessors()) {
8900+
auto *PredVPBB = cast<VPBasicBlock>(PredVPB);
8901+
VPBuilder B(PredVPBB, PredVPBB->getFirstNonPhi());
8902+
8903+
LLVMContext &Ctx = ExitIRI->getInstruction().getContext();
8904+
VPValue *Ext = B.createNaryOp(VPInstruction::ExtractFromEnd,
8905+
{V, Plan.getOrAddLiveIn(ConstantInt::get(
8906+
IntegerType::get(Ctx, 32), 1))});
8907+
ExitIRI->setOperand(0, Ext);
8908+
}
89078909
}
89088910
}
89098911

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,9 +1815,13 @@ void VPlanTransforms::handleUncountableEarlyExit(
18151815
auto *ExitingTerm = cast<BranchInst>(Exiting->getTerminator());
18161816
BasicBlock *TrueSucc = ExitingTerm->getSuccessor(0);
18171817
BasicBlock *FalseSucc = ExitingTerm->getSuccessor(1);
1818-
VPIRBasicBlock *VPExitBlock;
1819-
VPExitBlock = VPIRBasicBlock::fromBasicBlock(
1820-
!OrigLoop->contains(TrueSucc) ? TrueSucc : FalseSucc);
1818+
VPBasicBlock *VPExitBlock;
1819+
if (OrigLoop->getUniqueExitBlock()) {
1820+
VPExitBlock = cast<VPBasicBlock>(MiddleVPBB->getSuccessors()[0]);
1821+
} else {
1822+
VPExitBlock = VPIRBasicBlock::fromBasicBlock(
1823+
!OrigLoop->contains(TrueSucc) ? TrueSucc : FalseSucc);
1824+
}
18211825

18221826
VPValue *M = RecipeBuilder.getBlockInMask(
18231827
OrigLoop->contains(TrueSucc) ? TrueSucc : FalseSucc);

llvm/test/Transforms/LoopVectorize/X86/multi-exit-vplan.ll

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)