From 00f63b1b84d059a1ffa572e76708e03750a9e523 Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Mon, 11 Feb 2013 05:29:51 +0000 Subject: [PATCH] BBVectorize: Remove the linear searches from pair connection searching This removes the last of the linear searches over ranges of std::multimap iterators, giving a 7% speedup on the doduc.bc input from PR15222. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174859 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/BBVectorize.cpp | 35 ++++++++---------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/Transforms/Vectorize/BBVectorize.cpp b/lib/Transforms/Vectorize/BBVectorize.cpp index 0d3a4449db7..9da4c372aee 100644 --- a/lib/Transforms/Vectorize/BBVectorize.cpp +++ b/lib/Transforms/Vectorize/BBVectorize.cpp @@ -281,6 +281,7 @@ namespace { void computePairsConnectedTo( std::multimap &CandidatePairs, + DenseSet &CandidatePairsSet, std::vector &PairableInsts, std::multimap &ConnectedPairs, DenseMap &PairConnectionTypes, @@ -666,19 +667,6 @@ namespace { } } - // Returns true if J is the second element in some pair referenced by - // some multimap pair iterator pair. - template - bool isSecondInIteratorPair(V J, std::pair< - typename std::multimap::iterator, - typename std::multimap::iterator> PairRange) { - for (typename std::multimap::iterator K = PairRange.first; - K != PairRange.second; ++K) - if (K->second == J) return true; - - return false; - } - bool isPureIEChain(InsertElementInst *IE) { InsertElementInst *IENext = IE; do { @@ -1253,6 +1241,7 @@ namespace { // output of PI or PJ. void BBVectorize::computePairsConnectedTo( std::multimap &CandidatePairs, + DenseSet &CandidatePairsSet, std::vector &PairableInsts, std::multimap &ConnectedPairs, DenseMap &PairConnectionTypes, @@ -1274,8 +1263,6 @@ namespace { continue; } - VPIteratorPair IPairRange = CandidatePairs.equal_range(*I); - // For each use of the first variable, look for uses of the second // variable... for (Value::use_iterator J = P.second->use_begin(), @@ -1284,17 +1271,15 @@ namespace { P.second == SJ->getPointerOperand()) continue; - VPIteratorPair JPairRange = CandidatePairs.equal_range(*J); - // Look for : - if (isSecondInIteratorPair(*J, IPairRange)) { + if (CandidatePairsSet.count(ValuePair(*I, *J))) { VPPair VP(P, ValuePair(*I, *J)); ConnectedPairs.insert(VP); PairConnectionTypes.insert(VPPairWithType(VP, PairConnectionDirect)); } // Look for : - if (isSecondInIteratorPair(*I, JPairRange)) { + if (CandidatePairsSet.count(ValuePair(*J, *I))) { VPPair VP(P, ValuePair(*J, *I)); ConnectedPairs.insert(VP); PairConnectionTypes.insert(VPPairWithType(VP, PairConnectionSwap)); @@ -1309,7 +1294,7 @@ namespace { P.first == SJ->getPointerOperand()) continue; - if (isSecondInIteratorPair(*J, IPairRange)) { + if (CandidatePairsSet.count(ValuePair(*I, *J))) { VPPair VP(P, ValuePair(*I, *J)); ConnectedPairs.insert(VP); PairConnectionTypes.insert(VPPairWithType(VP, PairConnectionSplat)); @@ -1328,14 +1313,12 @@ namespace { P.second == SI->getPointerOperand()) continue; - VPIteratorPair IPairRange = CandidatePairs.equal_range(*I); - for (Value::use_iterator J = P.second->use_begin(); J != E; ++J) { if ((SJ = dyn_cast(*J)) && P.second == SJ->getPointerOperand()) continue; - if (isSecondInIteratorPair(*J, IPairRange)) { + if (CandidatePairsSet.count(ValuePair(*I, *J))) { VPPair VP(P, ValuePair(*I, *J)); ConnectedPairs.insert(VP); PairConnectionTypes.insert(VPPairWithType(VP, PairConnectionSplat)); @@ -1352,6 +1335,10 @@ namespace { std::vector &PairableInsts, std::multimap &ConnectedPairs, DenseMap &PairConnectionTypes) { + DenseSet CandidatePairsSet; + for (std::multimap::iterator I = CandidatePairs.begin(), + E = CandidatePairs.end(); I != E; ++I) + CandidatePairsSet.insert(*I); for (std::vector::iterator PI = PairableInsts.begin(), PE = PairableInsts.end(); PI != PE; ++PI) { @@ -1359,7 +1346,7 @@ namespace { for (std::multimap::iterator P = choiceRange.first; P != choiceRange.second; ++P) - computePairsConnectedTo(CandidatePairs, PairableInsts, + computePairsConnectedTo(CandidatePairs, CandidatePairsSet, PairableInsts, ConnectedPairs, PairConnectionTypes, *P); }