aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorNAKAMURA Takumi <geek4civic@gmail.com>2017-10-16 09:50:01 +0000
committerNAKAMURA Takumi <geek4civic@gmail.com>2017-10-16 09:50:01 +0000
commit904a9e2ef5169c744c69a38e4373872e20bbd381 (patch)
tree23fffe5be437f071d6c86fffa14a049b246bd363 /lib/Transforms
parentefa58149ae688aa73d8faf8f6de608f50349d392 (diff)
downloadllvm-904a9e2ef5169c744c69a38e4373872e20bbd381.tar.gz
Revert rL315894, "SLPVectorizer.cpp: Try to appease stage2-3 difference. (D38586)"
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315896 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Vectorize/SLPVectorizer.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 8643e60308f..6055aff8b9b 100644
--- a/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -588,7 +588,7 @@ public:
unsigned getTreeSize() const { return VectorizableTree.size(); }
/// \brief Perform LICM and CSE on the newly generated gather sequences.
- void optimizeGatherSequence(Function &F);
+ void optimizeGatherSequence();
/// \returns true if it is beneficial to reverse the vector order.
bool shouldReorder() const {
@@ -3299,7 +3299,7 @@ BoUpSLP::vectorizeTree(ExtraValueToDebugLocsMap &ExternallyUsedValues) {
return VectorizableTree[0].VectorizedValue;
}
-void BoUpSLP::optimizeGatherSequence(Function &F) {
+void BoUpSLP::optimizeGatherSequence() {
DEBUG(dbgs() << "SLP: Optimizing " << GatherSeq.size()
<< " gather sequences instructions.\n");
// LICM InsertElementInst sequences.
@@ -3333,16 +3333,30 @@ void BoUpSLP::optimizeGatherSequence(Function &F) {
Insert->moveBefore(PreHeader->getTerminator());
}
+ // Make a list of all reachable blocks in our CSE queue.
+ SmallVector<const DomTreeNode *, 8> CSEWorkList;
+ CSEWorkList.reserve(CSEBlocks.size());
+ for (BasicBlock *BB : CSEBlocks)
+ if (DomTreeNode *N = DT->getNode(BB)) {
+ assert(DT->isReachableFromEntry(N));
+ CSEWorkList.push_back(N);
+ }
+
+ // Sort blocks by domination. This ensures we visit a block after all blocks
+ // dominating it are visited.
+ std::stable_sort(CSEWorkList.begin(), CSEWorkList.end(),
+ [this](const DomTreeNode *A, const DomTreeNode *B) {
+ return DT->properlyDominates(A, B);
+ });
+
// Perform O(N^2) search over the gather sequences and merge identical
// instructions. TODO: We can further optimize this scan if we split the
// instructions into different buckets based on the insert lane.
SmallVector<Instruction *, 16> Visited;
- ReversePostOrderTraversal<Function *> RPOT(&F);
- for (auto BB : RPOT) {
- // Traverse CSEBlocks by RPOT order.
- if (!CSEBlocks.count(BB))
- continue;
-
+ for (auto I = CSEWorkList.begin(), E = CSEWorkList.end(); I != E; ++I) {
+ assert((I == CSEWorkList.begin() || !DT->dominates(*I, *std::prev(I))) &&
+ "Worklist not sorted properly!");
+ BasicBlock *BB = (*I)->getBlock();
// For all instructions in blocks containing gather sequences:
for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e;) {
Instruction *In = &*it++;
@@ -4208,7 +4222,7 @@ bool SLPVectorizerPass::runImpl(Function &F, ScalarEvolution *SE_,
}
if (Changed) {
- R.optimizeGatherSequence(F);
+ R.optimizeGatherSequence();
DEBUG(dbgs() << "SLP: vectorized \"" << F.getName() << "\"\n");
DEBUG(verifyFunction(F));
}