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

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 05:53:49 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:

My understanding is that so far, we have 2 conventions for default: either 0 or 4 depending on the environment. Which in the backend means `sc::Function` or `sc::Generic`, and no clear way to say afterwards what convention was used.

I kicked the problem a bit later by adding the `getFlatAddressSpace` function, and do something like AMDGPU does: return `-1` for environment we don't run this pass with.

Let me know if that is OK to move this forward :)


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


More information about the llvm-commits mailing list