summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-11-18 21:30:35 +0000
committerChris Lattner <sabre@nondot.org>2006-11-18 21:30:35 +0000
commit7acdc17fe48c0b9cdbfa50251aae689b7e57998f (patch)
tree0a501794b07594cb42ff82bdfa2d2da0767a4de0 /llvm/lib/CodeGen/BranchFolding.cpp
parent47ce26158f50079ffc7c2d8df221b26c75ef111e (diff)
downloadbcm5719-llvm-7acdc17fe48c0b9cdbfa50251aae689b7e57998f.tar.gz
bcm5719-llvm-7acdc17fe48c0b9cdbfa50251aae689b7e57998f.zip
make the previous change more aggressive, moving any block with no fallthrough.
This speeds up yacr2 by 7% on a core2. llvm-svn: 31856
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 04bed9c8a5b..d43b6879f3f 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -593,15 +593,15 @@ bool BranchFolder::CanFallThrough(MachineBasicBlock *CurBB) {
static bool IsBetterFallthrough(MachineBasicBlock *MBB1,
MachineBasicBlock *MBB2,
const TargetInstrInfo &TII) {
- // Right now, we use a simple heuristic. If MBB ends with a return, and
- // MBB2 doesn't, we prefer to fall through into MBB1. This allows us to
+ // Right now, we use a simple heuristic. If MBB2 ends with a call, and
+ // MBB1 doesn't, we prefer to fall through into MBB1. This allows us to
// optimize branches that branch to either a return block or an assert block
// into a fallthrough to the return.
if (MBB1->empty() || MBB2->empty()) return false;
MachineInstr *MBB1I = --MBB1->end();
MachineInstr *MBB2I = --MBB2->end();
- return TII.isReturn(MBB1I->getOpcode()) && !TII.isReturn(MBB2I->getOpcode());
+ return TII.isCall(MBB2I->getOpcode()) && !TII.isCall(MBB1I->getOpcode());
}
/// OptimizeBlock - Analyze and optimize control flow related to the specified
@@ -694,15 +694,17 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
}
}
- // If this block has no successors (e.g. it is a return block or ends with
- // a call to a no-return function like abort or __cxa_throw) and if the pred
- // falls through into this block, and if it would otherwise fall through
- // into the block after this, move this block to the end of the function.
+ // If this block doesn't fall through (e.g. it ends with an uncond branch or
+ // has no successors) and if the pred falls through into this block, and if
+ // it would otherwise fall through into the block after this, move this
+ // block to the end of the function.
+ //
// We consider it more likely that execution will stay in the function (e.g.
// due to loops) than it is to exit it. This asserts in loops etc, moving
// the assert condition out of the loop body.
- if (MBB->succ_empty() && !PriorCond.empty() && PriorFBB == 0 &&
- MachineFunction::iterator(PriorTBB) == FallThrough) {
+ if (!PriorCond.empty() && PriorFBB == 0 &&
+ MachineFunction::iterator(PriorTBB) == FallThrough &&
+ !CanFallThrough(MBB)) {
// We have to be careful that the succs of PredBB aren't both no-successor
// blocks. If neither have successors and if PredBB is the second from
// last block in the function, we'd just keep swapping the two blocks for
OpenPOWER on IntegriCloud