Fix bug: 2003-10-29-CallSiteResolve.ll & PR70
authorChris Lattner <sabre@nondot.org>
Thu, 30 Oct 2003 00:46:41 +0000 (00:46 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 30 Oct 2003 00:46:41 +0000 (00:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9600 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 91c549d495ed99b1be1503f593c29a70eb0dcbb4..bc1a81967f4b6f33fbe6d0429356662652fbb164 100644 (file)
@@ -1739,7 +1739,17 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
   if (Caller->getType() != NV->getType() && !Caller->use_empty()) {
     if (NV->getType() != Type::VoidTy) {
       NV = NC = new CastInst(NC, Caller->getType(), "tmp");
-      InsertNewInstBefore(NC, *Caller);
+
+      // If this is an invoke instruction, we should insert it after the first
+      // non-phi, instruction in the normal successor block.
+      if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
+        BasicBlock::iterator I = II->getNormalDest()->begin();
+        while (isa<PHINode>(I)) ++I;
+        InsertNewInstBefore(NC, *I);
+      } else {
+        // Otherwise, it's a call, just insert cast right after the call instr
+        InsertNewInstBefore(NC, *Caller);
+      }
       AddUsesToWorkList(*Caller);
     } else {
       NV = Constant::getNullValue(Caller->getType());