diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2018-01-16 18:17:01 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2018-01-16 18:17:01 +0000 |
commit | 6977dbcc7b831d9113b6a608afed280f00f43406 (patch) | |
tree | 409b0316457a1f7320ee7e44e0fd3e341a2c6624 /llvm/lib/Transforms/Vectorize | |
parent | d60d1baadb8001d2a13f4980889cea69df0a3c4e (diff) | |
download | bcm5719-llvm-6977dbcc7b831d9113b6a608afed280f00f43406.tar.gz bcm5719-llvm-6977dbcc7b831d9113b6a608afed280f00f43406.zip |
[SLP] Fix for PR32164: Improve vectorization of reverse order of extract operations.
Summary: Sometimes vectorization of insertelement instructions with extractelement operands may produce an extra shuffle operation, if these operands are in the reverse order. Patch tries to improve this situation by the reordering of the operands to remove this extra shuffle operation.
Reviewers: mkuper, hfinkel, RKSimon, spatel
Subscribers: mzolotukhin, llvm-commits
Differential Revision: https://reviews.llvm.org/D33954
llvm-svn: 322579
Diffstat (limited to 'llvm/lib/Transforms/Vectorize')
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 809facb0341..90f84e00b44 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -585,8 +585,7 @@ public: ScalarToTreeEntry.clear(); MustGather.clear(); ExternalUses.clear(); - NumLoadsWantToKeepOrder = 0; - NumLoadsWantToChangeOrder = 0; + NumOpsWantToKeepOrder.clear(); for (auto &Iter : BlocksSchedules) { BlockScheduling *BS = Iter.second.get(); BS->clear(); @@ -601,7 +600,12 @@ public: /// \returns true if it is beneficial to reverse the vector order. bool shouldReorder() const { - return NumLoadsWantToChangeOrder > NumLoadsWantToKeepOrder; + return std::accumulate( + NumOpsWantToKeepOrder.begin(), NumOpsWantToKeepOrder.end(), 0, + [](int Val1, + const decltype(NumOpsWantToKeepOrder)::value_type &Val2) { + return Val1 + (Val2.second < 0 ? 1 : -1); + }) > 0; } /// \return The vector element size in bits to use when vectorizing the @@ -1201,11 +1205,10 @@ private: /// List of users to ignore during scheduling and that don't need extracting. ArrayRef<Value *> UserIgnoreList; - // Number of load bundles that contain consecutive loads. - int NumLoadsWantToKeepOrder = 0; - - // Number of load bundles that contain consecutive loads in reversed order. - int NumLoadsWantToChangeOrder = 0; + /// Number of operation bundles that contain consecutive operations - number + /// of operation bundles that contain consecutive operations in reversed + /// order. + DenseMap<unsigned, int> NumOpsWantToKeepOrder; // Analysis and block reference. Function *F; @@ -1543,7 +1546,11 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, bool Reuse = canReuseExtract(VL, VL0); if (Reuse) { DEBUG(dbgs() << "SLP: Reusing extract sequence.\n"); + ++NumOpsWantToKeepOrder[S.Opcode]; } else { + SmallVector<Value *, 4> ReverseVL(VL.rbegin(), VL.rend()); + if (canReuseExtract(ReverseVL, VL0)) + --NumOpsWantToKeepOrder[S.Opcode]; BS.cancelScheduling(VL, VL0); } newTreeEntry(VL, Reuse, UserTreeIdx); @@ -1593,7 +1600,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, } if (Consecutive) { - ++NumLoadsWantToKeepOrder; + ++NumOpsWantToKeepOrder[S.Opcode]; newTreeEntry(VL, true, UserTreeIdx); DEBUG(dbgs() << "SLP: added a vector of loads.\n"); return; @@ -1612,7 +1619,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, newTreeEntry(VL, false, UserTreeIdx); if (ReverseConsecutive) { - ++NumLoadsWantToChangeOrder; + --NumOpsWantToKeepOrder[S.Opcode]; DEBUG(dbgs() << "SLP: Gathering reversed loads.\n"); } else { DEBUG(dbgs() << "SLP: Gathering non-consecutive loads.\n"); |