From 182a123a21e06e723e07a805d78cbdd020e79f17 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 14 Nov 2018 15:58:40 +0000 Subject: [PATCH] [VPlan, SLP] Use SmallPtrSet for Candidates. This slightly improves the candidate handling in getBest(). llvm-svn: 346870 --- lib/Transforms/Vectorize/VPlan.h | 2 +- lib/Transforms/Vectorize/VPlanSLP.cpp | 49 +++++++++++++-------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/Transforms/Vectorize/VPlan.h b/lib/Transforms/Vectorize/VPlan.h index dd50db346b0..5c1b4a83c30 100644 --- a/lib/Transforms/Vectorize/VPlan.h +++ b/lib/Transforms/Vectorize/VPlan.h @@ -1607,7 +1607,7 @@ private: /// candidates to choose from are values with an opcode matching \p Last's /// or loads consecutive to \p Last. std::pair getBest(OpMode Mode, VPValue *Last, - SmallVectorImpl &Candidates, + SmallPtrSetImpl &Candidates, VPInterleavedAccessInfo &IAI); /// Print bundle \p Values to dbgs(). diff --git a/lib/Transforms/Vectorize/VPlanSLP.cpp b/lib/Transforms/Vectorize/VPlanSLP.cpp index bc8277a33a7..ad3a85a6f76 100644 --- a/lib/Transforms/Vectorize/VPlanSLP.cpp +++ b/lib/Transforms/Vectorize/VPlanSLP.cpp @@ -240,12 +240,13 @@ static unsigned getLAScore(VPValue *V1, VPValue *V2, unsigned MaxLevel, std::pair VPlanSlp::getBest(OpMode Mode, VPValue *Last, - SmallVectorImpl &Candidates, + SmallPtrSetImpl &Candidates, VPInterleavedAccessInfo &IAI) { + assert((Mode == OpMode::Load || Mode == OpMode::Opcode) && + "Currently we only handle load and commutative opcodes"); LLVM_DEBUG(dbgs() << " getBest\n"); - VPValue *Best = Candidates[0]; - SmallVector BestCandidates; + SmallVector BestCandidates; LLVM_DEBUG(dbgs() << " Candidates for " << *cast(Last)->getUnderlyingInstr() << " "); for (auto *Candidate : Candidates) { @@ -265,34 +266,33 @@ VPlanSlp::getBest(OpMode Mode, VPValue *Last, if (BestCandidates.size() == 1) return {Mode, BestCandidates[0]}; - if (Mode == OpMode::Opcode) { - unsigned BestScore = 0; - for (unsigned Depth = 1; Depth < LookaheadMaxDepth; Depth++) { - unsigned PrevScore = ~0u; - bool AllSame = true; + VPValue *Best = nullptr; + unsigned BestScore = 0; + for (unsigned Depth = 1; Depth < LookaheadMaxDepth; Depth++) { + unsigned PrevScore = ~0u; + bool AllSame = true; - // FIXME: Avoid visiting the same operands multiple times. - for (auto *Candidate : BestCandidates) { - unsigned Score = getLAScore(Last, Candidate, Depth, IAI); - if (PrevScore == ~0u) - PrevScore = Score; - if (PrevScore != Score) - AllSame = false; + // FIXME: Avoid visiting the same operands multiple times. + for (auto *Candidate : BestCandidates) { + unsigned Score = getLAScore(Last, Candidate, Depth, IAI); + if (PrevScore == ~0u) PrevScore = Score; + if (PrevScore != Score) + AllSame = false; + PrevScore = Score; - if (Score > BestScore) { - BestScore = Score; - Best = Candidate; - } + if (Score > BestScore) { + BestScore = Score; + Best = Candidate; } - if (!AllSame) - break; } + if (!AllSame) + break; } LLVM_DEBUG(dbgs() << "Found best " << *cast(Best)->getUnderlyingInstr() << "\n"); - std::remove(Candidates.begin(), Candidates.end(), Best); + Candidates.erase(Best); return {Mode, Best}; } @@ -316,14 +316,13 @@ SmallVector VPlanSlp::reorderMultiNodeOps() { for (unsigned Lane = 1, E = MultiNodeOps[0].second.size(); Lane < E; ++Lane) { LLVM_DEBUG(dbgs() << " Finding best value for lane " << Lane << "\n"); - SmallVector Candidates; - Candidates.reserve(MultiNodeOps.size()); + SmallPtrSet Candidates; LLVM_DEBUG(dbgs() << " Candidates "); for (auto Ops : MultiNodeOps) { LLVM_DEBUG( dbgs() << *cast(Ops.second[Lane])->getUnderlyingInstr() << " "); - Candidates.push_back(Ops.second[Lane]); + Candidates.insert(Ops.second[Lane]); } LLVM_DEBUG(dbgs() << "\n");