[llvm] [SPIR-V] Fix storage class mismatch for globals initialized with a function pointer (PR #216744)

Alex Voicu via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 03:28:11 PDT 2026


================
@@ -987,10 +987,19 @@ Type *SPIRVEmitIntrinsicsImpl::deduceElementTypeHelper(
       Ty = SPIRV::getOriginalFunctionType(*Fn);
       GR->addDeducedElementType(I, Ty);
     } else {
-      Ty = deduceElementTypeByValueDeep(
-          Ref->getValueType(),
-          Ref->getNumOperands() > 0 ? Ref->getOperand(0) : nullptr, Visited,
-          UnknownElemTypeI8);
+      Value *Op = Ref->getNumOperands() > 0 ? Ref->getOperand(0) : nullptr;
+      if (isa_and_nonnull<Function>(Op) &&
+          TM.getSubtargetImpl()->canUseExtension(
+              SPIRV::Extension::SPV_INTEL_function_pointers)) {
+        if (Type *NestedTy =
+                deduceElementTypeHelper(Op, Visited, UnknownElemTypeI8))
+          Ty = getTypedPointerWrapper(
+              NestedTy, storageClassToAddressSpace(
+                            SPIRV::StorageClass::CodeSectionINTEL));
----------------
AlexVlx wrote:

We should not do this unconditionally (it will actually lead to bad things on AMDGCN). I would suggest that we default to the ProgramAS from the DL, and correcting the DLs to specify that (both we and Intel already do that, so that leaves a choice for vanilla SPV; I will note that as is the DLs are subtly broken anyways as they default the ProgramAS to AS0, which maps to private/StorageClassFunction, which is definitely not where the code for a function lives for targets that we know of).

https://github.com/llvm/llvm-project/pull/216744


More information about the llvm-commits mailing list