[llvm] [AMDGPU] Implement getAddrSpaceCastPreservedPtrMask (PR #182658)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Fri May 1 12:27:18 PDT 2026


================
@@ -207,6 +207,38 @@ class GCNTTIImpl final : public BasicTTIImplBase<GCNTTIImpl> {
     return AMDGPUAS::FLAT_ADDRESS;
   }
 
+  APInt getAddrSpaceCastPreservedPtrMask(unsigned SrcAS,
+                                         unsigned DstAS) const override {
+    // Only handle casts from flat (generic) address space.
+    if (SrcAS != AMDGPUAS::FLAT_ADDRESS)
+      return BaseT::getAddrSpaceCastPreservedPtrMask(SrcAS, DstAS);
+
+    unsigned FlatPtrSize = DL.getPointerSizeInBits(AMDGPUAS::FLAT_ADDRESS);
+
+    // For global and constant, addresses in flat and global/constant address
+    // spaces are the same - no conversion is needed. Global memory regions are
+    // architecturally separate from the private/local aperture regions (which
+    // are 2^32-aligned and use specific high-address ranges), so all 64 bits
+    // are preserved.
+    if (DstAS == AMDGPUAS::GLOBAL_ADDRESS ||
+        DstAS == AMDGPUAS::CONSTANT_ADDRESS)
+      return APInt::getAllOnes(FlatPtrSize);
+
+    // The apertures for local and private memory are 2^32 bytes in size and
+    // aligned to 2^32. Address changes within the lower 32 bits do not change
+    // the address space aperture, so it's safe to cast back to the original
+    // address space.
+    if (DstAS == AMDGPUAS::LOCAL_ADDRESS || DstAS == AMDGPUAS::PRIVATE_ADDRESS)
+      return APInt::getLowBitsSet(FlatPtrSize, 32);
----------------
shiltian wrote:

Are they going to stay the same? @arsenm @jayfoad 

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


More information about the llvm-commits mailing list