diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-11-10 21:40:01 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-11-10 21:40:01 +0000 |
| commit | 7ca174c49440e447ac90ce2cc4c70d950db28cb2 (patch) | |
| tree | fa8b2d2016d562a065dc58d23248747a7829c7e1 /lib | |
| parent | 8a0ab8392c91e1bae7901cedd6a12ba3aee2a1fd (diff) | |
| download | external_llvm-7ca174c49440e447ac90ce2cc4c70d950db28cb2.zip external_llvm-7ca174c49440e447ac90ce2cc4c70d950db28cb2.tar.gz external_llvm-7ca174c49440e447ac90ce2cc4c70d950db28cb2.tar.bz2 | |
Make jump threading eliminate blocks that just contain phi nodes,
debug intrinsics, and an unconditional branch when possible. This
reuses the TryToSimplifyUncondBranchFromEmptyBlock function split
out of simplifycfg.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86722 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Transforms/Scalar/JumpThreading.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/JumpThreading.cpp b/lib/Transforms/Scalar/JumpThreading.cpp index 9c9461fa..1d89399 100644 --- a/lib/Transforms/Scalar/JumpThreading.cpp +++ b/lib/Transforms/Scalar/JumpThreading.cpp @@ -115,6 +115,7 @@ bool JumpThreading::runOnFunction(Function &F) { bool Changed = false; for (Function::iterator I = F.begin(), E = F.end(); I != E;) { BasicBlock *BB = I; + // Thread all of the branches we can over this block. while (ProcessBlock(BB)) Changed = true; @@ -129,6 +130,26 @@ bool JumpThreading::runOnFunction(Function &F) { LoopHeaders.erase(BB); DeleteDeadBlock(BB); Changed = true; + } else if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) { + // Can't thread an unconditional jump, but if the block is "almost + // empty", we can replace uses of it with uses of the successor and make + // this dead. + if (BI->isUnconditional() && + BB != &BB->getParent()->getEntryBlock()) { + BasicBlock::iterator BBI = BB->getFirstNonPHI(); + // Ignore dbg intrinsics. + while (isa<DbgInfoIntrinsic>(BBI)) + ++BBI; + // If the terminator is the only non-phi instruction, try to nuke it. + if (BBI->isTerminator()) { + bool Erased = LoopHeaders.erase(BB); + + if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) + Changed = true; + else if (Erased) + LoopHeaders.insert(BB); + } + } } } AnotherIteration = Changed; |
