[llvm] r193112 - Fix CodeGen for vectors of pointers with address spaces.

Matt Arsenault Matthew.Arsenault at amd.com
Fri Nov 15 14:01:38 PST 2013


On 11/06/2013 01:52 AM, Patrik Hägglund H wrote:
> Hit Matt,
>
> I just wanted to say a big thank you for all your patches regarding address spaces!
>
> Your patches has made most of our own internal corresponding changes (not covering as many cases as your patches) obsolete, and we are now in the process of converting our front-end to emit address space annotated pointers for all our address spaces. Previously, we had the workaround of emitting mostly integers in place of pointers, for non-standard address spaces.
>
> We currently only have an uncategorized problem with SROA and address spaces, and the small patch shown below.
Yes, I haven't committed the SROA address space patches yet.
>
> Regards,
> Patrik Hägglund
>
> diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
> index 176e850..656da49 100644
> --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
> +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
> @@ -6297,7 +6297,7 @@ unsigned SelectionDAG::InferPtrAlignment(SDValue Ptr) const {
>     int64_t GVOffset = 0;
>     const TargetLowering *TLI = TM.getTargetLowering();
>     if (TLI->isGAPlusOffset(Ptr.getNode(), GV, GVOffset)) {
> -    unsigned PtrWidth = TLI->getPointerTy().getSizeInBits();
> +    unsigned PtrWidth = TLI->getPointerTypeSizeInBits(GV->getType());
>       APInt KnownZero(PtrWidth, 0), KnownOne(PtrWidth, 0);
>       llvm::ComputeMaskedBits(const_cast<GlobalValue*>(GV), KnownZero, KnownOne,
>                               TLI->getDataLayout());
> diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
> index d8a2cfb..788a325 100644
> --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
> +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
> @@ -1065,7 +1065,8 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
>         return DAG.getGlobalAddress(GV, getCurSDLoc(), VT);
>
>       if (isa<ConstantPointerNull>(C))
> -      return DAG.getConstant(0, TLI->getPointerTy());
> +      return DAG.getConstant(0, TLI->getPointerTy(
> +                               V->getType()->getPointerAddressSpace()));
>
>       if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
>         return DAG.getConstantFP(*CFP, VT);
>

Do you happen to have a test ready for this?

> -----Original Message-----
> From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Matt Arsenault
> Sent: den 21 oktober 2013 22:04
> To: llvm-commits at cs.uiuc.edu
> Subject: [llvm] r193112 - Fix CodeGen for vectors of pointers with address spaces.
>
> Author: arsenm
> Date: Mon Oct 21 15:03:58 2013
> New Revision: 193112
>
> URL: http://llvm.org/viewvc/llvm-project?rev=193112&view=rev
> Log:
> Fix CodeGen for vectors of pointers with address spaces.
>
> Modified:
>      llvm/trunk/include/llvm/Target/TargetLowering.h
>      llvm/trunk/test/CodeGen/R600/gep-address-space.ll
>
> Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=193112&r1=193111&r2=193112&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
> +++ llvm/trunk/include/llvm/Target/TargetLowering.h Mon Oct 21 15:03:58 2013
> @@ -570,14 +570,18 @@ public:
>     /// otherwise it will assert.
>     EVT getValueType(Type *Ty, bool AllowUnknown = false) const {
>       // Lower scalar pointers to native pointer types.
> -    if (Ty->isPointerTy()) return getPointerTy(Ty->getPointerAddressSpace());
> +    if (PointerType *PTy = dyn_cast<PointerType>(Ty))
> +      return getPointerTy(PTy->getAddressSpace());
>   
>       if (Ty->isVectorTy()) {
>         VectorType *VTy = cast<VectorType>(Ty);
>         Type *Elm = VTy->getElementType();
>         // Lower vectors of pointers to native pointer types.
> -      if (Elm->isPointerTy())
> -        Elm = EVT(PointerTy).getTypeForEVT(Ty->getContext());
> +      if (PointerType *PT = dyn_cast<PointerType>(Elm)) {
> +        EVT PointerTy(getPointerTy(PT->getAddressSpace()));
> +        Elm = PointerTy.getTypeForEVT(Ty->getContext());
> +      }
> +
>         return EVT::getVectorVT(Ty->getContext(), EVT::getEVT(Elm, false),
>                          VTy->getNumElements());
>       }
>
> Modified: llvm/trunk/test/CodeGen/R600/gep-address-space.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/R600/gep-address-space.ll?rev=193112&r1=193111&r2=193112&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/R600/gep-address-space.ll (original)
> +++ llvm/trunk/test/CodeGen/R600/gep-address-space.ll Mon Oct 21 15:03:58 2013
> @@ -8,3 +8,33 @@ define void @use_gep_address_space([1024
>     ret void
>   }
>   
> +define void @gep_as_vector_v4(<4 x [1024 x i32] addrspace(3)*> %array) nounwind {
> +; CHECK-LABEL: @gep_as_vector_v4:
> +; CHECK: V_ADD_I32
> +; CHECK: V_ADD_I32
> +; CHECK: V_ADD_I32
> +; CHECK: V_ADD_I32
> +  %p = getelementptr <4 x [1024 x i32] addrspace(3)*> %array, <4 x i16> zeroinitializer, <4 x i16> <i16 16, i16 16, i16 16, i16 16>
> +  %p0 = extractelement <4 x i32 addrspace(3)*> %p, i32 0
> +  %p1 = extractelement <4 x i32 addrspace(3)*> %p, i32 1
> +  %p2 = extractelement <4 x i32 addrspace(3)*> %p, i32 2
> +  %p3 = extractelement <4 x i32 addrspace(3)*> %p, i32 3
> +  store i32 99, i32 addrspace(3)* %p0
> +  store i32 99, i32 addrspace(3)* %p1
> +  store i32 99, i32 addrspace(3)* %p2
> +  store i32 99, i32 addrspace(3)* %p3
> +  ret void
> +}
> +
> +define void @gep_as_vector_v2(<2 x [1024 x i32] addrspace(3)*> %array) nounwind {
> +; CHECK-LABEL: @gep_as_vector_v2:
> +; CHECK: V_ADD_I32
> +; CHECK: V_ADD_I32
> +  %p = getelementptr <2 x [1024 x i32] addrspace(3)*> %array, <2 x i16> zeroinitializer, <2 x i16> <i16 16, i16 16>
> +  %p0 = extractelement <2 x i32 addrspace(3)*> %p, i32 0
> +  %p1 = extractelement <2 x i32 addrspace(3)*> %p, i32 1
> +  store i32 99, i32 addrspace(3)* %p0
> +  store i32 99, i32 addrspace(3)* %p1
> +  ret void
> +}
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>






More information about the llvm-commits mailing list