[llvm-commits] CVS: llvm/lib/CodeGen/BranchFolding.cpp
Chris Lattner
sabre at nondot.org
Fri Oct 20 23:11:57 PDT 2006
Changes in directory llvm/lib/CodeGen:
BranchFolding.cpp updated: 1.18 -> 1.19
---
Log message:
don't break infinite loops
---
Diffs of the changes: (+19 -6)
BranchFolding.cpp | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.18 llvm/lib/CodeGen/BranchFolding.cpp:1.19
--- llvm/lib/CodeGen/BranchFolding.cpp:1.18 Sat Oct 21 00:54:00 2006
+++ llvm/lib/CodeGen/BranchFolding.cpp Sat Oct 21 01:11:43 2006
@@ -499,7 +499,7 @@
// 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 @@
}
// 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.
More information about the llvm-commits
mailing list