Skip to content

Commit 595b057

Browse files
committed
!fixup address latest comments, thanks
1 parent 8dfd569 commit 595b057

File tree

4 files changed

+34
-66
lines changed

4 files changed

+34
-66
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2883,8 +2883,11 @@ void InnerLoopVectorizer::fixNonInductionPHIs(VPTransformState &State) {
28832883
PHINode *NewPhi = cast<PHINode>(State.get(VPPhi));
28842884
// Make sure the builder has a valid insert point.
28852885
Builder.SetInsertPoint(NewPhi);
2886-
for (const auto &[Inc, VPBB] : VPPhi->incoming_values_and_blocks())
2886+
for (unsigned Idx = 0; Idx < VPPhi->getNumIncomingValues(); ++Idx) {
2887+
VPValue *Inc = VPPhi->getIncomingValue(Idx);
2888+
const VPBasicBlock *VPBB = VPPhi->getIncomingBlock(Idx);
28872889
NewPhi->addIncoming(State.get(Inc), State.CFG.VPBB2IRBB[VPBB]);
2890+
}
28882891
}
28892892
}
28902893
}

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,26 @@ InstructionCost VPBasicBlock::cost(ElementCount VF, VPCostContext &Ctx) {
790790
return Cost;
791791
}
792792

793+
const VPBasicBlock *VPBasicBlock::getCFGPredecessor(unsigned Idx) const {
794+
const VPBlockBase *Pred = nullptr;
795+
if (getNumPredecessors() > 0) {
796+
Pred = getPredecessors()[Idx];
797+
} else {
798+
auto *Region = getParent();
799+
assert(Region && !Region->isReplicator() && Region->getEntry() == this &&
800+
"must be in the entry block of a non-replicate region");
801+
assert(
802+
Idx < 2 && Region->getNumPredecessors() == 1 &&
803+
"when placed in an entry block, only 2 incoming blocks are available");
804+
805+
// Idx == 0 selects the predecessor of the region, Idx == 1 selects the
806+
// region itself whose exiting block feeds the phi across the backedge.
807+
Pred = Idx == 0 ? Region->getSinglePredecessor() : Region;
808+
}
809+
810+
return Pred->getExitingBasicBlock();
811+
}
812+
793813
InstructionCost VPRegionBlock::cost(ElementCount VF, VPCostContext &Ctx) {
794814
if (!isReplicator()) {
795815
InstructionCost Cost = 0;

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,42 +1180,13 @@ template <typename RecipeTy> class VPPhiAccessors {
11801180
return getAsRecipe()->getOperand(Idx);
11811181
}
11821182

1183-
/// Returns an interator range over the incoming values
1184-
VPUser::const_operand_range incoming_values() const {
1185-
return getAsRecipe()->operands();
1186-
}
1187-
11881183
/// Returns the incoming block with index \p Idx.
1189-
const VPBasicBlock *getIncomingBlock(unsigned Idx) const;
1190-
1191-
using const_incoming_block_iterator =
1192-
mapped_iterator<detail::index_iterator,
1193-
std::function<const VPBasicBlock *(size_t)>>;
1194-
using const_incoming_blocks_range =
1195-
iterator_range<const_incoming_block_iterator>;
1196-
1197-
const_incoming_block_iterator incoming_block_begin() const {
1198-
return const_incoming_block_iterator(
1199-
detail::index_iterator(0),
1200-
[this](size_t Idx) { return getIncomingBlock(Idx); });
1201-
}
1202-
const_incoming_block_iterator incoming_block_end() const {
1203-
return const_incoming_block_iterator(
1204-
detail::index_iterator(getAsRecipe()->getNumOperands()),
1205-
[this](size_t Idx) { return getIncomingBlock(Idx); });
1184+
const VPBasicBlock *getIncomingBlock(unsigned Idx) const {
1185+
return getAsRecipe()->getParent()->getCFGPredecessor(Idx);
12061186
}
12071187

1208-
/// Returns an iterator range over the incoming blocks.
1209-
const_incoming_blocks_range incoming_blocks() const {
1210-
return make_range(incoming_block_begin(), incoming_block_end());
1211-
}
1212-
1213-
/// Returns an iterator range over pairs of incoming values and corresponding
1214-
/// incoming blocks.
1215-
detail::zippy<llvm::detail::zip_shortest, VPUser::const_operand_range,
1216-
const_incoming_blocks_range>
1217-
incoming_values_and_blocks() const {
1218-
return zip(incoming_values(), incoming_blocks());
1188+
unsigned getNumIncomingValues() const {
1189+
return getAsRecipe()->getNumOperands();
12191190
}
12201191
};
12211192

@@ -3372,6 +3343,12 @@ class VPBasicBlock : public VPBlockBase {
33723343
/// the cloned recipes.
33733344
VPBasicBlock *clone() override;
33743345

3346+
/// Returns the predecessor block at index \p Idx with the predecessors as per
3347+
/// the corresponding plain CFG. If the block is an entry block to a region,
3348+
/// the first predecessor is the single predecessor of a region, and the
3349+
/// second predecessor is the exiting block of the region.
3350+
const VPBasicBlock *getCFGPredecessor(unsigned Idx) const;
3351+
33753352
protected:
33763353
/// Execute the recipes in the IR basic block \p BB.
33773354
void executeRecipes(VPTransformState *State, BasicBlock *BB);

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,32 +1205,6 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12051205
}
12061206
#endif
12071207

1208-
/// Returns the incoming block at index \p Idx for \p R. This handles both
1209-
/// recipes placed in entry blocks of loop regions (incoming blocks are the
1210-
/// region's predecessor and the region's exit) and other locations (incoming
1211-
/// blocks are the direct predecessors).
1212-
static const VPBasicBlock *getIncomingBlockForRecipe(const VPRecipeBase *R,
1213-
unsigned Idx) {
1214-
const VPBasicBlock *Parent = R->getParent();
1215-
const VPBlockBase *Pred = nullptr;
1216-
if (Parent->getNumPredecessors() > 0) {
1217-
Pred = Parent->getPredecessors()[Idx];
1218-
} else {
1219-
auto *Region = Parent->getParent();
1220-
assert(Region && !Region->isReplicator() && Region->getEntry() == Parent &&
1221-
"must be in the entry block of a non-replicate region");
1222-
assert(
1223-
Idx < 2 && R->getNumOperands() == 2 &&
1224-
"when placed in an entry block, only 2 incoming blocks are available");
1225-
1226-
// Idx == 0 selects the predecessor of the region, Idx == 1 selects the
1227-
// region itself whose exiting block feeds the phi across the backedge.
1228-
Pred = Idx == 0 ? Region->getSinglePredecessor() : Region;
1229-
}
1230-
1231-
return Pred->getExitingBasicBlock();
1232-
}
1233-
12341208
void VPIRMetadata::applyMetadata(Instruction &I) const {
12351209
for (const auto &[Kind, Node] : Metadata)
12361210
I.setMetadata(Kind, Node);
@@ -3712,12 +3686,6 @@ void VPReductionPHIRecipe::print(raw_ostream &O, const Twine &Indent,
37123686
}
37133687
#endif
37143688

3715-
template <>
3716-
const VPBasicBlock *
3717-
VPPhiAccessors<VPWidenPHIRecipe>::getIncomingBlock(unsigned Idx) const {
3718-
return getIncomingBlockForRecipe(getAsRecipe(), Idx);
3719-
}
3720-
37213689
void VPWidenPHIRecipe::execute(VPTransformState &State) {
37223690
assert(EnableVPlanNativePath &&
37233691
"Non-native vplans are not expected to have VPWidenPHIRecipes.");

0 commit comments

Comments
 (0)