Skip to content

Commit 5ca39e8

Browse files
committed
[SLP] Optimize getSpillCost(); NFCI
For a given set of live values, the spill cost will always be the same for each call. Compute the cost once and multiply it by the number of calls. (I'm not sure this spill cost modeling makes sense if there are multiple calls, as the spill cost will likely be shared across calls in that case. But that's how it currently works.) llvm-svn: 365552
1 parent 1366262 commit 5ca39e8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -3355,6 +3355,7 @@ int BoUpSLP::getSpillCost() const {
33553355
});
33563356

33573357
// Now find the sequence of instructions between PrevInst and Inst.
3358+
unsigned NumCalls = 0;
33583359
BasicBlock::reverse_iterator InstIt = ++Inst->getIterator().getReverse(),
33593360
PrevInstIt =
33603361
PrevInst->getIterator().getReverse();
@@ -3367,16 +3368,19 @@ int BoUpSLP::getSpillCost() const {
33673368
// Debug informations don't impact spill cost.
33683369
if ((isa<CallInst>(&*PrevInstIt) &&
33693370
!isa<DbgInfoIntrinsic>(&*PrevInstIt)) &&
3370-
&*PrevInstIt != PrevInst) {
3371-
SmallVector<Type*, 4> V;
3372-
for (auto *II : LiveValues)
3373-
V.push_back(VectorType::get(II->getType(), BundleWidth));
3374-
Cost += TTI->getCostOfKeepingLiveOverCall(V);
3375-
}
3371+
&*PrevInstIt != PrevInst)
3372+
NumCalls++;
33763373

33773374
++PrevInstIt;
33783375
}
33793376

3377+
if (NumCalls) {
3378+
SmallVector<Type*, 4> V;
3379+
for (auto *II : LiveValues)
3380+
V.push_back(VectorType::get(II->getType(), BundleWidth));
3381+
Cost += NumCalls * TTI->getCostOfKeepingLiveOverCall(V);
3382+
}
3383+
33803384
PrevInst = Inst;
33813385
}
33823386

0 commit comments

Comments
 (0)