diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-28 17:32:47 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-28 17:32:47 +0000 |
commit | cf420cca572b061fdd63587cb90904c641b6e216 (patch) | |
tree | 970c8b20df75264bb7a13b5cf9052a83e4f35cd9 /lib/CodeGen/BranchFolding.cpp | |
parent | c24ff8ed12d01a1b1d2fac57876fc7580024ec49 (diff) |
improve deletion of blocks that just contain branches by knowing that
the pred block doesn't fall through into them if it's a jumptable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31263 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 5cad24845d..07d44dc5d7 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -534,43 +534,48 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { // completely eliminate the block is when the block before this one // falls through into MBB and we can't understand the prior block's branch // condition. - if (MBB->empty() && (!PriorUnAnalyzable || !PrevBB.isSuccessor(MBB))) { - // If the prior block falls through into us, turn it into an - // explicit branch to us to make updates simpler. - if (PrevBB.isSuccessor(MBB) && PriorTBB != MBB && PriorFBB != MBB) { - if (PriorTBB == 0) { - assert(PriorCond.empty() && PriorFBB == 0 && "Bad branch analysis"); - PriorTBB = MBB; - } else { - assert(PriorFBB == 0 && "Machine CFG out of date!"); - PriorFBB = MBB; + if (MBB->empty()) { + bool PredHasNoFallThrough = TII->BlockHasNoFallThrough(PrevBB); + if (PredHasNoFallThrough || !PriorUnAnalyzable || + !PrevBB.isSuccessor(MBB)) { + // If the prior block falls through into us, turn it into an + // explicit branch to us to make updates simpler. + if (!PredHasNoFallThrough && PrevBB.isSuccessor(MBB) && + PriorTBB != MBB && PriorFBB != MBB) { + if (PriorTBB == 0) { + assert(PriorCond.empty() && PriorFBB == 0 && "Bad branch analysis"); + PriorTBB = MBB; + } else { + assert(PriorFBB == 0 && "Machine CFG out of date!"); + PriorFBB = MBB; + } + TII->RemoveBranch(PrevBB); + TII->InsertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond); } - TII->RemoveBranch(PrevBB); - TII->InsertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond); - } - // Iterate through all the predecessors, revectoring each in-turn. - MachineBasicBlock::pred_iterator PI = MBB->pred_begin(); - bool DidChange = false; - bool HasBranchToSelf = false; - while (PI != MBB->pred_end()) { - if (*PI == MBB) { - // If this block has an uncond branch to itself, leave it. - ++PI; - HasBranchToSelf = true; - } else { - DidChange = true; - ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII); + // Iterate through all the predecessors, revectoring each in-turn. + MachineBasicBlock::pred_iterator PI = MBB->pred_begin(); + bool DidChange = false; + bool HasBranchToSelf = false; + while (PI != MBB->pred_end()) { + if (*PI == MBB) { + // If this block has an uncond branch to itself, leave it. + ++PI; + HasBranchToSelf = true; + } else { + DidChange = true; + ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII); + } } - } - // Change any jumptables to go to the new MBB. - MBB->getParent()->getJumpTableInfo()->ReplaceMBBInJumpTables(MBB, - CurTBB); - if (DidChange) { - ++NumBranchOpts; - MadeChange = true; - if (!HasBranchToSelf) return; + // Change any jumptables to go to the new MBB. + MBB->getParent()->getJumpTableInfo()->ReplaceMBBInJumpTables(MBB, + CurTBB); + if (DidChange) { + ++NumBranchOpts; + MadeChange = true; + if (!HasBranchToSelf) return; + } } } |