Avoid inserting an entry block unless we need it
authorChris Lattner <sabre@nondot.org>
Wed, 14 Aug 2002 21:35:02 +0000 (21:35 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Aug 2002 21:35:02 +0000 (21:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3336 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/ADCE.cpp

index 062b52ff50c0e090e688854084d937fc684596a4..618ff23b4fbb70482af6be38011a41a227591e89 100644 (file)
@@ -235,11 +235,15 @@ bool ADCE::doADCE() {
       dropReferencesOfDeadInstructionsInLiveBlock(I);
     
   } else {                                   // If there are some blocks dead...
-    // Insert a new entry node to eliminate the entry node as a special case.
-    BasicBlock *NewEntry = new BasicBlock();
-    NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
-    Func->getBasicBlockList().push_front(NewEntry);
-    AliveBlocks.insert(NewEntry);    // This block is always alive!
+    // If the entry node is dead, insert a new entry node to eliminate the entry
+    // node as a special case.
+    //
+    if (!AliveBlocks.count(&Func->front())) {
+      BasicBlock *NewEntry = new BasicBlock();
+      NewEntry->getInstList().push_back(new BranchInst(&Func->front()));
+      Func->getBasicBlockList().push_front(NewEntry);
+      AliveBlocks.insert(NewEntry);    // This block is always alive!
+    }
     
     // Loop over all of the alive blocks in the function.  If any successor
     // blocks are not alive, we adjust the outgoing branches to branch to the