[llvm-commits] CVS: llvm/lib/CodeGen/IfConversion.cpp

Evan Cheng evan.cheng at apple.com
Fri Jun 1 00:42:38 PDT 2007



Changes in directory llvm/lib/CodeGen:

IfConversion.cpp updated: 1.19 -> 1.20
---
Log message:

Ifcvt triangle: don't ifcvt 'true' BB if it has other predecessors; don't merge 'false' BB if it has other predecessors.

---
Diffs of the changes:  (+18 -3)

 IfConversion.cpp |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)


Index: llvm/lib/CodeGen/IfConversion.cpp
diff -u llvm/lib/CodeGen/IfConversion.cpp:1.19 llvm/lib/CodeGen/IfConversion.cpp:1.20
--- llvm/lib/CodeGen/IfConversion.cpp:1.19	Thu May 31 19:55:26 2007
+++ llvm/lib/CodeGen/IfConversion.cpp	Fri Jun  1 02:41:07 2007
@@ -460,14 +460,29 @@
   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);






More information about the llvm-commits mailing list