Reverts wrong modification to MachineBlockPlacement & BranchFolding; uses a new strat...
[oota-llvm.git] / lib / CodeGen / BranchFolding.cpp
index e0b7d73339d700a27ed31d8d1bce75e4242b6f67..a56fec468cc94cd282e56543663cecaf565e41ad 100644 (file)
@@ -1116,6 +1116,12 @@ bool BranchFolder::OptimizeBranches(MachineFunction &MF) {
   for (MachineFunction::iterator I = std::next(MF.begin()), E = MF.end();
        I != E; ) {
     MachineBasicBlock *MBB = &*I++;
+    // XXX-disabled: Don't optimize blocks that contain intentionally added fake
+    // conditional branch.
+    if (!MBB->getCanEliminateMachineBB()) {
+      continue;
+    }
+
     MadeChange |= OptimizeBlock(MBB);
 
     // If it is dead, remove it.
@@ -1254,7 +1260,6 @@ ReoptimizeBlock:
       goto ReoptimizeBlock;
     }
 
-    /*
     // If the previous block unconditionally falls through to this block and
     // this block has no other predecessors, move the contents of this block
     // into the prior block. This doesn't usually happen when SimplifyCFG
@@ -1290,20 +1295,10 @@ ReoptimizeBlock:
       MadeChange = true;
       return MadeChange;
     }
-    */
 
     // If the previous branch *only* branches to *this* block (conditional or
     // not) remove the branch.
     if (PriorTBB == MBB && !PriorFBB) {
-      // XXX-disabled: Don't fold conditional branches that we added
-      // intentionally.
-      MachineBasicBlock::iterator I = PrevBB.getLastNonDebugInstr();
-      if (I != PrevBB.end()) {
-        if (I->isConditionalBranch()) {
-          return MadeChange ;
-        }
-      }
-
       TII->RemoveBranch(PrevBB);
       MadeChange = true;
       ++NumBranchOpts;