summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2017-11-09 19:07:16 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2017-11-09 19:07:16 +0000
commit0bd90044254fedb089c7a4c65f43956e1d5dee47 (patch)
treeeeff87685e8895e1505e8b11f78eb86be4c72a5f /llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
parentbbb66ad7b2daba4b6f7ccfb8d15fa656c99ef00b (diff)
downloadbcm5719-llvm-0bd90044254fedb089c7a4c65f43956e1d5dee47.tar.gz
bcm5719-llvm-0bd90044254fedb089c7a4c65f43956e1d5dee47.zip
[SLP] Fix PR23510: Try to find best possible vectorizable stores.
Summary: The analysis of the store sequence goes in straight order - from the first store to the last. Bu the best opportunity for vectorization will happen if we're going to use reverse order - from last store to the first. It may be best because usually users have some initialization part + further processing and this first initialization may confuse SLP vectorizer. Reviewers: RKSimon, hfinkel, mkuper, spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D39606 llvm-svn: 317821
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp')
-rw-r--r--llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 6c607062f25..6a21fefd494 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -4316,7 +4316,8 @@ bool SLPVectorizerPass::vectorizeStoreChain(ArrayRef<Value *> Chain, BoUpSLP &R,
bool SLPVectorizerPass::vectorizeStores(ArrayRef<StoreInst *> Stores,
BoUpSLP &R) {
- SetVector<StoreInst *> Heads, Tails;
+ SetVector<StoreInst *> Heads;
+ SmallDenseSet<StoreInst *> Tails;
SmallDenseMap<StoreInst *, StoreInst *> ConsecutiveChain;
// We may run into multiple chains that merge into a single chain. We mark the
@@ -4324,45 +4325,51 @@ bool SLPVectorizerPass::vectorizeStores(ArrayRef<StoreInst *> Stores,
BoUpSLP::ValueSet VectorizedStores;
bool Changed = false;
- // Do a quadratic search on all of the given stores and find
+ // Do a quadratic search on all of the given stores in reverse order and find
// all of the pairs of stores that follow each other.
SmallVector<unsigned, 16> IndexQueue;
- for (unsigned i = 0, e = Stores.size(); i < e; ++i) {
- IndexQueue.clear();
+ unsigned E = Stores.size();
+ IndexQueue.resize(E - 1);
+ for (unsigned I = E; I > 0; --I) {
+ unsigned Idx = I - 1;
// If a store has multiple consecutive store candidates, search Stores
- // array according to the sequence: from i+1 to e, then from i-1 to 0.
+ // array according to the sequence: Idx-1, Idx+1, Idx-2, Idx+2, ...
// This is because usually pairing with immediate succeeding or preceding
// candidate create the best chance to find slp vectorization opportunity.
- unsigned j = 0;
- for (j = i + 1; j < e; ++j)
- IndexQueue.push_back(j);
- for (j = i; j > 0; --j)
- IndexQueue.push_back(j - 1);
-
- for (auto &k : IndexQueue) {
- if (isConsecutiveAccess(Stores[i], Stores[k], *DL, *SE)) {
- Tails.insert(Stores[k]);
- Heads.insert(Stores[i]);
- ConsecutiveChain[Stores[i]] = Stores[k];
+ unsigned Offset = 1;
+ unsigned Cnt = 0;
+ for (unsigned J = 0; J < E - 1; ++J, ++Offset) {
+ if (Idx >= Offset) {
+ IndexQueue[Cnt] = Idx - Offset;
+ ++Cnt;
+ }
+ if (Idx + Offset < E) {
+ IndexQueue[Cnt] = Idx + Offset;
+ ++Cnt;
+ }
+ }
+
+ for (auto K : IndexQueue) {
+ if (isConsecutiveAccess(Stores[K], Stores[Idx], *DL, *SE)) {
+ Tails.insert(Stores[Idx]);
+ Heads.insert(Stores[K]);
+ ConsecutiveChain[Stores[K]] = Stores[Idx];
break;
}
}
}
// For stores that start but don't end a link in the chain:
- for (SetVector<StoreInst *>::iterator it = Heads.begin(), e = Heads.end();
- it != e; ++it) {
- if (Tails.count(*it))
+ for (auto *SI : llvm::reverse(Heads)) {
+ if (Tails.count(SI))
continue;
// We found a store instr that starts a chain. Now follow the chain and try
// to vectorize it.
BoUpSLP::ValueList Operands;
- StoreInst *I = *it;
+ StoreInst *I = SI;
// Collect the chain into a list.
- while (Tails.count(I) || Heads.count(I)) {
- if (VectorizedStores.count(I))
- break;
+ while ((Tails.count(I) || Heads.count(I)) && !VectorizedStores.count(I)) {
Operands.push_back(I);
// Move to the next value in the chain.
I = ConsecutiveChain[I];
OpenPOWER on IntegriCloud