Use the new MergeBasicBlockIntoOnlyPred function.
authorChris Lattner <sabre@nondot.org>
Thu, 27 Nov 2008 07:54:12 +0000 (07:54 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 27 Nov 2008 07:54:12 +0000 (07:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60163 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/CodeGenPrepare.cpp

index 93252c8b3bdc227c2f1130c2da677930ed3c3f4c..caf60c8c7af04ef5c18071484b241d09607c6471 100644 (file)
@@ -205,25 +205,7 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) {
   // If the destination block has a single pred, then this is a trivial edge,
   // just collapse it.
   if (DestBB->getSinglePredecessor()) {
-    // If DestBB has single-entry PHI nodes, fold them.
-    while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
-      Value *NewVal = PN->getIncomingValue(0);
-      // Replace self referencing PHI with undef, it must be dead.
-      if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
-      PN->replaceAllUsesWith(NewVal);
-      PN->eraseFromParent();
-    }
-
-    // Splice all the PHI nodes from BB over to DestBB.
-    DestBB->getInstList().splice(DestBB->begin(), BB->getInstList(),
-                                 BB->begin(), BI);
-
-    // Anything that branched to BB now branches to DestBB.
-    BB->replaceAllUsesWith(DestBB);
-
-    // Nuke BB.
-    BB->eraseFromParent();
-
+    MergeBasicBlockIntoOnlyPred(DestBB);
     DOUT << "AFTER:\n" << *DestBB << "\n\n\n";
     return;
   }