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]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}}
20 ; SI-ALLOCA: BUFFER_STORE_DWORD v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[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]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}}
120 ; SI-PROMOTE: BUFFER_STORE_SHORT v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}}
121 ; SI-PROMOTE-NOT: MOVREL
122 ; SI-PROMOTE: BUFFER_LOAD_SSHORT v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}}
123 define void @short_array(i32 addrspace(1)* %out, i32 %index) {
125 %0 = alloca [2 x i16]
126 %1 = getelementptr [2 x i16]* %0, i32 0, i32 0
127 %2 = getelementptr [2 x i16]* %0, i32 0, i32 1
130 %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
132 %5 = sext i16 %4 to i32
133 store i32 %5, i32 addrspace(1)* %out
137 ; FUNC-LABEL: @char_array
141 ; SI-DAG: BUFFER_STORE_BYTE v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} {{offen$}}
142 ; SI-DAG: BUFFER_STORE_BYTE v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:0x1
143 define void @char_array(i32 addrspace(1)* %out, i32 %index) {
146 %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
147 %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
150 %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
152 %5 = sext i8 %4 to i32
153 store i32 %5, i32 addrspace(1)* %out
158 ; Make sure we don't overwrite workitem information with private memory
160 ; FUNC-LABEL: @work_item_info
162 ; Additional check in case the move ends up in the last slot
163 ; R600-NOT: MOV * TO.X
165 ; SI-NOT: V_MOV_B32_e{{(32|64)}} v0
166 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
168 %0 = alloca [2 x i32]
169 %1 = getelementptr [2 x i32]* %0, i32 0, i32 0
170 %2 = getelementptr [2 x i32]* %0, i32 0, i32 1
173 %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
175 %5 = call i32 @llvm.r600.read.tidig.x()
177 store i32 %6, i32 addrspace(1)* %out
181 ; Test that two stack objects are not stored in the same register
182 ; The second stack object should be in T3.X
183 ; FUNC-LABEL: @no_overlap
185 ; R600_CHECK: [[CHAN:[XYZW]]]+
186 ; R600-NOT: [[CHAN]]+
187 ; SI: V_MOV_B32_e32 v3
188 define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
190 %0 = alloca [3 x i8], align 1
191 %1 = alloca [2 x i8], align 1
192 %2 = getelementptr [3 x i8]* %0, i32 0, i32 0
193 %3 = getelementptr [3 x i8]* %0, i32 0, i32 1
194 %4 = getelementptr [3 x i8]* %0, i32 0, i32 2
195 %5 = getelementptr [2 x i8]* %1, i32 0, i32 0
196 %6 = getelementptr [2 x i8]* %1, i32 0, i32 1
202 %7 = getelementptr [3 x i8]* %0, i32 0, i32 %in
203 %8 = getelementptr [2 x i8]* %1, i32 0, i32 %in
207 %12 = sext i8 %11 to i32
208 store i32 %12, i32 addrspace(1)* %out
212 define void @char_array_array(i32 addrspace(1)* %out, i32 %index) {
214 %alloca = alloca [2 x [2 x i8]]
215 %gep0 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0
216 %gep1 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1
217 store i8 0, i8* %gep0
218 store i8 1, i8* %gep1
219 %gep2 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index
220 %load = load i8* %gep2
221 %sext = sext i8 %load to i32
222 store i32 %sext, i32 addrspace(1)* %out
226 define void @i32_array_array(i32 addrspace(1)* %out, i32 %index) {
228 %alloca = alloca [2 x [2 x i32]]
229 %gep0 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0
230 %gep1 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1
231 store i32 0, i32* %gep0
232 store i32 1, i32* %gep1
233 %gep2 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index
234 %load = load i32* %gep2
235 store i32 %load, i32 addrspace(1)* %out
239 define void @i64_array_array(i64 addrspace(1)* %out, i32 %index) {
241 %alloca = alloca [2 x [2 x i64]]
242 %gep0 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0
243 %gep1 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1
244 store i64 0, i64* %gep0
245 store i64 1, i64* %gep1
246 %gep2 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index
247 %load = load i64* %gep2
248 store i64 %load, i64 addrspace(1)* %out
252 %struct.pair32 = type { i32, i32 }
254 define void @struct_array_array(i32 addrspace(1)* %out, i32 %index) {
256 %alloca = alloca [2 x [2 x %struct.pair32]]
257 %gep0 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1
258 %gep1 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1
259 store i32 0, i32* %gep0
260 store i32 1, i32* %gep1
261 %gep2 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0
262 %load = load i32* %gep2
263 store i32 %load, i32 addrspace(1)* %out
267 define void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) {
269 %alloca = alloca [2 x %struct.pair32]
270 %gep0 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1
271 %gep1 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0
272 store i32 0, i32* %gep0
273 store i32 1, i32* %gep1
274 %gep2 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0
275 %load = load i32* %gep2
276 store i32 %load, i32 addrspace(1)* %out
280 define void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
282 %tmp = alloca [2 x i32]
283 %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
284 %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
285 store i32 0, i32* %tmp1
286 store i32 1, i32* %tmp2
287 %cmp = icmp eq i32 %in, 0
288 %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
289 %load = load i32* %sel
290 store i32 %load, i32 addrspace(1)* %out