[llvm-commits] CVS: llvm/lib/CodeGen/BranchFolding.cpp
Chris Lattner
sabre at nondot.org
Fri Oct 20 22:43:45 PDT 2006
Changes in directory llvm/lib/CodeGen:
BranchFolding.cpp updated: 1.16 -> 1.17
---
Log message:
Transform code like:
jle FOO
jmp BAR
BAR:
into:
jle FOO
BAR:
... whoa!
---
Diffs of the changes: (+13 -2)
BranchFolding.cpp | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.16 llvm/lib/CodeGen/BranchFolding.cpp:1.17
--- llvm/lib/CodeGen/BranchFolding.cpp:1.16 Sat Oct 21 00:08:28 2006
+++ llvm/lib/CodeGen/BranchFolding.cpp Sat Oct 21 00:43:30 2006
@@ -30,7 +30,7 @@
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 @@
!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 @@
++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.
More information about the llvm-commits
mailing list