1 ; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck %s -check-prefix=R600 -check-prefix=FUNC
2 ; RUN: llc -mattr=+promote-alloca -verify-machineinstrs -march=r600 -mcpu=SI < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC
3 ; RUN: llc -mattr=-promote-alloca -verify-machineinstrs -march=r600 -mcpu=SI < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC
5 declare i32 @llvm.r600.read.tidig.x() nounwind readnone
7 ; FUNC-LABEL: @mova_same_clause
14 ; SI-PROMOTE: DS_WRITE_B32
15 ; SI-PROMOTE: DS_WRITE_B32
16 ; SI-PROMOTE: DS_READ_B32
17 ; SI-PROMOTE: DS_READ_B32
19 ; SI-ALLOCA: BUFFER_STORE_DWORD v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], v{{[0-9]+}}, s{{[0-9]+}}
20 ; SI-ALLOCA: BUFFER_STORE_DWORD v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], v{{[0-9]+}}, s{{[0-9]+}}
21 define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
23 %stack = alloca [5 x i32], align 4
24 %0 = load i32 addrspace(1)* %in, align 4
25 %arrayidx1 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %0
26 store i32 4, i32* %arrayidx1, align 4
27 %arrayidx2 = getelementptr inbounds i32 addrspace(1)* %in, i32 1
28 %1 = load i32 addrspace(1)* %arrayidx2, align 4
29 %arrayidx3 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %1
30 store i32 5, i32* %arrayidx3, align 4
31 %arrayidx10 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 0
32 %2 = load i32* %arrayidx10, align 4
33 store i32 %2, i32 addrspace(1)* %out, align 4
34 %arrayidx12 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 1
35 %3 = load i32* %arrayidx12
36 %arrayidx13 = getelementptr inbounds i32 addrspace(1)* %out, i32 1
37 store i32 %3, i32 addrspace(1)* %arrayidx13
41 ; This test checks that the stack offset is calculated correctly for structs.
42 ; All register loads/stores should be optimized away, so there shouldn't be
43 ; any MOVA instructions.
45 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
48 ; FUNC-LABEL: @multiple_structs
52 %struct.point = type { i32, i32 }
54 define void @multiple_structs(i32 addrspace(1)* %out) {
56 %a = alloca %struct.point
57 %b = alloca %struct.point
58 %a.x.ptr = getelementptr %struct.point* %a, i32 0, i32 0
59 %a.y.ptr = getelementptr %struct.point* %a, i32 0, i32 1
60 %b.x.ptr = getelementptr %struct.point* %b, i32 0, i32 0
61 %b.y.ptr = getelementptr %struct.point* %b, i32 0, i32 1
62 store i32 0, i32* %a.x.ptr
63 store i32 1, i32* %a.y.ptr
64 store i32 2, i32* %b.x.ptr
65 store i32 3, i32* %b.y.ptr
66 %a.indirect.ptr = getelementptr %struct.point* %a, i32 0, i32 0
67 %b.indirect.ptr = getelementptr %struct.point* %b, i32 0, i32 0
68 %a.indirect = load i32* %a.indirect.ptr
69 %b.indirect = load i32* %b.indirect.ptr
70 %0 = add i32 %a.indirect, %b.indirect
71 store i32 %0, i32 addrspace(1)* %out
75 ; Test direct access of a private array inside a loop. The private array
76 ; loads and stores should be lowered to copies, so there shouldn't be any
79 ; FUNC-LABEL: @direct_loop
83 define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
85 %prv_array_const = alloca [2 x i32]
86 %prv_array = alloca [2 x i32]
87 %a = load i32 addrspace(1)* %in
88 %b_src_ptr = getelementptr i32 addrspace(1)* %in, i32 1
89 %b = load i32 addrspace(1)* %b_src_ptr
90 %a_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
91 store i32 %a, i32* %a_dst_ptr
92 %b_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 1
93 store i32 %b, i32* %b_dst_ptr
97 %inc = phi i32 [0, %entry], [%count, %for.body]
98 %x_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
100 %y_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
101 %y = load i32* %y_ptr
103 store i32 %xy, i32* %y_ptr
104 %count = add i32 %inc, 1
105 %done = icmp eq i32 %count, 4095
106 br i1 %done, label %for.end, label %for.body
109 %value_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
110 %value = load i32* %value_ptr
111 store i32 %value, i32 addrspace(1)* %out
115 ; FUNC-LABEL: @short_array
119 ; SI-PROMOTE: BUFFER_STORE_SHORT v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], v{{[0-9]+}}, s{{[0-9]+}}
120 ; SI-PROMOTE: BUFFER_STORE_SHORT v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], v{{[0-9]+}}, s{{[0-9]+}}
121 ; SI_PROMOTE: BUFFER_LOAD_SSHORT v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}] + v{{[0-9]+}}, s{{[0-9]+}}
122 define void @short_array(i32 addrspace(1)* %out, i32 %index) {
124 %0 = alloca [2 x i16]
125 %1 = getelementptr [2 x i16]* %0, i32 0, i32 0
126 %2 = getelementptr [2 x i16]* %0, i32 0, i32 1
129 %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
131 %5 = sext i16 %4 to i32
132 store i32 %5, i32 addrspace(1)* %out
136 ; FUNC-LABEL: @char_array
140 ; SI-DAG: BUFFER_STORE_BYTE v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], v{{[0-9]+}}, s{{[0-9]+}}, 0x0
141 ; SI-DAG: BUFFER_STORE_BYTE v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], v{{[0-9]+}}, s{{[0-9]+}}, 0x1
142 define void @char_array(i32 addrspace(1)* %out, i32 %index) {
145 %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
146 %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
149 %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
151 %5 = sext i8 %4 to i32
152 store i32 %5, i32 addrspace(1)* %out
157 ; Make sure we don't overwrite workitem information with private memory
159 ; FUNC-LABEL: @work_item_info
161 ; Additional check in case the move ends up in the last slot
162 ; R600-NOT: MOV * TO.X
164 ; SI-NOT: V_MOV_B32_e{{(32|64)}} v0
165 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
167 %0 = alloca [2 x i32]
168 %1 = getelementptr [2 x i32]* %0, i32 0, i32 0
169 %2 = getelementptr [2 x i32]* %0, i32 0, i32 1
172 %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
174 %5 = call i32 @llvm.r600.read.tidig.x()
176 store i32 %6, i32 addrspace(1)* %out
180 ; Test that two stack objects are not stored in the same register
181 ; The second stack object should be in T3.X
182 ; FUNC-LABEL: @no_overlap
184 ; R600_CHECK: [[CHAN:[XYZW]]]+
185 ; R600-NOT: [[CHAN]]+
186 ; SI: V_MOV_B32_e32 v3
187 define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
189 %0 = alloca [3 x i8], align 1
190 %1 = alloca [2 x i8], align 1
191 %2 = getelementptr [3 x i8]* %0, i32 0, i32 0
192 %3 = getelementptr [3 x i8]* %0, i32 0, i32 1
193 %4 = getelementptr [3 x i8]* %0, i32 0, i32 2
194 %5 = getelementptr [2 x i8]* %1, i32 0, i32 0
195 %6 = getelementptr [2 x i8]* %1, i32 0, i32 1
201 %7 = getelementptr [3 x i8]* %0, i32 0, i32 %in
202 %8 = getelementptr [2 x i8]* %1, i32 0, i32 %in
206 %12 = sext i8 %11 to i32
207 store i32 %12, i32 addrspace(1)* %out
211 define void @char_array_array(i32 addrspace(1)* %out, i32 %index) {
213 %alloca = alloca [2 x [2 x i8]]
214 %gep0 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0
215 %gep1 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1
216 store i8 0, i8* %gep0
217 store i8 1, i8* %gep1
218 %gep2 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index
219 %load = load i8* %gep2
220 %sext = sext i8 %load to i32
221 store i32 %sext, i32 addrspace(1)* %out
225 define void @i32_array_array(i32 addrspace(1)* %out, i32 %index) {
227 %alloca = alloca [2 x [2 x i32]]
228 %gep0 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0
229 %gep1 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1
230 store i32 0, i32* %gep0
231 store i32 1, i32* %gep1
232 %gep2 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index
233 %load = load i32* %gep2
234 store i32 %load, i32 addrspace(1)* %out
238 define void @i64_array_array(i64 addrspace(1)* %out, i32 %index) {
240 %alloca = alloca [2 x [2 x i64]]
241 %gep0 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0
242 %gep1 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1
243 store i64 0, i64* %gep0
244 store i64 1, i64* %gep1
245 %gep2 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index
246 %load = load i64* %gep2
247 store i64 %load, i64 addrspace(1)* %out
251 %struct.pair32 = type { i32, i32 }
253 define void @struct_array_array(i32 addrspace(1)* %out, i32 %index) {
255 %alloca = alloca [2 x [2 x %struct.pair32]]
256 %gep0 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1
257 %gep1 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1
258 store i32 0, i32* %gep0
259 store i32 1, i32* %gep1
260 %gep2 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0
261 %load = load i32* %gep2
262 store i32 %load, i32 addrspace(1)* %out
266 define void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) {
268 %alloca = alloca [2 x %struct.pair32]
269 %gep0 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1
270 %gep1 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0
271 store i32 0, i32* %gep0
272 store i32 1, i32* %gep1
273 %gep2 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0
274 %load = load i32* %gep2
275 store i32 %load, i32 addrspace(1)* %out
279 define void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
281 %tmp = alloca [2 x i32]
282 %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
283 %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
284 store i32 0, i32* %tmp1
285 store i32 1, i32* %tmp2
286 %cmp = icmp eq i32 %in, 0
287 %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
288 %load = load i32* %sel
289 store i32 %load, i32 addrspace(1)* %out