From a0d44fe4cd92c11466b82af4f5089af845a2eeb5 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Wed, 27 Nov 2013 05:35:16 +0000 Subject: Merging r195791: ------------------------------------------------------------------------ r195791 | nadav | 2013-11-26 14:24:25 -0800 (Tue, 26 Nov 2013) | 4 lines PR1860 - We can't save a list of ExtractElement instructions to CSE because some of these instructions may be removed and optimized in future iterations. Instead we save a list of basic blocks that we need to CSE. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195818 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Vectorize/SLPVectorizer.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'lib/Transforms') diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 699be956c0..9f18596098 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -520,6 +520,8 @@ private: /// Holds all of the instructions that we gathered. SetVector GatherSeq; + /// A list of blocks that we are going to CSE. + SmallSet CSEBlocks; /// Numbers instructions in different blocks. DenseMap BlocksNumbers; @@ -1274,6 +1276,7 @@ Value *BoUpSLP::Gather(ArrayRef VL, VectorType *Ty) { Vec = Builder.CreateInsertElement(Vec, VL[i], Builder.getInt32(i)); if (Instruction *Insrt = dyn_cast(Vec)) { GatherSeq.insert(Insrt); + CSEBlocks.insert(Insrt->getParent()); // Add to our 'need-to-extract' list. if (ScalarToTreeEntry.count(VL[i])) { @@ -1588,8 +1591,7 @@ Value *BoUpSLP::vectorizeTree() { if (PHINode *PN = dyn_cast(Vec)) { Builder.SetInsertPoint(PN->getParent()->getFirstInsertionPt()); Value *Ex = Builder.CreateExtractElement(Vec, Lane); - if (Instruction *Ins = dyn_cast(Ex)) - GatherSeq.insert(Ins); + CSEBlocks.insert(PN->getParent()); User->replaceUsesOfWith(Scalar, Ex); } else if (isa(Vec)){ if (PHINode *PH = dyn_cast(User)) { @@ -1597,23 +1599,20 @@ Value *BoUpSLP::vectorizeTree() { if (PH->getIncomingValue(i) == Scalar) { Builder.SetInsertPoint(PH->getIncomingBlock(i)->getTerminator()); Value *Ex = Builder.CreateExtractElement(Vec, Lane); - if (Instruction *Ins = dyn_cast(Ex)) - GatherSeq.insert(Ins); + CSEBlocks.insert(PH->getIncomingBlock(i)); PH->setOperand(i, Ex); } } } else { Builder.SetInsertPoint(cast(User)); Value *Ex = Builder.CreateExtractElement(Vec, Lane); - if (Instruction *Ins = dyn_cast(Ex)) - GatherSeq.insert(Ins); + CSEBlocks.insert(cast(User)->getParent()); User->replaceUsesOfWith(Scalar, Ex); } } else { Builder.SetInsertPoint(F->getEntryBlock().begin()); Value *Ex = Builder.CreateExtractElement(Vec, Lane); - if (Instruction *Ins = dyn_cast(Ex)) - GatherSeq.insert(Ins); + CSEBlocks.insert(&F->getEntryBlock()); User->replaceUsesOfWith(Scalar, Ex); } @@ -1676,9 +1675,6 @@ public: void BoUpSLP::optimizeGatherSequence() { DEBUG(dbgs() << "SLP: Optimizing " << GatherSeq.size() << " gather sequences instructions.\n"); - // Keep a list of visited BBs to run CSE on. It is typically small. - SmallPtrSet VisitedBBs; - SmallVector CSEWorkList; // LICM InsertElementInst sequences. for (SetVector::iterator it = GatherSeq.begin(), e = GatherSeq.end(); it != e; ++it) { @@ -1687,9 +1683,6 @@ void BoUpSLP::optimizeGatherSequence() { if (!Insert) continue; - if (VisitedBBs.insert(Insert->getParent())) - CSEWorkList.push_back(Insert->getParent()); - // Check if this block is inside a loop. Loop *L = LI->getLoopFor(Insert->getParent()); if (!L) @@ -1716,6 +1709,7 @@ void BoUpSLP::optimizeGatherSequence() { // Sort blocks by domination. This ensures we visit a block after all blocks // dominating it are visited. + SmallVector CSEWorkList(CSEBlocks.begin(), CSEBlocks.end()); std::stable_sort(CSEWorkList.begin(), CSEWorkList.end(), DTCmp(DT)); // Perform O(N^2) search over the gather sequences and merge identical @@ -1731,8 +1725,7 @@ void BoUpSLP::optimizeGatherSequence() { // For all instructions in blocks containing gather sequences: for (BasicBlock::iterator it = BB->begin(), e = BB->end(); it != e;) { Instruction *In = it++; - if ((!isa(In) && !isa(In)) || - !GatherSeq.count(In)) + if (!isa(In) && !isa(In)) continue; // Check if we can replace this instruction with any of the @@ -1754,6 +1747,8 @@ void BoUpSLP::optimizeGatherSequence() { } } } + CSEBlocks.clear(); + GatherSeq.clear(); } /// The SLPVectorizer Pass. -- cgit v1.2.3