1; RUN: llc -march=amdgcn -mcpu=SI -verify-machineinstrs< %s | FileCheck --check-prefix=SI --check-prefix=BOTH %s
2; RUN: llc -march=amdgcn -mcpu=bonaire -verify-machineinstrs< %s | FileCheck --check-prefix=CI --check-prefix=BOTH %s
3; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs< %s | FileCheck --check-prefix=CI --check-prefix=BOTH %s
4
5; BOTH-LABEL: {{^}}local_i32_load
6; BOTH: ds_read_b32 [[REG:v[0-9]+]], v{{[0-9]+}} offset:28
7; BOTH: buffer_store_dword [[REG]],
8define void @local_i32_load(i32 addrspace(1)* %out, i32 addrspace(3)* %in) nounwind {
9  %gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
10  %val = load i32, i32 addrspace(3)* %gep, align 4
11  store i32 %val, i32 addrspace(1)* %out, align 4
12  ret void
13}
14
15; BOTH-LABEL: {{^}}local_i32_load_0_offset
16; BOTH: ds_read_b32 [[REG:v[0-9]+]], v{{[0-9]+}}
17; BOTH: buffer_store_dword [[REG]],
18define void @local_i32_load_0_offset(i32 addrspace(1)* %out, i32 addrspace(3)* %in) nounwind {
19  %val = load i32, i32 addrspace(3)* %in, align 4
20  store i32 %val, i32 addrspace(1)* %out, align 4
21  ret void
22}
23
24; BOTH-LABEL: {{^}}local_i8_load_i16_max_offset:
25; BOTH-NOT: ADD
26; BOTH: ds_read_u8 [[REG:v[0-9]+]], {{v[0-9]+}} offset:65535
27; BOTH: buffer_store_byte [[REG]],
28define void @local_i8_load_i16_max_offset(i8 addrspace(1)* %out, i8 addrspace(3)* %in) nounwind {
29  %gep = getelementptr i8, i8 addrspace(3)* %in, i32 65535
30  %val = load i8, i8 addrspace(3)* %gep, align 4
31  store i8 %val, i8 addrspace(1)* %out, align 4
32  ret void
33}
34
35; BOTH-LABEL: {{^}}local_i8_load_over_i16_max_offset:
36; The LDS offset will be 65536 bytes, which is larger than the size of LDS on
37; SI, which is why it is being OR'd with the base pointer.
38; SI: s_or_b32 [[ADDR:s[0-9]+]], s{{[0-9]+}}, 0x10000
39; CI: s_add_i32 [[ADDR:s[0-9]+]], s{{[0-9]+}}, 0x10000
40; BOTH: v_mov_b32_e32 [[VREGADDR:v[0-9]+]], [[ADDR]]
41; BOTH: ds_read_u8 [[REG:v[0-9]+]], [[VREGADDR]]
42; BOTH: buffer_store_byte [[REG]],
43define void @local_i8_load_over_i16_max_offset(i8 addrspace(1)* %out, i8 addrspace(3)* %in) nounwind {
44  %gep = getelementptr i8, i8 addrspace(3)* %in, i32 65536
45  %val = load i8, i8 addrspace(3)* %gep, align 4
46  store i8 %val, i8 addrspace(1)* %out, align 4
47  ret void
48}
49
50; BOTH-LABEL: {{^}}local_i64_load:
51; BOTH-NOT: ADD
52; BOTH: ds_read_b64 [[REG:v[[0-9]+:[0-9]+]]], v{{[0-9]+}} offset:56
53; BOTH: buffer_store_dwordx2 [[REG]],
54define void @local_i64_load(i64 addrspace(1)* %out, i64 addrspace(3)* %in) nounwind {
55  %gep = getelementptr i64, i64 addrspace(3)* %in, i32 7
56  %val = load i64, i64 addrspace(3)* %gep, align 8
57  store i64 %val, i64 addrspace(1)* %out, align 8
58  ret void
59}
60
61; BOTH-LABEL: {{^}}local_i64_load_0_offset
62; BOTH: ds_read_b64 [[REG:v\[[0-9]+:[0-9]+\]]], v{{[0-9]+}}
63; BOTH: buffer_store_dwordx2 [[REG]],
64define void @local_i64_load_0_offset(i64 addrspace(1)* %out, i64 addrspace(3)* %in) nounwind {
65  %val = load i64, i64 addrspace(3)* %in, align 8
66  store i64 %val, i64 addrspace(1)* %out, align 8
67  ret void
68}
69
70; BOTH-LABEL: {{^}}local_f64_load:
71; BOTH-NOT: ADD
72; BOTH: ds_read_b64 [[REG:v[[0-9]+:[0-9]+]]], v{{[0-9]+}} offset:56
73; BOTH: buffer_store_dwordx2 [[REG]],
74define void @local_f64_load(double addrspace(1)* %out, double addrspace(3)* %in) nounwind {
75  %gep = getelementptr double, double addrspace(3)* %in, i32 7
76  %val = load double, double addrspace(3)* %gep, align 8
77  store double %val, double addrspace(1)* %out, align 8
78  ret void
79}
80
81; BOTH-LABEL: {{^}}local_f64_load_0_offset
82; BOTH: ds_read_b64 [[REG:v\[[0-9]+:[0-9]+\]]], v{{[0-9]+}}
83; BOTH: buffer_store_dwordx2 [[REG]],
84define void @local_f64_load_0_offset(double addrspace(1)* %out, double addrspace(3)* %in) nounwind {
85  %val = load double, double addrspace(3)* %in, align 8
86  store double %val, double addrspace(1)* %out, align 8
87  ret void
88}
89
90; BOTH-LABEL: {{^}}local_i64_store:
91; BOTH-NOT: ADD
92; BOTH: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:56
93define void @local_i64_store(i64 addrspace(3)* %out) nounwind {
94  %gep = getelementptr i64, i64 addrspace(3)* %out, i32 7
95  store i64 5678, i64 addrspace(3)* %gep, align 8
96  ret void
97}
98
99; BOTH-LABEL: {{^}}local_i64_store_0_offset:
100; BOTH-NOT: ADD
101; BOTH: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}
102define void @local_i64_store_0_offset(i64 addrspace(3)* %out) nounwind {
103  store i64 1234, i64 addrspace(3)* %out, align 8
104  ret void
105}
106
107; BOTH-LABEL: {{^}}local_f64_store:
108; BOTH-NOT: ADD
109; BOTH: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:56
110define void @local_f64_store(double addrspace(3)* %out) nounwind {
111  %gep = getelementptr double, double addrspace(3)* %out, i32 7
112  store double 16.0, double addrspace(3)* %gep, align 8
113  ret void
114}
115
116; BOTH-LABEL: {{^}}local_f64_store_0_offset
117; BOTH: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}
118define void @local_f64_store_0_offset(double addrspace(3)* %out) nounwind {
119  store double 20.0, double addrspace(3)* %out, align 8
120  ret void
121}
122
123; BOTH-LABEL: {{^}}local_v2i64_store:
124; BOTH-NOT: ADD
125; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:112
126; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:120
127; BOTH: s_endpgm
128define void @local_v2i64_store(<2 x i64> addrspace(3)* %out) nounwind {
129  %gep = getelementptr <2 x i64>, <2 x i64> addrspace(3)* %out, i32 7
130  store <2 x i64> <i64 5678, i64 5678>, <2 x i64> addrspace(3)* %gep, align 16
131  ret void
132}
133
134; BOTH-LABEL: {{^}}local_v2i64_store_0_offset:
135; BOTH-NOT: ADD
136; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}
137; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:8
138; BOTH: s_endpgm
139define void @local_v2i64_store_0_offset(<2 x i64> addrspace(3)* %out) nounwind {
140  store <2 x i64> <i64 1234, i64 1234>, <2 x i64> addrspace(3)* %out, align 16
141  ret void
142}
143
144; BOTH-LABEL: {{^}}local_v4i64_store:
145; BOTH-NOT: ADD
146; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:224
147; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:232
148; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:240
149; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:248
150; BOTH: s_endpgm
151define void @local_v4i64_store(<4 x i64> addrspace(3)* %out) nounwind {
152  %gep = getelementptr <4 x i64>, <4 x i64> addrspace(3)* %out, i32 7
153  store <4 x i64> <i64 5678, i64 5678, i64 5678, i64 5678>, <4 x i64> addrspace(3)* %gep, align 16
154  ret void
155}
156
157; BOTH-LABEL: {{^}}local_v4i64_store_0_offset:
158; BOTH-NOT: ADD
159; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}
160; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:8
161; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:16
162; BOTH-DAG: ds_write_b64 v{{[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}} offset:24
163; BOTH: s_endpgm
164define void @local_v4i64_store_0_offset(<4 x i64> addrspace(3)* %out) nounwind {
165  store <4 x i64> <i64 1234, i64 1234, i64 1234, i64 1234>, <4 x i64> addrspace(3)* %out, align 16
166  ret void
167}
168