diff options
author | Mohammad Shahid <Asghar-ahmad.Shahid@amd.com> | 2017-03-03 10:02:47 +0000 |
---|---|---|
committer | Mohammad Shahid <Asghar-ahmad.Shahid@amd.com> | 2017-03-03 10:02:47 +0000 |
commit | bdac9f30c0bf0251e59f84a101230dd61ebfcf16 (patch) | |
tree | 48b4edb4dce7218ddd3242f4c7dcdc22294e24ad /llvm/lib/Analysis/LoopAccessAnalysis.cpp | |
parent | ce52b80744cd23677286115c60cc13f34113f558 (diff) | |
download | llvm-bdac9f30c0bf0251e59f84a101230dd61ebfcf16.zip llvm-bdac9f30c0bf0251e59f84a101230dd61ebfcf16.tar.gz llvm-bdac9f30c0bf0251e59f84a101230dd61ebfcf16.tar.bz2 |
[SLP] Fixes the bug due to absence of in order uses of scalars which needs to be available
for VectorizeTree() API.This API uses it for proper mask computation to be used in shufflevector IR.
The fix is to compute the mask for out of order memory accesses while building the vectorizable tree
instead of actual vectorization of vectorizable tree.It also needs to recompute the proper Lane for
external use of vectorizable scalars based on shuffle mask.
Reviewers: mkuper
Differential Revision: https://reviews.llvm.org/D30159
Change-Id: Ide8773ce0ad3562f3cf4d1a0ad0f487e2f60ce5d
llvm-svn: 296863
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/LoopAccessAnalysis.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index a3ed412..0d588b9 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1040,7 +1040,8 @@ static unsigned getAddressSpaceOperand(Value *I) { bool llvm::sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL, ScalarEvolution &SE, - SmallVectorImpl<Value *> &Sorted) { + SmallVectorImpl<Value *> &Sorted, + SmallVectorImpl<unsigned> *Mask) { SmallVector<std::pair<int64_t, Value *>, 4> OffValPairs; OffValPairs.reserve(VL.size()); Sorted.reserve(VL.size()); @@ -1050,7 +1051,6 @@ bool llvm::sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL, Value *Ptr0 = getPointerOperand(VL[0]); const SCEV *Scev0 = SE.getSCEV(Ptr0); Value *Obj0 = GetUnderlyingObject(Ptr0, DL); - for (auto *Val : VL) { // The only kind of access we care about here is load. if (!isa<LoadInst>(Val)) @@ -1077,14 +1077,30 @@ bool llvm::sortMemAccesses(ArrayRef<Value *> VL, const DataLayout &DL, OffValPairs.emplace_back(Diff->getAPInt().getSExtValue(), Val); } - std::sort(OffValPairs.begin(), OffValPairs.end(), - [](const std::pair<int64_t, Value *> &Left, - const std::pair<int64_t, Value *> &Right) { - return Left.first < Right.first; + SmallVector<unsigned, 4> UseOrder(VL.size()); + for (unsigned i = 0; i < VL.size(); i++) { + UseOrder[i] = i; + } + + // Sort the memory accesses and keep the order of their uses in UseOrder. + std::sort(UseOrder.begin(), UseOrder.end(), + [&OffValPairs](unsigned Left, unsigned Right) { + return OffValPairs[Left].first < OffValPairs[Right].first; }); - for (auto &it : OffValPairs) - Sorted.push_back(it.second); + for (unsigned i = 0; i < VL.size(); i++) + Sorted.emplace_back(OffValPairs[UseOrder[i]].second); + + // Sort UseOrder to compute the Mask. + if (Mask) { + Mask->reserve(VL.size()); + for (unsigned i = 0; i < VL.size(); i++) + Mask->emplace_back(i); + std::sort(Mask->begin(), Mask->end(), + [&UseOrder](unsigned Left, unsigned Right) { + return UseOrder[Left] < UseOrder[Right]; + }); + } return true; } |