Skip to content

Commit e2ce9ea

Browse files
committed
Address review comments
1 parent 624279d commit e2ce9ea

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9073,15 +9073,27 @@ addUsersInExitBlocks(VPlan &Plan,
90739073
return;
90749074

90759075
auto *MiddleVPBB = Plan.getMiddleBlock();
9076-
VPBuilder B(MiddleVPBB, MiddleVPBB->getFirstNonPhi());
90779076
VPBuilder MiddleB(MiddleVPBB, MiddleVPBB->getFirstNonPhi());
90789077
VPBuilder EarlyExitB;
90799078
VPBasicBlock *VectorEarlyExitVPBB = Plan.getEarlyExit();
90809079
VPValue *EarlyExitMask = nullptr;
9081-
if (VectorEarlyExitVPBB)
9080+
if (VectorEarlyExitVPBB) {
90829081
EarlyExitB.setInsertPoint(VectorEarlyExitVPBB,
90839082
VectorEarlyExitVPBB->getFirstNonPhi());
90849083

9084+
// Lookup and cache the early exit mask.
9085+
VPBasicBlock *MiddleSplitVPBB =
9086+
cast<VPBasicBlock>(VectorEarlyExitVPBB->getSinglePredecessor());
9087+
VPInstruction *PredTerm =
9088+
cast<VPInstruction>(MiddleSplitVPBB->getTerminator());
9089+
assert(PredTerm->getOpcode() == VPInstruction::BranchOnCond &&
9090+
"Unexpected middle split block terminator");
9091+
VPInstruction *ScalarCond = cast<VPInstruction>(PredTerm->getOperand(0));
9092+
assert(ScalarCond->getOpcode() == VPInstruction::AnyOf &&
9093+
"Unexpected condition for middle split block terminator branch");
9094+
EarlyExitMask = ScalarCond->getOperand(0);
9095+
}
9096+
90859097
// Introduce extract for exiting values and update the VPIRInstructions
90869098
// modeling the corresponding LCSSA phis.
90879099
for (VPIRInstruction *ExitIRI : ExitUsersToFix) {
@@ -9097,22 +9109,6 @@ addUsersInExitBlocks(VPlan &Plan,
90979109
cast<VPBasicBlock>(ExitIRI->getParent()->getPredecessors()[Idx]);
90989110
if (PredVPBB != MiddleVPBB) {
90999111
assert(ExitIRI->getParent()->getNumPredecessors() <= 2);
9100-
9101-
// Lookup and cache the early exit mask.
9102-
if (!EarlyExitMask) {
9103-
VPBasicBlock *MiddleSplitVPBB =
9104-
cast<VPBasicBlock>(VectorEarlyExitVPBB->getSinglePredecessor());
9105-
VPInstruction *PredTerm =
9106-
cast<VPInstruction>(MiddleSplitVPBB->getTerminator());
9107-
assert(PredTerm->getOpcode() == VPInstruction::BranchOnCond &&
9108-
"Unexpected middle split block terminator");
9109-
VPInstruction *ScalarCond =
9110-
cast<VPInstruction>(PredTerm->getOperand(0));
9111-
assert(
9112-
ScalarCond->getOpcode() == VPInstruction::AnyOf &&
9113-
"Unexpected condition for middle split block terminator branch");
9114-
EarlyExitMask = ScalarCond->getOperand(0);
9115-
}
91169112
Ext = EarlyExitB.createNaryOp(VPInstruction::ExtractFirstActive,
91179113
{Op, EarlyExitMask});
91189114
} else {

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,26 @@ void VPlan::prepareToExecute(Value *TripCountV, Value *VectorTripCountV,
957957
}
958958
}
959959

960+
bool VPlan::isExitBlock(VPBlockBase *VPBB) {
961+
if (!isa<VPIRBasicBlock>(VPBB) || VPBB->getNumSuccessors() ||
962+
VPBB == getScalarHeader())
963+
return false;
964+
965+
VPRegionBlock *RegionBlock = getVectorLoopRegion();
966+
if (!RegionBlock)
967+
return false;
968+
969+
// The block must be a successor of the region block.
970+
if (llvm::is_contained(
971+
vp_depth_first_shallow(RegionBlock->getSingleSuccessor()), VPBB)) {
972+
assert(llvm::is_contained(getExitBlocks(), VPBB) &&
973+
"Expected to find VPlan block in list of exit blocks!");
974+
return true;
975+
}
976+
977+
return false;
978+
}
979+
960980
/// Generate the code inside the preheader and body of the vectorized loop.
961981
/// Assumes a single pre-header basic-block was created for this. Introduce
962982
/// additional basic-blocks as needed, and fill them all.

llvm/lib/Transforms/Vectorize/VPlanCFG.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -306,24 +306,6 @@ template <> struct GraphTraits<VPlan *> {
306306
}
307307
};
308308

309-
inline bool VPlan::isExitBlock(VPBlockBase *VPBB) {
310-
if (!isa<VPIRBasicBlock>(VPBB) || VPBB->getNumSuccessors() ||
311-
VPBB == getScalarHeader())
312-
return false;
313-
314-
VPRegionBlock *RegionBlock = getVectorLoopRegion();
315-
if (!RegionBlock)
316-
return false;
317-
318-
// The block must be a successor of the region block.
319-
for (auto *OtherVPBB :
320-
vp_depth_first_shallow(RegionBlock->getSingleSuccessor()))
321-
if (OtherVPBB == VPBB)
322-
return true;
323-
324-
return false;
325-
}
326-
327309
inline auto VPlan::getExitBlocks() {
328310
VPBlockBase *ScalarHeader = getScalarHeader();
329311
return make_filter_range(

0 commit comments

Comments
 (0)