From e6e811277f045ee3d61cd62622d71005c47eb48d Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sat, 16 Nov 2013 20:50:54 +0000 Subject: [PATCH] Fix assert on unaligned access to global with different address space size. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194934 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- .../R600/32-bit-local-address-space.ll | 24 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index bac06ccaf57..85e5494b8e0 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -6372,7 +6372,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(GV), KnownZero, KnownOne, TLI->getDataLayout()); diff --git a/test/CodeGen/R600/32-bit-local-address-space.ll b/test/CodeGen/R600/32-bit-local-address-space.ll index 2ae467105af..566a422d9ef 100644 --- a/test/CodeGen/R600/32-bit-local-address-space.ll +++ b/test/CodeGen/R600/32-bit-local-address-space.ll @@ -50,4 +50,26 @@ define void @null_32bit_lds_ptr(i32 addrspace(1)* %out, i32 addrspace(3)* %lds) %x = select i1 %cmp, i32 123, i32 456 store i32 %x, i32 addrspace(1)* %out ret void -} \ No newline at end of file +} + +; CHECK-LABEL: @mul_32bit_ptr: +; CHECK: V_MUL_LO_I32 +; CHECK-NEXT: V_ADD_I32_e32 +; CHECK-NEXT: DS_READ_B32 +define void @mul_32bit_ptr(float addrspace(1)* %out, [3 x float] addrspace(3)* %lds, i32 %tid) { + %ptr = getelementptr [3 x float] addrspace(3)* %lds, i32 %tid, i32 0 + %val = load float addrspace(3)* %ptr + store float %val, float addrspace(1)* %out + ret void +} + +@g_lds = addrspace(3) global float zeroinitializer, align 4 + +; CHECK-LABEL: @infer_ptr_alignment_global_offset: +; CHECK: V_MOV_B32_e32 [[REG:v[0-9]+]], 0 +; CHECK: DS_READ_B32 v{{[0-9]+}}, 0, [[REG]] +define void @infer_ptr_alignment_global_offset(float addrspace(1)* %out, i32 %tid) { + %val = load float addrspace(3)* @g_lds + store float %val, float addrspace(1)* %out + ret void +}