1 ; RUN: llc -mtriple=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck -check-prefixes=SI,FUNC,GFX7 %s
2 ; RUN: llc -mtriple=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -check-prefixes=SI,FUNC,GFX8 %s
4 ; On Southern Islands GPUs the local address space(3) uses 32-bit pointers and
5 ; the global address space(1) uses 64-bit pointers. These tests check to make sure
6 ; the correct pointer size is used for the local address space.
8 ; The e{{32|64}} suffix on the instructions refers to the encoding size and not
9 ; the size of the operands. The operand size is denoted in the instruction name.
10 ; Instructions with B32, U32, and I32 in their name take 32-bit operands, while
11 ; instructions with B64, U64, and I64 take 64-bit operands.
13 ; FUNC-LABEL: {{^}}local_address_load:
14 ; SI: v_mov_b32_e{{32|64}} [[PTR:v[0-9]]]
15 ; SI: ds_read_b32 v{{[0-9]+}}, [[PTR]]
16 define amdgpu_kernel void @local_address_load(ptr addrspace(1) %out, ptr addrspace(3) %in) {
18 %0 = load i32, ptr addrspace(3) %in
19 store i32 %0, ptr addrspace(1) %out
23 ; FUNC-LABEL: {{^}}local_address_gep:
24 ; SI: s_add_i32 [[SPTR:s[0-9]]]
25 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
26 ; SI: ds_read_b32 [[VPTR]]
27 define amdgpu_kernel void @local_address_gep(ptr addrspace(1) %out, ptr addrspace(3) %in, i32 %offset) {
29 %0 = getelementptr i32, ptr addrspace(3) %in, i32 %offset
30 %1 = load i32, ptr addrspace(3) %0
31 store i32 %1, ptr addrspace(1) %out
35 ; FUNC-LABEL: {{^}}local_address_gep_const_offset:
36 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], s{{[0-9]+}}
37 ; SI: ds_read_b32 v{{[0-9]+}}, [[VPTR]] offset:4
38 define amdgpu_kernel void @local_address_gep_const_offset(ptr addrspace(1) %out, ptr addrspace(3) %in) {
40 %0 = getelementptr i32, ptr addrspace(3) %in, i32 1
41 %1 = load i32, ptr addrspace(3) %0
42 store i32 %1, ptr addrspace(1) %out
46 ; Offset too large, can't fold into 16-bit immediate offset.
47 ; FUNC-LABEL: {{^}}local_address_gep_large_const_offset:
48 ; SI: s_add_i32 [[SPTR:s[0-9]]], s{{[0-9]+}}, 0x10004
49 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
50 ; SI: ds_read_b32 [[VPTR]]
51 define amdgpu_kernel void @local_address_gep_large_const_offset(ptr addrspace(1) %out, ptr addrspace(3) %in) {
53 %0 = getelementptr i32, ptr addrspace(3) %in, i32 16385
54 %1 = load i32, ptr addrspace(3) %0
55 store i32 %1, ptr addrspace(1) %out
59 ; FUNC-LABEL: {{^}}null_32bit_lds_ptr:
63 ; GFX8-NOT: v_cmp_ne_u32
65 define amdgpu_kernel void @null_32bit_lds_ptr(ptr addrspace(1) %out, ptr addrspace(3) %lds) nounwind {
66 %cmp = icmp ne ptr addrspace(3) %lds, null
67 %x = select i1 %cmp, i32 123, i32 456
68 store i32 %x, ptr addrspace(1) %out
72 ; FUNC-LABEL: {{^}}mul_32bit_ptr:
76 define amdgpu_kernel void @mul_32bit_ptr(ptr addrspace(1) %out, ptr addrspace(3) %lds, i32 %tid) {
77 %ptr = getelementptr [3 x float], ptr addrspace(3) %lds, i32 %tid, i32 0
78 %val = load float, ptr addrspace(3) %ptr
79 store float %val, ptr addrspace(1) %out
83 @g_lds = addrspace(3) global float undef, align 4
85 ; FUNC-LABEL: {{^}}infer_ptr_alignment_global_offset:
86 ; SI: v_mov_b32_e32 [[PTR:v[0-9]+]], 0{{$}}
87 ; SI: ds_read_b32 v{{[0-9]+}}, [[PTR]]
88 define amdgpu_kernel void @infer_ptr_alignment_global_offset(ptr addrspace(1) %out, i32 %tid) {
89 %val = load float, ptr addrspace(3) @g_lds
90 store float %val, ptr addrspace(1) %out
95 @ptr = addrspace(3) global ptr addrspace(3) undef
96 @dst = addrspace(3) global [16383 x i32] undef
98 ; FUNC-LABEL: {{^}}global_ptr:
100 define amdgpu_kernel void @global_ptr() nounwind {
101 store ptr addrspace(3) getelementptr ([16383 x i32], ptr addrspace(3) @dst, i32 0, i32 16), ptr addrspace(3) @ptr
105 ; FUNC-LABEL: {{^}}local_address_store:
107 define amdgpu_kernel void @local_address_store(ptr addrspace(3) %out, i32 %val) {
108 store i32 %val, ptr addrspace(3) %out
112 ; FUNC-LABEL: {{^}}local_address_gep_store:
113 ; SI: s_add_i32 [[SADDR:s[0-9]+]],
114 ; SI: v_mov_b32_e32 [[ADDR:v[0-9]+]], [[SADDR]]
115 ; SI: ds_write_b32 [[ADDR]], v{{[0-9]+}}
116 define amdgpu_kernel void @local_address_gep_store(ptr addrspace(3) %out, i32, i32 %val, i32 %offset) {
117 %gep = getelementptr i32, ptr addrspace(3) %out, i32 %offset
118 store i32 %val, ptr addrspace(3) %gep, align 4
122 ; FUNC-LABEL: {{^}}local_address_gep_const_offset_store:
123 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], s{{[0-9]+}}
124 ; SI: v_mov_b32_e32 [[VAL:v[0-9]+]], s{{[0-9]+}}
125 ; SI: ds_write_b32 [[VPTR]], [[VAL]] offset:4
126 define amdgpu_kernel void @local_address_gep_const_offset_store(ptr addrspace(3) %out, i32 %val) {
127 %gep = getelementptr i32, ptr addrspace(3) %out, i32 1
128 store i32 %val, ptr addrspace(3) %gep, align 4
132 ; Offset too large, can't fold into 16-bit immediate offset.
133 ; FUNC-LABEL: {{^}}local_address_gep_large_const_offset_store:
134 ; SI: s_add_i32 [[SPTR:s[0-9]]], s{{[0-9]+}}, 0x10004
135 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
136 ; SI: ds_write_b32 [[VPTR]], v{{[0-9]+$}}
137 define amdgpu_kernel void @local_address_gep_large_const_offset_store(ptr addrspace(3) %out, i32 %val) {
138 %gep = getelementptr i32, ptr addrspace(3) %out, i32 16385
139 store i32 %val, ptr addrspace(3) %gep, align 4