aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/IfConversion.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-05-18 01:55:58 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-05-18 01:55:58 +0000
commit47d25020728d23ca62a805963e3b0885a4df1bc6 (patch)
tree33a7955e07c72aeee588f9e04bbfe4f0569e6ee5 /lib/CodeGen/IfConversion.cpp
parentdcc50a4aeee13e5bb7aec9f6a2e5ca80ef54c40d (diff)
If true / false blocks fallthrough before ifcvt, add unconditional branches to ifcvt'd block.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/IfConversion.cpp')
-rw-r--r--lib/CodeGen/IfConversion.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/CodeGen/IfConversion.cpp b/lib/CodeGen/IfConversion.cpp
index 9b69bf16f8..a98f04b1ef 100644
--- a/lib/CodeGen/IfConversion.cpp
+++ b/lib/CodeGen/IfConversion.cpp
@@ -87,8 +87,6 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
TII = MF.getTarget().getInstrInfo();
if (!TII) return false;
- MadeChange = false;
-
MF.RenumberBlocks();
unsigned NumBBs = MF.getNumBlockIDs();
BBAnalysis.resize(NumBBs);
@@ -98,6 +96,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
// candidates to perform if-convesion.
InitialFunctionAnalysis(MF, Candidates);
+ MadeChange = false;
for (unsigned i = 0, e = Candidates.size(); i != e; ++i) {
BBInfo &BBI = BBAnalysis[Candidates[i]];
switch (BBI.Kind) {
@@ -111,6 +110,9 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
break;
}
}
+
+ BBAnalysis.clear();
+
return MadeChange;
}
@@ -150,6 +152,10 @@ void IfConverter::AnalyzeBlock(MachineBasicBlock *BB) {
if (TrueBBI.Kind != ICNotClassfied)
return;
+ // TODO: Only handle very simple cases for now.
+ if (TrueBBI.FalseBB || TrueBBI.Cond.size())
+ return;
+
// No false branch. This BB must end with a conditional branch and a
// fallthrough.
if (!BBI.FalseBB)
@@ -168,8 +174,7 @@ void IfConverter::AnalyzeBlock(MachineBasicBlock *BB) {
return;
// TODO: Only handle very simple cases for now.
- if (TrueBBI.FalseBB || FalseBBI.FalseBB ||
- TrueBBI.Cond.size() || FalseBBI.Cond.size())
+ if (FalseBBI.FalseBB || FalseBBI.Cond.size())
return;
if (TrueBBI.TrueBB && TrueBBI.TrueBB == BBI.FalseBB) {
@@ -309,11 +314,21 @@ bool IfConverter::IfConvertDiamond(BBInfo &BBI) {
TrueBBI.Size -= TII->RemoveBranch(*BBI.TrueBB);
PredicateBlock(BBI.TrueBB, BBI.Cond);
+ // Either the 'true' block fallthrough to another block or it ends with a
+ // return. If it's the former, add a conditional branch to its successor.
+ if (!TrueBBI.TrueBB)
+ TII->InsertBranch(*BBI.TrueBB, *BBI.TrueBB->succ_begin(), NULL, BBI.Cond);
+
// Predicate the 'false' block.
std::vector<MachineOperand> NewCond(BBI.Cond);
TII->ReverseBranchCondition(NewCond);
PredicateBlock(BBI.FalseBB, NewCond, true);
+ // Either the 'false' block fallthrough to another block or it ends with a
+ // return. If it's the former, add a conditional branch to its successor.
+ if (!FalseBBI.TrueBB)
+ TII->InsertBranch(*BBI.FalseBB, *BBI.FalseBB->succ_begin(), NULL,NewCond);
+
// Merge the 'true' and 'false' blocks by copying the instructions
// from the 'false' block to the 'true' block.
MergeBlocks(TrueBBI, FalseBBI);