diff --git a/lib/Target/HSAIL/HSAILUtilityFunctions.cpp b/lib/Target/HSAIL/HSAILUtilityFunctions.cpp
index 49f99fc..10baf50 100644
--- a/lib/Target/HSAIL/HSAILUtilityFunctions.cpp
+++ b/lib/Target/HSAIL/HSAILUtilityFunctions.cpp
@@ -166,6 +166,7 @@ unsigned getAlignTypeQualifier(Type *ty, const DataLayout &DL,
 static bool isKernelFunc(StringRef str) {
   if (str.startswith("__OpenCL_") && str.endswith("_kernel"))
     return true;
+
   return false;
 }
 
@@ -173,6 +174,19 @@ bool isKernelFunc(const Function *F) {
   if (CallingConv::SPIR_KERNEL == F->getCallingConv())
     return true;
 
+  NamedMDNode *kernels = F->getParent()->getNamedMetadata("opencl.kernels");
+  if (kernels != NULL) {
+    for (unsigned i = 0, e = kernels->getNumOperands(); i != e; ++i) {
+      if (kernels->getOperand(i)->getOperand(0) == NULL)
+        continue; // globaldce might have removed uncalled kernels
+      Function *k =
+        cast<Function>(dyn_cast<ValueAsMetadata>(
+          kernels->getOperand(i)->getOperand(0))->getValue());
+      if (k == F)
+        return true;
+    }
+  }
+
   return isKernelFunc(F->getName());
 }
 
