Skip to content

Commit ccb40b0

Browse files
committed
[VPlan] Add insertOnEdge to VPBlockUtils (NFC).
Add a new helper to insert a new VPBlockBase on an edge between 2 blocks. Suggested in #114292 and also useful for some existing code.
1 parent 69fb9bc commit ccb40b0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,6 +4177,24 @@ class VPBlockUtils {
41774177
return cast<BlockTy>(&Block);
41784178
});
41794179
}
4180+
4181+
/// Inserts \p BlockPtr on the edge between \p From and \p To. That is, update
4182+
/// \p From's successor to \p To to point to \p BlockPtr and \p To's
4183+
/// predecessor from \p From to \p BlockPtr. \p From and \p To are added to \p
4184+
/// BlockPtr's predecessors and successors respectively. There must be a
4185+
/// single edge between \p From and \p To.
4186+
static void insertOnEdge(VPBlockBase *From, VPBlockBase *To,
4187+
VPBlockBase *BlockPtr) {
4188+
auto &Successors = From->getSuccessors();
4189+
auto &Predecessors = To->getPredecessors();
4190+
assert(count(Successors, To) == 1 && count(Predecessors, From) == 1 &&
4191+
"must have single between From and To");
4192+
unsigned SuccIdx = std::distance(Successors.begin(), find(Successors, To));
4193+
unsigned PredIx =
4194+
std::distance(Predecessors.begin(), find(Predecessors, From));
4195+
VPBlockUtils::connectBlocks(From, BlockPtr, -1, SuccIdx);
4196+
VPBlockUtils::connectBlocks(BlockPtr, To, PredIx, -1);
4197+
}
41804198
};
41814199

41824200
class VPInterleavedAccessInfo {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ static void addReplicateRegions(VPlan &Plan) {
360360
// Record predicated instructions for above packing optimizations.
361361
VPBlockBase *Region = createReplicateRegion(RepR, Plan);
362362
Region->setParent(CurrentBlock->getParent());
363-
VPBlockUtils::connectBlocks(CurrentBlock, Region, -1, 0);
364-
VPBlockUtils::connectBlocks(Region, SplitBlock, 0, -1);
363+
VPBlockUtils::insertOnEdge(CurrentBlock, SplitBlock, Region);
365364
}
366365
}
367366

0 commit comments

Comments
 (0)