Skip to content

Commit af7ef89

Browse files
committed
[LV] Extend dead instruction detection to multiple exiting blocks
Given we haven't yet enabled multiple exiting blocks, this is currently non functional, but it's an obvious extension which cleans up a later patch. I don't think this is worth review (as it's pretty obvious), if anyone disagrees, feel feel to revert or comment and I will.
1 parent c415e70 commit af7ef89

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7472,16 +7472,23 @@ void LoopVectorizationPlanner::executePlan(InnerLoopVectorizer &ILV,
74727472

74737473
void LoopVectorizationPlanner::collectTriviallyDeadInstructions(
74747474
SmallPtrSetImpl<Instruction *> &DeadInstructions) {
7475-
BasicBlock *Latch = OrigLoop->getLoopLatch();
74767475

7477-
// We create new control-flow for the vectorized loop, so the original
7478-
// condition will be dead after vectorization if it's only used by the
7479-
// branch.
7480-
auto *Cmp = dyn_cast<Instruction>(Latch->getTerminator()->getOperand(0));
7481-
if (Cmp && Cmp->hasOneUse()) {
7482-
DeadInstructions.insert(Cmp);
7476+
// We create new control-flow for the vectorized loop, so the original exit
7477+
// conditions will be dead after vectorization if it's only used by the
7478+
// terminator
7479+
SmallVector<BasicBlock*> ExitingBlocks;
7480+
OrigLoop->getExitingBlocks(ExitingBlocks);
7481+
for (auto *BB : ExitingBlocks) {
7482+
auto *Cmp = dyn_cast<Instruction>(BB->getTerminator()->getOperand(0));
7483+
if (!Cmp || !Cmp->hasOneUse())
7484+
continue;
7485+
7486+
// TODO: we should introduce a getUniqueExitingBlocks on Loop
7487+
if (!DeadInstructions.insert(Cmp).second)
7488+
continue;
74837489

74847490
// The operands of the icmp is often a dead trunc, used by IndUpdate.
7491+
// TODO: can recurse through operands in general
74857492
for (Value *Op : Cmp->operands()) {
74867493
if (isa<TruncInst>(Op) && Op->hasOneUse())
74877494
DeadInstructions.insert(cast<Instruction>(Op));
@@ -7491,6 +7498,7 @@ void LoopVectorizationPlanner::collectTriviallyDeadInstructions(
74917498
// We create new "steps" for induction variable updates to which the original
74927499
// induction variables map. An original update instruction will be dead if
74937500
// all its users except the induction variable are dead.
7501+
auto *Latch = OrigLoop->getLoopLatch();
74947502
for (auto &Induction : Legal->getInductionVars()) {
74957503
PHINode *Ind = Induction.first;
74967504
auto *IndUpdate = cast<Instruction>(Ind->getIncomingValueForBlock(Latch));

0 commit comments

Comments
 (0)