[llvm] [SPIR-V] Add InferAddrSpaces pass to the backend (PR #137766)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 02:20:55 PDT 2025


================
@@ -190,6 +191,14 @@ void SPIRVPassConfig::addIRPasses() {
   TargetPassConfig::addIRPasses();
 
   if (TM.getSubtargetImpl()->isVulkanEnv()) {
+    // The frontend has a tendency to quickly addrspacecast pointers to the
+    // default address space, and relies on addrspacecast instructions at the
+    // boundaries. Vulkan does not allow such things, and we must keep the
+    // pointer address space stable.
+    // This pass will determine real address space of a pointer, and patch
+    // instructions removing Addrspacecasts.
+    addPass(createInferAddressSpacesPass(/* AddressSpace= */ 0));
----------------
Keenuts wrote:

I'm not sure about that. In the logical SPIRV world (outside of buffer content), there are no relationships between addresses like a flat address space would give, pointers are abstract and have no numerical value.
>From the HLSL point of view, it's a bit the same: those address spaces are "spaces", but it's not defined if it's flat or not (we don't do pointer arithmetic for ex).
(once again, this is valid for let's say 2 input variables, not for data inside a resource like a buffer)
So saying I feel saying "0 is flat" wouldn't be right in this case.

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


More information about the llvm-commits mailing list