summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp27
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");
OpenPOWER on IntegriCloud