The correct fix for PR612, which also fixes
authorChris Lattner <sabre@nondot.org>
Wed, 3 Aug 2005 18:51:44 +0000 (18:51 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 3 Aug 2005 18:51:44 +0000 (18:51 +0000)
Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22628 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/LowerInvoke.cpp

index 96d5b98c6bdeef5b99efb5b9b3971977b5d6e88a..b0d8fb8a3081343c4c2fed01392e7ae8e065ea7d 100644 (file)
@@ -283,10 +283,20 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
       // Create the receiver block if there is a critical edge to the normal
       // destination.
       SplitCriticalEdge(II, 0, this);
-      BasicBlock::iterator InsertLoc = II->getNormalDest()->begin();
-      while (isa<PHINode>(InsertLoc)) ++InsertLoc;
       
+      // There should not be any PHI nodes in II->getNormalDest() now.  It has
+      // a single predecessor, so any PHI nodes are unneeded.  Remove them now
+      // by replacing them with their single input value.
+      assert(II->getNormalDest()->getSinglePredecessor() &&
+             "Split crit edge doesn't have a single predecessor!");
 
+      BasicBlock::iterator InsertLoc = II->getNormalDest()->begin();
+      while (PHINode *PN = dyn_cast<PHINode>(InsertLoc)) {
+        PN->replaceAllUsesWith(PN->getIncomingValue(0));
+        PN->eraseFromParent();        
+        InsertLoc = II->getNormalDest()->begin();
+      }
+      
       // Insert a normal call instruction on the normal execution path.
       std::string Name = II->getName(); II->setName("");
       CallInst *NewCall = new CallInst(II->getCalledValue(),