If true / false blocks fallthrough before ifcvt, add unconditional branches to ifcvt...
authorEvan Cheng <evan.cheng@apple.com>
Fri, 18 May 2007 01:55:58 +0000 (01:55 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Fri, 18 May 2007 01:55:58 +0000 (01:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37200 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/IfConversion.cpp

index 9b69bf16f8c88fce9165a173cba9486bc7dbcd73..a98f04b1ef2dbcc351b84d17414c450fd26bafca 100644 (file)
@@ -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);