Skip to content

Commit 5797781

Browse files
committed
!fixup address latest comments, thanks
1 parent 2b76566 commit 5797781

File tree

6 files changed

+32
-46
lines changed

6 files changed

+32
-46
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,11 +2383,10 @@ void InnerLoopVectorizer::introduceCheckBlockInVPlan(BasicBlock *CheckIRBB) {
23832383
unsigned NumPredecessors = ScalarPH->getNumPredecessors();
23842384
(void)NumPredecessors;
23852385
for (VPRecipeBase &R : cast<VPBasicBlock>(ScalarPH)->phis()) {
2386-
auto *ResumePhi = cast<VPPhi>(&R);
2387-
ResumePhi->addOperand(
2388-
ResumePhi->getOperand(ResumePhi->getNumOperands() - 1));
2389-
assert(ResumePhi->getNumIncoming() == NumPredecessors &&
2386+
assert(isa<VPPhi>(&R) && "Phi expected to be VPPhi");
2387+
assert(cast<VPPhi>(&R)->getNumIncoming() == NumPredecessors - 1 &&
23902388
"must have incoming values for all operands");
2389+
R.addOperand(R.getOperand(NumPredecessors - 2));
23912390
}
23922391
}
23932392

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,9 +1122,9 @@ class VPPhiAccessors {
11221122
return getAsRecipe()->getNumOperands();
11231123
}
11241124

1125-
/// Removes the incoming value corresponding to \p IncomingBlock, which must
1126-
/// be a predecessor.
1127-
void removeIncomingValue(VPBlockBase *IncomingBlock) const;
1125+
/// Removes the incoming value for \p IncomingBlock, which must be a
1126+
/// predecessor.
1127+
void removeIncomingValueFor(VPBlockBase *IncomingBlock) const;
11281128

11291129
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
11301130
/// Print the recipe.
@@ -3530,22 +3530,22 @@ class VPScalarIVStepsRecipe : public VPRecipeWithIRFlags,
35303530

35313531
/// Casting from VPRecipeBase -> VPPhiAccessors is supported for all recipe
35323532
/// types implementing VPPhiAccessors. Used by isa<> & co.
3533-
template <> struct CastIsPossible<VPPhiAccessors, const VPRecipeBase *> {
3534-
static inline bool isPossible(const VPRecipeBase *f) {
3533+
template <typename SrcTy> struct CastIsPossible<VPPhiAccessors, SrcTy> {
3534+
static inline bool isPossible(SrcTy f) {
35353535
// TODO: include VPPredInstPHIRecipe too, once it implements VPPhiAccessors.
35363536
return isa<VPIRPhi, VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPhi>(f);
35373537
}
35383538
};
35393539
/// Support casting from VPRecipeBase -> VPPhiAccessors, by down-casting to the
35403540
/// recipe types implementing VPPhiAccessors. Used by cast<>, dyn_cast<> & co.
3541-
template <>
3542-
struct CastInfo<VPPhiAccessors, const VPRecipeBase *>
3543-
: public CastIsPossible<VPPhiAccessors, const VPRecipeBase *> {
3541+
template <typename SrcTy>
3542+
struct CastInfo<VPPhiAccessors, SrcTy>
3543+
: public CastIsPossible<VPPhiAccessors, SrcTy> {
35443544

3545-
using Self = CastInfo<VPPhiAccessors, const VPRecipeBase *>;
3545+
using Self = CastInfo<VPPhiAccessors, SrcTy>;
35463546

35473547
/// doCast is used by cast<>.
3548-
static inline VPPhiAccessors *doCast(const VPRecipeBase *R) {
3548+
static inline VPPhiAccessors *doCast(SrcTy R) {
35493549
return const_cast<VPPhiAccessors *>([R]() -> const VPPhiAccessors * {
35503550
switch (R->getVPDefID()) {
35513551
case VPDef::VPInstructionSC:
@@ -3561,7 +3561,7 @@ struct CastInfo<VPPhiAccessors, const VPRecipeBase *>
35613561
}
35623562

35633563
/// doCastIfPossible is used by dyn_cast<>.
3564-
static inline VPPhiAccessors *doCastIfPossible(const VPRecipeBase *f) {
3564+
static inline VPPhiAccessors *doCastIfPossible(SrcTy f) {
35653565
if (!Self::isPossible(f))
35663566
return nullptr;
35673567
return doCast(f);

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void VPlanTransforms::prepareForVectorization(
503503
HandledUncountableEarlyExit = true;
504504
} else {
505505
for (VPRecipeBase &R : EB->phis())
506-
cast<VPIRPhi>(&R)->removeIncomingValue(Pred);
506+
cast<VPIRPhi>(&R)->removeIncomingValueFor(Pred);
507507
}
508508
cast<VPBasicBlock>(Pred)->getTerminator()->eraseFromParent();
509509
VPBlockUtils::disconnectBlocks(Pred, EB);
@@ -528,16 +528,18 @@ void VPlanTransforms::prepareForVectorization(
528528
VPBasicBlock *ScalarPH = Plan.createVPBasicBlock("scalar.ph");
529529
VPBlockUtils::connectBlocks(ScalarPH, Plan.getScalarHeader());
530530

531+
// The connection order corresponds to the operands of the conditional branch,
532+
// with the middle block already connected to the exit block.
531533
VPBlockUtils::connectBlocks(MiddleVPBB, ScalarPH);
532534
// Also connect the entry block to the scalar preheader.
533535
// TODO: Also introduce a branch recipe together with the minimum trip count
534536
// check.
535537
VPBlockUtils::connectBlocks(Plan.getEntry(), ScalarPH);
536538
Plan.getEntry()->swapSuccessors();
537539

538-
// If MiddleVPBB has a single successor the original loop exits via the latch
539-
// and the single successor must be the scalar preheader. There's no need to
540-
// add a runtime check to MiddleVPBB.
540+
// If MiddleVPBB has a single successor then the original loop does not exit
541+
// via the latch and the single successor must be the scalar preheader.
542+
// There's no need to add a runtime check to MiddleVPBB.
541543
if (MiddleVPBB->getNumSuccessors() == 1) {
542544
assert(MiddleVPBB->getSingleSuccessor() == ScalarPH &&
543545
"must have ScalarPH as single successor");
@@ -546,8 +548,9 @@ void VPlanTransforms::prepareForVectorization(
546548

547549
assert(MiddleVPBB->getNumSuccessors() == 2 && "must have 2 successors");
548550

549-
// If needed, add a check in the middle block to see if we have completed
550-
// all of the iterations in the first vector loop.
551+
// Add a check in the middle block to see if we have completed$ all of the
552+
// iterations in the first vector loop.
553+
//
551554
// Three cases:
552555
// 1) If we require a scalar epilogue, the scalar ph must execute. Set the
553556
// condition to false.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ void VPIRPhi::execute(VPTransformState &State) {
11851185
State.Builder.SetInsertPoint(Phi->getParent(), std::next(Phi->getIterator()));
11861186
}
11871187

1188-
void VPPhiAccessors::removeIncomingValue(VPBlockBase *IncomingBlock) const {
1188+
void VPPhiAccessors::removeIncomingValueFor(VPBlockBase *IncomingBlock) const {
11891189
VPRecipeBase *R = const_cast<VPRecipeBase *>(getAsRecipe());
11901190
auto &Preds = R->getParent()->getPredecessors();
11911191
assert(R->getNumOperands() == Preds.size() &&

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,32 +1865,15 @@ static void removeBranchOnConst(VPlan &Plan) {
18651865
const auto &Preds = RemovedSucc->getPredecessors();
18661866
assert(count(Preds, VPBB) == 1 &&
18671867
"There must be a single edge between VPBB and its successor");
1868-
unsigned DeadIdx = std::distance(Preds.begin(), find(Preds, VPBB));
1869-
1870-
// Values coming from VPBB into ResumePhi recipes of RemoveSucc are removed
1871-
// from these recipes.
1868+
// Values coming from VPBB into phi recipes of RemoveSucc are removed from
1869+
// these recipes.
18721870
for (VPRecipeBase &R : make_early_inc_range(*RemovedSucc)) {
1873-
if (isa<VPIRPhi>(&R)) {
1874-
assert(RemovedSucc->getNumPredecessors() == 1 &&
1875-
"VPIRPhis must have a single predecessor");
1876-
cast<VPIRPhi>(&R)->removeIncomingValue(VPBB);
1877-
continue;
1878-
}
1879-
1880-
auto *VPI = dyn_cast<VPPhi>(&R);
1881-
if (!VPI)
1871+
auto *Phi = dyn_cast<VPPhiAccessors>(&R);
1872+
if (!Phi)
18821873
break;
1883-
VPBuilder B(VPI);
1884-
SmallVector<VPValue *> NewOperands;
1885-
// Create new operand list, with the dead incoming value filtered out.
1886-
for (const auto &[Idx, Op] : enumerate(VPI->operands())) {
1887-
if (Idx == DeadIdx)
1888-
continue;
1889-
NewOperands.push_back(Op);
1890-
}
1891-
VPI->replaceAllUsesWith(
1892-
B.createScalarPhi(NewOperands, VPI->getDebugLoc(), VPI->getName()));
1893-
VPI->eraseFromParent();
1874+
assert((!isa<VPIRPhi>(&R) || RemovedSucc->getNumPredecessors() == 1) &&
1875+
"VPIRPhis must have a single predecessor");
1876+
Phi->removeIncomingValueFor(VPBB);
18941877
}
18951878
// Disconnect blocks and remove the terminator. RemovedSucc will be deleted
18961879
// automatically on VPlan destruction if it becomes unreachable.

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ raw_ostream &operator<<(raw_ostream &OS, const VPRecipeBase &R);
200200
/// This class augments VPValue with operands which provide the inverse def-use
201201
/// edges from VPValue's users to their defs.
202202
class VPUser {
203+
/// Grant access to removeOperand for VPPhiAccessors, the only supported user.
203204
friend class VPPhiAccessors;
204205

205206
SmallVector<VPValue *, 2> Operands;

0 commit comments

Comments
 (0)