Skip to content

Commit 6c45224

Browse files
committed
Address review comments
* Add new VPBlockUtils::reassociateBlocks that replaces all associations to Old with New. * Removed code to clear successors/predecessors in the deleted block.
1 parent 389ab09 commit 6c45224

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,15 +1004,12 @@ static void replaceVPBBWithIRVPBB(VPBasicBlock *VPBB, BasicBlock *IRBB) {
10041004
assert(!R.isPhi() && "Tried to move phi recipe to end of block");
10051005
R.moveBefore(*IRVPBB, IRVPBB->end());
10061006
}
1007-
VPBlockBase *PredVPBB = VPBB->getSinglePredecessor();
1008-
PredVPBB->replaceSuccessor(VPBB, IRVPBB);
1009-
IRVPBB->setPredecessors({PredVPBB});
1010-
for (auto *Succ : to_vector(VPBB->getSuccessors()))
1011-
Succ->replacePredecessor(VPBB, IRVPBB);
1007+
1008+
VPBlockUtils::reassociateBlocks(VPBB, IRVPBB);
1009+
IRVPBB->setPredecessors(VPBB->getPredecessors());
10121010
IRVPBB->setSuccessors(VPBB->getSuccessors());
10131011

1014-
VPBB->clearSuccessors();
1015-
VPBB->clearPredecessors();
1012+
// Any successor/predecessor lists will be cleared on deletion.
10161013
delete VPBB;
10171014
}
10181015

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3882,6 +3882,15 @@ class VPBlockUtils {
38823882
To->removePredecessor(From);
38833883
}
38843884

3885+
/// Reassociate all the blocks connected to \p Old so that they now point to
3886+
/// \p New.
3887+
static void reassociateBlocks(VPBlockBase *Old, VPBlockBase *New) {
3888+
for (auto *Pred : to_vector(Old->getPredecessors()))
3889+
Pred->replaceSuccessor(Old, New);
3890+
for (auto *Succ : to_vector(Old->getSuccessors()))
3891+
Succ->replacePredecessor(Old, New);
3892+
}
3893+
38853894
/// Return an iterator range over \p Range which only includes \p BlockTy
38863895
/// blocks. The accesses are casted to \p BlockTy.
38873896
template <typename BlockTy, typename T>

0 commit comments

Comments
 (0)