diff --git a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
index c85a8a4f2dcf6dbf94285b0e22f8c4bf89fada4d..27910715fe76685e1ad6e6cdd356c2c5a4e5288e 100644
--- a/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+++ b/hpvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
@@ -1137,6 +1137,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
 // Function to replace call instructions to functions in the kernel
   std::map<Function *, Function *> OrgToClonedFuncMap;
   std::vector<Function *> FuncToBeRemoved;
+  std::vector<CallInst *> CallstoRemoved;
   auto CloneAndReplaceCall = [&] (CallInst *CI, Function *OrgFunc) {
     Function* NewFunc;
     // Check if the called function has already been cloned before.
@@ -1157,7 +1158,7 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
     CallInst* Inst = CallInst::Create(NewFunc, args,
         OrgFunc->getReturnType()->isVoidTy()? "" : CI->getName(), CI);
     CI->replaceAllUsesWith(Inst);
-    IItoRemove.push_back(CI);
+    CallstoRemoved.push_back(CI);
     return NewFunc;
   };
 
@@ -1880,6 +1881,11 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
 		KernelM->getFunctionList().push_back(F);
 	}
 
+	 for (auto *I : reverse(CallstoRemoved)) {
+                DEBUG(errs() << "Erasing: " << *I << "\n");
+                I->eraseFromParent();
+        }
+
 	addCLMetadata(F_nvptx);
 	kernel->KernelFunction = F_nvptx;
 	errs() << "Identified kernel - " << kernel->KernelFunction->getName() << "\n";