aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/IfConversion.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-06-01 07:41:07 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-06-01 07:41:07 +0000
commit8c52938e44c6eacfee5faf7103e567f79fa5ebef (patch)
treee2056b14348615a07c74fef78aa57cc9417dcc97 /lib/CodeGen/IfConversion.cpp
parentdf4da14948dfbc567831f3af4f6ef913c4dd12ad (diff)
Ifcvt triangle: don't ifcvt 'true' BB if it has other predecessors; don't merge 'false' BB if it has other predecessors.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37382 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/IfConversion.cpp')
-rw-r--r--lib/CodeGen/IfConversion.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/CodeGen/IfConversion.cpp b/lib/CodeGen/IfConversion.cpp
index 0b2e42f1ff..77604dd8bc 100644
--- a/lib/CodeGen/IfConversion.cpp
+++ b/lib/CodeGen/IfConversion.cpp
@@ -460,14 +460,29 @@ bool IfConverter::IfConvertTriangle(BBInfo &BBI) {
if (!TrueBBI.isPredicable)
return false;
+ // FIXME: Consider duplicating if BB is small.
+ if (BBI.TrueBB->pred_size() > 1)
+ return false;
+
// Predicate the 'true' block after removing its branch.
TrueBBI.NonPredSize -= TII->RemoveBranch(*BBI.TrueBB);
PredicateBlock(TrueBBI, BBI.BrCond);
- // Join the 'true' and 'false' blocks by copying the instructions
- // from the 'false' block to the 'true' block.
+ // If 'true' block has a 'false' successor, add a early exit branch to it.
+ if (TrueBBI.FalseBB) {
+ std::vector<MachineOperand> RevCond(TrueBBI.BrCond);
+ if (TII->ReverseBranchCondition(RevCond))
+ assert(false && "Unable to reverse branch condition!");
+ TII->InsertBranch(*BBI.TrueBB, TrueBBI.FalseBB, NULL, RevCond);
+ }
+
+ // Join the 'true' and 'false' blocks if the 'false' block has no other
+ // predecessors. Otherwise, add a unconditional branch from 'true' to 'false'.
BBInfo &FalseBBI = BBAnalysis[BBI.FalseBB->getNumber()];
- MergeBlocks(TrueBBI, FalseBBI);
+ if (FalseBBI.BB->pred_size() == 2)
+ MergeBlocks(TrueBBI, FalseBBI);
+ else
+ InsertUncondBranch(TrueBBI.BB, FalseBBI.BB, TII);
// Now merge the entry of the triangle with the true block.
BBI.NonPredSize -= TII->RemoveBranch(*BBI.BB);