diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-17 18:16:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-17 18:16:40 +0000 |
commit | ffddf6ba1c58b42dcfd071972754649c3ca5dff7 (patch) | |
tree | 60c9dd5a9525383b48cb4ef486eca66ee37be2c3 /lib/CodeGen/BranchFolding.cpp | |
parent | 065a13fd6902c8a858a8e5009ab1d87b859a1ac2 (diff) |
Enable deleting branches to successor blocks. With the previous patches,
branch folding can now compile stuff like this:
void foo(int W, int X, int Y, int Z) {
if (W & 1) {
for (; X;--X) bar();
} else if (W & 2) {
for (; Y;--Y) bar();
} else if (W & 4) {
for (; Z;--Z) bar();
} else if (W & 8) {
for (; W;--W) bar();
}
if (W) {
bar();
}
}
contrived testcase where loops exits all end up merging together. To have
the loop merges be:
...
cmplw cr0, r30, r27
bne cr0, LBB1_14 ;bb38
LBB1_16: ;cond_next48.loopexit
mr r27, r29
LBB1_20: ;cond_next48
cmplwi cr0, r27, 0
beq cr0, LBB1_22 ;UnifiedReturnBlock
...
instead of:
...
cmplw cr0, r30, r27
bne cr0, LBB1_14 ;bb38
LBB1_16: ;cond_next48.loopexit
mr r27, r29
b LBB1_20 ;cond_next48
LBB1_17: ;cond_next48.loopexit1
b LBB1_20 ;cond_next48
LBB1_18: ;cond_next48.loopexit2
b LBB1_20 ;cond_next48
LBB1_19: ;cond_next48.loopexit3
LBB1_20: ;cond_next48
cmplwi cr0, r27, 0
beq cr0, LBB1_22 ;UnifiedReturnBlock
...
This is CodeGen/PowerPC/branch-opt.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31006 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index b589c03f56..725317378c 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -137,10 +137,11 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { // Check to see if we can simplify the terminator of the block before this // one. -#if 0 + MachineBasicBlock &PrevBB = *prior(MBB); + MachineBasicBlock *PriorTBB = 0, *PriorFBB = 0; std::vector<MachineOperand> PriorCond; - if (!TII->AnalyzeBranch(*prior(MBB), PriorTBB, PriorFBB, PriorCond)) { + if (!TII->AnalyzeBranch(PrevBB, PriorTBB, PriorFBB, PriorCond)) { // If the previous branch is conditional and both conditions go to the same // destination, remove the branch, replacing it with an unconditional one. if (PriorTBB && PriorTBB == PriorFBB) { @@ -160,8 +161,6 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { return OptimizeBlock(MBB); } } -#endif - #if 0 |