From 5ca39e828c893f6fa823ea0cc5f2a8b9e19cecc7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 9 Jul 2019 20:24:44 +0000 Subject: [PATCH] [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 --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 49fce10..8cd948e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3355,6 +3355,7 @@ int BoUpSLP::getSpillCost() const { }); // Now find the sequence of instructions between PrevInst and Inst. + unsigned NumCalls = 0; BasicBlock::reverse_iterator InstIt = ++Inst->getIterator().getReverse(), PrevInstIt = PrevInst->getIterator().getReverse(); @@ -3367,16 +3368,19 @@ int BoUpSLP::getSpillCost() const { // Debug informations don't impact spill cost. if ((isa(&*PrevInstIt) && !isa(&*PrevInstIt)) && - &*PrevInstIt != PrevInst) { - SmallVector V; - for (auto *II : LiveValues) - V.push_back(VectorType::get(II->getType(), BundleWidth)); - Cost += TTI->getCostOfKeepingLiveOverCall(V); - } + &*PrevInstIt != PrevInst) + NumCalls++; ++PrevInstIt; } + if (NumCalls) { + SmallVector V; + for (auto *II : LiveValues) + V.push_back(VectorType::get(II->getType(), BundleWidth)); + Cost += NumCalls * TTI->getCostOfKeepingLiveOverCall(V); + } + PrevInst = Inst; } -- 2.7.4