Skip to content

Commit 43e6f46

Browse files
committed
[VPlan] Pre-compute cost for all instrs only feeding exit conditions.
This fixes the following buildbot failures after 90fd99c: https://lab.llvm.org/buildbot/#/builders/17/builds/47 https://lab.llvm.org/buildbot/#/builders/168/builds/37
1 parent b1b7643 commit 43e6f46

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7357,16 +7357,30 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan,
73577357
/// be a single condition to control the vector loop.
73587358
SmallVector<BasicBlock *> Exiting;
73597359
CM.TheLoop->getExitingBlocks(Exiting);
7360-
// Add the cost of all exit conditions.
7360+
SetVector<Instruction *> ExitInstrs;
7361+
// Collect all exit conditions.
73617362
for (BasicBlock *EB : Exiting) {
73627363
auto *Term = dyn_cast<BranchInst>(EB->getTerminator());
73637364
if (!Term)
73647365
continue;
73657366
if (auto *CondI = dyn_cast<Instruction>(Term->getOperand(0))) {
7366-
assert(!CostCtx.SkipCostComputation.contains(CondI) &&
7367-
"Condition already skipped?");
7368-
CostCtx.SkipCostComputation.insert(CondI);
7369-
Cost += CostCtx.getLegacyCost(CondI, VF);
7367+
ExitInstrs.insert(CondI);
7368+
}
7369+
}
7370+
// Compute the cost of all instructions only feeding the exit conditions.
7371+
for (unsigned I = 0; I != ExitInstrs.size(); ++I) {
7372+
Instruction *CondI = ExitInstrs[I];
7373+
if (!OrigLoop->contains(CondI) ||
7374+
!CostCtx.SkipCostComputation.insert(CondI).second)
7375+
continue;
7376+
Cost += CostCtx.getLegacyCost(CondI, VF);
7377+
for (Value *Op : CondI->operands()) {
7378+
auto *OpI = dyn_cast<Instruction>(Op);
7379+
if (!OpI || any_of(OpI->users(), [&ExitInstrs](User *U) {
7380+
return !ExitInstrs.contains(cast<Instruction>(U));
7381+
}))
7382+
continue;
7383+
ExitInstrs.insert(OpI);
73707384
}
73717385
}
73727386

0 commit comments

Comments
 (0)