[llvm] [AMDGPU] Allow casts between the Global and Constant Addr Spaces in isValidAddrSpaceCast (PR #112493)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 13:35:23 PDT 2024


================
@@ -174,24 +174,45 @@ class GCNTTIImpl final : public BasicTTIImplBase<GCNTTIImpl> {
   bool isAlwaysUniform(const Value *V) const;
 
   bool isValidAddrSpaceCast(unsigned FromAS, unsigned ToAS) const {
-    if (ToAS == AMDGPUAS::FLAT_ADDRESS) {
-      switch (FromAS) {
+    // Address space casts must cast between different address spaces.
+    if (FromAS == ToAS)
+      return false;
+
+    if (FromAS == AMDGPUAS::FLAT_ADDRESS ||
+        FromAS == AMDGPUAS::GLOBAL_ADDRESS ||
+        FromAS == AMDGPUAS::CONSTANT_ADDRESS ||
+        FromAS > AMDGPUAS::MAX_AMDGPU_ADDRESS) {
+      // Casting any 64-bit AS to another 64-bit AS or to a 32-bit AS is
+      // valid.
+      switch (ToAS) {
+      case AMDGPUAS::FLAT_ADDRESS:
       case AMDGPUAS::GLOBAL_ADDRESS:
-      case AMDGPUAS::CONSTANT_ADDRESS:
-      case AMDGPUAS::CONSTANT_ADDRESS_32BIT:
       case AMDGPUAS::LOCAL_ADDRESS:
+      case AMDGPUAS::CONSTANT_ADDRESS:
       case AMDGPUAS::PRIVATE_ADDRESS:
+      case AMDGPUAS::CONSTANT_ADDRESS_32BIT:
         return true;
       default:
         break;
       }
-      return false;
+      if (ToAS > AMDGPUAS::MAX_AMDGPU_ADDRESS)
+        return true;
+    } else if (FromAS == AMDGPUAS::LOCAL_ADDRESS ||
+               FromAS == AMDGPUAS::PRIVATE_ADDRESS ||
+               FromAS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) {
+      // Casting from a 32-bit AS to any 64-bit AS is valid.
+      switch (ToAS) {
+      case AMDGPUAS::FLAT_ADDRESS:
+      case AMDGPUAS::GLOBAL_ADDRESS:
+      case AMDGPUAS::CONSTANT_ADDRESS:
+        return true;
+      default:
+        break;
----------------
arsenm wrote:

Yes, p1 -> p3/p5 are also illegal 

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


More information about the llvm-commits mailing list