summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-11 21:04:37 +0000
committerChris Lattner <sabre@nondot.org>2009-10-11 21:04:37 +0000
commitbb058d3a23f0a7d31804f8e51886820c9e2088b7 (patch)
tree128d3ac10878120952fa0ebc429bcfe51cb9e92d /llvm/lib/Transforms
parent8b3081350ece03d314e701735c9d7cadd0b4ad3c (diff)
downloadbcm5719-llvm-bb058d3a23f0a7d31804f8e51886820c9e2088b7.tar.gz
bcm5719-llvm-bb058d3a23f0a7d31804f8e51886820c9e2088b7.zip
populate instcombine's initial worklist more carefully, causing
it to visit instructions from the start of the function to the end of the function in the first path. This greatly speeds up some pathological cases (e.g. PR5150). llvm-svn: 83790
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 06a5660f72e..9d883543c80 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -12681,6 +12681,9 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
const TargetData *TD) {
SmallVector<BasicBlock*, 256> Worklist;
Worklist.push_back(BB);
+
+ std::vector<Instruction*> InstrsForInstCombineWorklist;
+ InstrsForInstCombineWorklist.reserve(128);
while (!Worklist.empty()) {
BB = Worklist.back();
@@ -12727,7 +12730,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
DBI_Prev = 0;
}
- IC.Worklist.Add(Inst);
+ InstrsForInstCombineWorklist.push_back(Inst);
}
// Recursively visit successors. If this is a branch or switch on a
@@ -12759,6 +12762,16 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
Worklist.push_back(TI->getSuccessor(i));
}
+
+ // Once we've found all of the instructions to add to instcombine's worklist,
+ // add them in reverse order. This way instcombine will visit from the top
+ // of the function down. This jives well with the way that it adds all uses
+ // of instructions to the worklist after doing a transformation, thus avoiding
+ // some N^2 behavior in pathological cases.
+ for (std::vector<Instruction*>::reverse_iterator
+ I = InstrsForInstCombineWorklist.rbegin(),
+ E = InstrsForInstCombineWorklist.rend(); I != E; ++I)
+ IC.Worklist.Add(*I);
}
bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
OpenPOWER on IntegriCloud