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

Evan Cheng evan.cheng at apple.com
Thu May 17 18:56:18 PDT 2007



Changes in directory llvm/lib/CodeGen:

IfConversion.cpp updated: 1.5 -> 1.6
---
Log message:

If true / false blocks fallthrough before ifcvt, add unconditional branches to ifcvt'd block.

---
Diffs of the changes:  (+19 -4)

 IfConversion.cpp |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)


Index: llvm/lib/CodeGen/IfConversion.cpp
diff -u llvm/lib/CodeGen/IfConversion.cpp:1.5 llvm/lib/CodeGen/IfConversion.cpp:1.6
--- llvm/lib/CodeGen/IfConversion.cpp:1.5	Thu May 17 19:20:58 2007
+++ llvm/lib/CodeGen/IfConversion.cpp	Thu May 17 20:55:58 2007
@@ -87,8 +87,6 @@
   TII = MF.getTarget().getInstrInfo();
   if (!TII) return false;
 
-  MadeChange = false;
-
   MF.RenumberBlocks();
   unsigned NumBBs = MF.getNumBlockIDs();
   BBAnalysis.resize(NumBBs);
@@ -98,6 +96,7 @@
   // 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 @@
       break;
     }
   }
+
+  BBAnalysis.clear();
+
   return MadeChange;
 }
 
@@ -150,6 +152,10 @@
   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 @@
     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 @@
     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);






More information about the llvm-commits mailing list