[PATCH] Address Space Casting

Matt Arsenault Matthew.Arsenault at amd.com
Wed Aug 14 12:07:52 PDT 2013



================
Comment at: lib/IR/ConstantFold.cpp:692-693
@@ -691,2 +691,4 @@
     return FoldBitCast(V, DestTy);
+  case Instruction::AddrSpaceCast:
+    return 0;
   }
----------------
Are addrspace casts allowed between the same address space? If so, you could transform addrspace cast to the same address space into a bitcast

================
Comment at: lib/IR/Instructions.cpp:2320-2325
@@ +2319,8 @@
+    case 14: {
+      PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy);
+      PointerType *DstPtrTy = dyn_cast<PointerType>(DstTy);
+
+      assert(SrcPtrTy && DstPtrTy);
+
+      if (SrcPtrTy->getAddressSpace() != DstPtrTy->getAddressSpace())
+        return Instruction::AddrSpaceCast;
----------------
If you're asserting anyway, it's probably better to just use ->getPointerAddressSpace()

================
Comment at: lib/IR/Verifier.cpp:1445-1446
@@ +1444,4 @@
+          "AddrSpaceCast result must be a pointer", &I);
+  Assert1(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),
+          "AddrSpaceCast must be between different address spaces", &I);
+  visitInstruction(I);
----------------
I'm not sure this should be disallowed. In cases where the address spaces could differ, it could be easier for a frontend to just always emit addrspace cast, which could be turned into bitcast when possible. In that case it might be better to call this ptrcast, and bitcast could be used in the case when the address spaces match.

================
Comment at: lib/IR/Instructions.cpp:2180-2181
@@ -2176,3 +2179,3 @@
   };
   
   // If either of the casts are a bitcast from scalar to vector, disallow the
----------------
Somewhere in here should remove the parts I added to check if bitcast address spaces match.


http://llvm-reviews.chandlerc.com/D1401



More information about the llvm-commits mailing list