Add support for removing invoke instructions

llvm-svn: 12858
diff --git a/llvm/lib/Transforms/Scalar/GCSE.cpp b/llvm/lib/Transforms/Scalar/GCSE.cpp
index bbefe81..7db7d4d 100644
--- a/llvm/lib/Transforms/Scalar/GCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/GCSE.cpp
@@ -167,6 +167,13 @@
   // anything special.
   if (!isa<Constant>(V)) {
     I->replaceAllUsesWith(V);
+
+    if (InvokeInst *II = dyn_cast<InvokeInst>(I)) {
+      // Removing an invoke instruction requires adding a branch to the normal
+      // destination and removing PHI node entries in the exception destination.
+      new BranchInst(II->getNormalDest(), II);
+      II->getUnwindDest()->removePredecessor(II->getParent());
+    }
     
     // Erase the instruction from the program.
     I->getParent()->getInstList().erase(I);
@@ -179,6 +186,13 @@
   // Perform the replacement.
   I->replaceAllUsesWith(C);
 
+  if (InvokeInst *II = dyn_cast<InvokeInst>(I)) {
+    // Removing an invoke instruction requires adding a branch to the normal
+    // destination and removing PHI node entries in the exception destination.
+    new BranchInst(II->getNormalDest(), II);
+    II->getUnwindDest()->removePredecessor(II->getParent());
+  }
+
   // Erase the instruction from the program.
   I->getParent()->getInstList().erase(I);