diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-21 06:11:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-21 06:11:43 +0000 |
commit | 4bc135e93beebdcb3b9c44745c5ccbc91199ac0b (patch) | |
tree | 99a9610859b715469b6a29960c60c55df478e888 /lib/CodeGen/BranchFolding.cpp | |
parent | 7c4fe259f8bfeae542cfef25c1f1e9b1ff25a39b (diff) |
don't break infinite loops
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31102 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index befcd00221..0752e3c9f7 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -499,7 +499,7 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { // If this branch is the only thing in its block, see if we can forward // other blocks across it. if (CurTBB && CurCond.empty() && CurFBB == 0 && - TII->isBranch(MBB->begin()->getOpcode())) { + TII->isBranch(MBB->begin()->getOpcode()) && CurTBB != &*MBB) { // This block may contain just an unconditional branch. Because there can // be 'non-branch terminators' in the block, try removing the branch and // then seeing if the block is empty. @@ -526,15 +526,28 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { } // Iterate through all the predecessors, revectoring each in-turn. - while (!MBB->pred_empty()) - ReplaceUsesOfBlockWith(*(MBB->pred_end()-1), MBB, CurTBB, TII); + 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); - ++NumBranchOpts; - MadeChange = true; - return; + if (DidChange) { + ++NumBranchOpts; + MadeChange = true; + if (!HasBranchToSelf) return; + } } // Add the branch back if the block is more than just an uncond branch. |