diff --git a/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp b/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
index a8350fde04ae3fe5562ac998769d853390aa4892..d111352f9dad2b2280b51b551ee25e6e1d109c13 100644
--- a/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
+++ b/llvm/lib/Transforms/DFG2LLVM_NVPTX/DFG2LLVM_NVPTX.cpp
@@ -1339,44 +1339,48 @@ void CGT_NVPTX::codeGen(DFLeafNode* N) {
         break;
       }
 
-    }
-    else if(IntrinsicInst* II = dyn_cast<IntrinsicInst>(I)) {
-      switch(II->getIntrinsicID()) {
-        case Intrinsic::sin:
-        case Intrinsic::cos:
-        {
-          errs() << "Found sincos: " << *II << "\n";
-          // Get the libclc function
-          // libclc uses mangled name for sin cos
-          assert(II->getType()->isFloatTy()
-              && "Only handling sin(float) and cos(float)!");
-          std::string name;
-          if(II->getIntrinsicID() == Intrinsic::sin)
-            name = "_Z3sinf";
-          else
-            name = "_Z3cosf";
-
-          FunctionType* SinCosFT = FunctionType::get(II->getType(),
-                                Type::getFloatTy(getGlobalContext()),
-                                false);
-          Function* LibclcFunction = cast<Function>
-                             (KernelM.getOrInsertFunction(name, SinCosFT));
-          CallInst* CI = CallInst::Create(LibclcFunction, II->getArgOperand(0), II->getName(), II);
-
-          II->replaceAllUsesWith(CI);
-          IItoRemove.push_back(II);
-        }
-        break;
-        default:
-          errs() << "[WARNING] Found Intrinsic: " << *II << "\n" ;
-      }
-
     }
     else if(CallInst* CI = dyn_cast<CallInst>(I)) {
       DEBUG(errs() << "Found a call: " << *CI << "\n");
       Function* calleeF = cast<Function>(CI->getCalledValue()->stripPointerCasts());
       if(calleeF->isDeclaration()) {
+        // Add the declaration to kernel module
+        errs() << "Adding declaration to Kernel module: " << *calleeF << "\n";
         KernelM.getOrInsertFunction(calleeF->getName(), calleeF->getFunctionType());
+        if(IntrinsicInst* II = dyn_cast<IntrinsicInst>(CI)) {
+          // Now handle a few specific intrinsics
+          // For now, sin and cos are translated to their libclc equivalent
+          switch(II->getIntrinsicID()) {
+            case Intrinsic::sin:
+            case Intrinsic::cos:
+            {
+              errs() << "Found sincos: " << *II << "\n";
+              // Get the libclc function
+              // libclc uses mangled name for sin cos
+              assert(II->getType()->isFloatTy()
+                  && "Only handling sin(float) and cos(float)!");
+              std::string name;
+              if(II->getIntrinsicID() == Intrinsic::sin)
+                name = "_Z3sinf";
+              else
+                name = "_Z3cosf";
+
+              FunctionType* SinCosFT = FunctionType::get(II->getType(),
+                                    Type::getFloatTy(getGlobalContext()),
+                                    false);
+              Function* LibclcFunction = cast<Function>
+                                 (KernelM.getOrInsertFunction(name, SinCosFT));
+              CallInst* CI = CallInst::Create(LibclcFunction, II->getArgOperand(0), II->getName(), II);
+
+              II->replaceAllUsesWith(CI);
+              IItoRemove.push_back(II);
+            }
+            break;
+            default:
+              errs() << "[WARNING] Found Intrinsic: " << *II << "\n" ;
+          }
+        }
+
       }
       else {
         // Clone the function