Fix PR1752 and LoopSimplify/2007-10-28-InvokeCrash.ll: terminators 
can have uses too.  Wouldn't it be nice if invoke didn't exist? :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43426 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp
index 20eecd6..21a4e23 100644
--- a/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/lib/Transforms/Utils/LoopSimplify.cpp
@@ -34,7 +34,7 @@
 
 #define DEBUG_TYPE "loopsimplify"
 #include "llvm/Transforms/Scalar.h"
-#include "llvm/Constant.h"
+#include "llvm/Constants.h"
 #include "llvm/Instructions.h"
 #include "llvm/Function.h"
 #include "llvm/Type.h"
@@ -158,12 +158,14 @@
     for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
       TI->getSuccessor(i)->removePredecessor(BB);
    
-    // Add a new unreachable instruction.
+    // Add a new unreachable instruction before the old terminator.
     new UnreachableInst(TI);
     
     // Delete the dead terminator.
-    if (AA) AA->deleteValue(&BB->back());
-    BB->getInstList().pop_back();
+    if (AA) AA->deleteValue(TI);
+    if (!TI->use_empty())
+      TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
+    TI->eraseFromParent();
     Changed |= true;
   }