================
@@ -285,6 +289,20 @@ void 
NVPTXTargetCodeGenInfo::addNVVMMetadata(llvm::GlobalValue *GV,
 bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
   return false;
 }
+
+llvm::Constant *
+NVPTXTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
+                                       llvm::PointerType *PT,
+                                       QualType QT) const {
+  auto &Ctx = CGM.getContext();
+  if (PT->getAddressSpace() != Ctx.getTargetAddressSpace(LangAS::opencl_local))
+    return llvm::ConstantPointerNull::get(PT);
+
+  auto NPT = llvm::PointerType::get(
+      PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
+  return llvm::ConstantExpr::getAddrSpaceCast(
+      llvm::ConstantPointerNull::get(NPT), PT);
+}
----------------
arichardson wrote:

As far as I can tell the reason for the AMDGPU code using an addrspacecast is 
the following comment `// Currently LLVM assumes null pointers always have 
value 0, which results in incorrectly transformed IR.` so it can't use a `null` 
literal for all ones.

Looking at the lang-ref I can't actually see anywhere that `ptr addrspace(X) 
null` is the zero value, so this should probably be clarified in the lagref: 
https://llvm.org/docs/LangRef.html#t-pointer

https://github.com/llvm/llvm-project/pull/78759
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to