Skip to content

Commit 95eeae1

Browse files
committed
[VPlan] Add PredIdx and SuccIdx arguments to connectBlocks (NFC).
Add extra arguments to connectBlocks which allow selecting which existing predecessor/successor to update. This avoids having to disconnect blocks first unnecessarily. Suggested in #114292.
1 parent dfe43bd commit 95eeae1

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,17 +4113,29 @@ class VPBlockUtils {
41134113
IfFalse->setParent(BlockPtr->getParent());
41144114
}
41154115

4116-
/// Connect VPBlockBases \p From and \p To bi-directionally. Append \p To to
4117-
/// the successors of \p From and \p From to the predecessors of \p To. Both
4118-
/// VPBlockBases must have the same parent, which can be null. Both
4119-
/// VPBlockBases can be already connected to other VPBlockBases.
4120-
static void connectBlocks(VPBlockBase *From, VPBlockBase *To) {
4116+
/// Connect VPBlockBases \p From and \p To bi-directionally. If \p PredIdx is
4117+
/// -1, append \p From to the predecessors of \p To, otherwise set \p To's
4118+
/// predecessor at \p PredIdx to \p From. If \p SuccIdx is -1, append \p To to
4119+
/// the successors of \p From, otherwise set \p From's successor at \p SuccIdx
4120+
/// to \p To. Both VPBlockBases must have the same parent, which can be null.
4121+
/// Both VPBlockBases can be already connected to other VPBlockBases.
4122+
static void connectBlocks(VPBlockBase *From, VPBlockBase *To,
4123+
unsigned PredIdx = -1u, unsigned SuccIdx = -1u) {
41214124
assert((From->getParent() == To->getParent()) &&
41224125
"Can't connect two block with different parents");
4123-
assert(From->getNumSuccessors() < 2 &&
4126+
assert((SuccIdx != -1u || From->getNumSuccessors() < 2) &&
41244127
"Blocks can't have more than two successors.");
4125-
From->appendSuccessor(To);
4126-
To->appendPredecessor(From);
4128+
assert((PredIdx != -1u || To->getNumPredecessors() < 2) &&
4129+
"Blocks can't have more than two predecessors.");
4130+
if (SuccIdx == -1u)
4131+
From->appendSuccessor(To);
4132+
else
4133+
From->getSuccessors()[SuccIdx] = To;
4134+
4135+
if (PredIdx == -1u)
4136+
To->appendPredecessor(From);
4137+
else
4138+
To->getPredecessors()[PredIdx] = From;
41274139
}
41284140

41294141
/// Disconnect VPBlockBases \p From and \p To bi-directionally. Remove \p To

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,8 @@ 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::disconnectBlocks(CurrentBlock, SplitBlock);
364-
VPBlockUtils::connectBlocks(CurrentBlock, Region);
365-
VPBlockUtils::connectBlocks(Region, SplitBlock);
363+
VPBlockUtils::connectBlocks(CurrentBlock, Region, -1, 0);
364+
VPBlockUtils::connectBlocks(Region, SplitBlock, 0, -1);
366365
}
367366
}
368367

0 commit comments

Comments
 (0)