1 ; RUN: llc -march=amdgcn -mcpu=verde -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
3 ; On Southern Islands GPUs the local address space(3) uses 32-bit pointers and
4 ; the global address space(1) uses 64-bit pointers. These tests check to make sure
5 ; the correct pointer size is used for the local address space.
7 ; The e{{32|64}} suffix on the instructions refers to the encoding size and not
8 ; the size of the operands. The operand size is denoted in the instruction name.
9 ; Instructions with B32, U32, and I32 in their name take 32-bit operands, while
10 ; instructions with B64, U64, and I64 take 64-bit operands.
12 ; FUNC-LABEL: {{^}}local_address_load:
13 ; SI: v_mov_b32_e{{32|64}} [[PTR:v[0-9]]]
14 ; SI: ds_read_b32 v{{[0-9]+}}, [[PTR]]
15 define void @local_address_load(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
17 %0 = load i32 addrspace(3)* %in
18 store i32 %0, i32 addrspace(1)* %out
22 ; FUNC-LABEL: {{^}}local_address_gep:
23 ; SI: s_add_i32 [[SPTR:s[0-9]]]
24 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
25 ; SI: ds_read_b32 [[VPTR]]
26 define void @local_address_gep(i32 addrspace(1)* %out, i32 addrspace(3)* %in, i32 %offset) {
28 %0 = getelementptr i32 addrspace(3)* %in, i32 %offset
29 %1 = load i32 addrspace(3)* %0
30 store i32 %1, i32 addrspace(1)* %out
34 ; FUNC-LABEL: {{^}}local_address_gep_const_offset:
35 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], s{{[0-9]+}}
36 ; SI: ds_read_b32 v{{[0-9]+}}, [[VPTR]] offset:4
37 define void @local_address_gep_const_offset(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
39 %0 = getelementptr i32 addrspace(3)* %in, i32 1
40 %1 = load i32 addrspace(3)* %0
41 store i32 %1, i32 addrspace(1)* %out
45 ; Offset too large, can't fold into 16-bit immediate offset.
46 ; FUNC-LABEL: {{^}}local_address_gep_large_const_offset:
47 ; SI: s_add_i32 [[SPTR:s[0-9]]], s{{[0-9]+}}, 0x10004
48 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
49 ; SI: ds_read_b32 [[VPTR]]
50 define void @local_address_gep_large_const_offset(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
52 %0 = getelementptr i32 addrspace(3)* %in, i32 16385
53 %1 = load i32 addrspace(3)* %0
54 store i32 %1, i32 addrspace(1)* %out
58 ; FUNC-LABEL: {{^}}null_32bit_lds_ptr:
60 ; SI-NOT: v_cmp_ne_i32
62 define void @null_32bit_lds_ptr(i32 addrspace(1)* %out, i32 addrspace(3)* %lds) nounwind {
63 %cmp = icmp ne i32 addrspace(3)* %lds, null
64 %x = select i1 %cmp, i32 123, i32 456
65 store i32 %x, i32 addrspace(1)* %out
69 ; FUNC-LABEL: {{^}}mul_32bit_ptr:
73 define void @mul_32bit_ptr(float addrspace(1)* %out, [3 x float] addrspace(3)* %lds, i32 %tid) {
74 %ptr = getelementptr [3 x float] addrspace(3)* %lds, i32 %tid, i32 0
75 %val = load float addrspace(3)* %ptr
76 store float %val, float addrspace(1)* %out
80 @g_lds = addrspace(3) global float undef, align 4
82 ; FUNC-LABEL: {{^}}infer_ptr_alignment_global_offset:
83 ; SI: v_mov_b32_e32 [[REG:v[0-9]+]], 0
84 ; SI: ds_read_b32 v{{[0-9]+}}, [[REG]]
85 define void @infer_ptr_alignment_global_offset(float addrspace(1)* %out, i32 %tid) {
86 %val = load float addrspace(3)* @g_lds
87 store float %val, float addrspace(1)* %out
92 @ptr = addrspace(3) global i32 addrspace(3)* undef
93 @dst = addrspace(3) global [16384 x i32] undef
95 ; FUNC-LABEL: {{^}}global_ptr:
97 define void @global_ptr() nounwind {
98 store i32 addrspace(3)* getelementptr ([16384 x i32] addrspace(3)* @dst, i32 0, i32 16), i32 addrspace(3)* addrspace(3)* @ptr
102 ; FUNC-LABEL: {{^}}local_address_store:
104 define void @local_address_store(i32 addrspace(3)* %out, i32 %val) {
105 store i32 %val, i32 addrspace(3)* %out
109 ; FUNC-LABEL: {{^}}local_address_gep_store:
110 ; SI: s_add_i32 [[SADDR:s[0-9]+]],
111 ; SI: v_mov_b32_e32 [[ADDR:v[0-9]+]], [[SADDR]]
112 ; SI: ds_write_b32 [[ADDR]], v{{[0-9]+}}
113 define void @local_address_gep_store(i32 addrspace(3)* %out, i32, i32 %val, i32 %offset) {
114 %gep = getelementptr i32 addrspace(3)* %out, i32 %offset
115 store i32 %val, i32 addrspace(3)* %gep, align 4
119 ; FUNC-LABEL: {{^}}local_address_gep_const_offset_store:
120 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], s{{[0-9]+}}
121 ; SI: v_mov_b32_e32 [[VAL:v[0-9]+]], s{{[0-9]+}}
122 ; SI: ds_write_b32 [[VPTR]], [[VAL]] offset:4
123 define void @local_address_gep_const_offset_store(i32 addrspace(3)* %out, i32 %val) {
124 %gep = getelementptr i32 addrspace(3)* %out, i32 1
125 store i32 %val, i32 addrspace(3)* %gep, align 4
129 ; Offset too large, can't fold into 16-bit immediate offset.
130 ; FUNC-LABEL: {{^}}local_address_gep_large_const_offset_store:
131 ; SI: s_add_i32 [[SPTR:s[0-9]]], s{{[0-9]+}}, 0x10004
132 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
133 ; SI: ds_write_b32 [[VPTR]], v{{[0-9]+}} [M0]{{$}}
134 define void @local_address_gep_large_const_offset_store(i32 addrspace(3)* %out, i32 %val) {
135 %gep = getelementptr i32 addrspace(3)* %out, i32 16385
136 store i32 %val, i32 addrspace(3)* %gep, align 4