[PATCH] Address Space Casting

Michele Scandale michele.scandale at gmail.com
Wed Aug 14 16:15:33 PDT 2013


  To me seems fine to generalize the semantic of the instruction 'addrspacecast' so to allow also casting within the same address space (the name would change into 'ptrcast').

  Is it fine to you too to have this general "cast between pointers" instruction and have "bitcast" that will have the same semantic of the general instruction when both source and destination are pointers in the same address space?


================
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);
----------------
Matt Arsenault wrote:
> 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.
>From the specification that David summarized, 'addrspacecast' should be used only when address spaces are different, while bitcast should be used when the address space is the same.

I agree with you that generalizing the semantic would increase the flexibility... I'll fix the patch in this direction.

================
Comment at: lib/IR/ConstantFold.cpp:692-693
@@ -691,2 +691,4 @@
     return FoldBitCast(V, DestTy);
+  case Instruction::AddrSpaceCast:
+    return 0;
   }
----------------
Matt Arsenault wrote:
> Are addrspace casts allowed between the same address space? If so, you could transform addrspace cast to the same address space into a bitcast
With respect to the specification no: the addrspacecast is used only between differen address spaces


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



More information about the llvm-commits mailing list