diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-21 05:43:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-21 05:43:30 +0000 |
commit | 3ca52185af1442d1bc6db6445c0f88bd72857dc3 (patch) | |
tree | 1d291daa399269879cfb18787652aa923ba5b43f /llvm/lib | |
parent | d881660366bc0fc714f1d4d6e4f12530ecd99eb7 (diff) | |
download | bcm5719-llvm-3ca52185af1442d1bc6db6445c0f88bd72857dc3.tar.gz bcm5719-llvm-3ca52185af1442d1bc6db6445c0f88bd72857dc3.zip |
Transform code like:
jle FOO
jmp BAR
BAR:
into:
jle FOO
BAR:
... whoa!
llvm-svn: 31098
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/BranchFolding.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index bcf0a846bfd..5be6baf64c2 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -30,7 +30,7 @@ using namespace llvm; static Statistic<> NumDeadBlocks("branchfold", "Number of dead blocks removed"); static Statistic<> NumBranchOpts("branchfold", "Number of branches optimized"); static Statistic<> NumTailMerge ("branchfold", "Number of block tails merged"); -static cl::opt<bool> EnableTailMerge("enable-tail-merge"); +static cl::opt<bool> EnableTailMerge("enable-tail-merge", cl::init(false)); namespace { struct BranchFolder : public MachineFunctionPass { @@ -442,7 +442,8 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { !PriorCond.empty(), MBB); // If the previous branch is conditional and both conditions go to the same - // destination, remove the branch, replacing it with an unconditional one. + // destination, remove the branch, replacing it with an unconditional one or + // a fall-through. if (PriorTBB && PriorTBB == PriorFBB) { TII->RemoveBranch(PrevBB); PriorCond.clear(); @@ -461,6 +462,16 @@ void BranchFolder::OptimizeBlock(MachineFunction::iterator MBB) { ++NumBranchOpts; return OptimizeBlock(MBB); } + + // If the prior block branches somewhere else on the condition and here if + // the condition is false, remove the uncond second branch. + if (PriorFBB == &*MBB) { + TII->RemoveBranch(PrevBB); + TII->InsertBranch(PrevBB, PriorTBB, 0, PriorCond); + MadeChange = true; + ++NumBranchOpts; + return OptimizeBlock(MBB); + } } // Analyze the branch in the current block. |