1 ; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck %s -check-prefix=R600 -check-prefix=FUNC
2 ; RUN: opt -S -mtriple=r600-unknown-unknown -mcpu=redwood -amdgpu-promote-alloca < %s | FileCheck -check-prefix=OPT %s
4 declare i32 @llvm.r600.read.tidig.x() nounwind readnone
6 ; FUNC-LABEL: {{^}}mova_same_clause:
13 ; OPT: call i32 @llvm.r600.read.local.size.y(), !range !0
14 ; OPT: call i32 @llvm.r600.read.local.size.z(), !range !0
15 ; OPT: call i32 @llvm.r600.read.tidig.x(), !range !1
16 ; OPT: call i32 @llvm.r600.read.tidig.y(), !range !1
17 ; OPT: call i32 @llvm.r600.read.tidig.z(), !range !1
19 define amdgpu_kernel void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) #0 {
21 %stack = alloca [5 x i32], align 4
22 %0 = load i32, i32 addrspace(1)* %in, align 4
23 %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %0
24 store i32 4, i32* %arrayidx1, align 4
25 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
26 %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4
27 %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %1
28 store i32 5, i32* %arrayidx3, align 4
29 %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 0
30 %2 = load i32, i32* %arrayidx10, align 4
31 store i32 %2, i32 addrspace(1)* %out, align 4
32 %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 1
33 %3 = load i32, i32* %arrayidx12
34 %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1
35 store i32 %3, i32 addrspace(1)* %arrayidx13
39 ; This test checks that the stack offset is calculated correctly for structs.
40 ; All register loads/stores should be optimized away, so there shouldn't be
41 ; any MOVA instructions.
43 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
46 ; FUNC-LABEL: {{^}}multiple_structs:
48 %struct.point = type { i32, i32 }
50 define amdgpu_kernel void @multiple_structs(i32 addrspace(1)* %out) #0 {
52 %a = alloca %struct.point
53 %b = alloca %struct.point
54 %a.x.ptr = getelementptr inbounds %struct.point, %struct.point* %a, i32 0, i32 0
55 %a.y.ptr = getelementptr inbounds %struct.point, %struct.point* %a, i32 0, i32 1
56 %b.x.ptr = getelementptr inbounds %struct.point, %struct.point* %b, i32 0, i32 0
57 %b.y.ptr = getelementptr inbounds %struct.point, %struct.point* %b, i32 0, i32 1
58 store i32 0, i32* %a.x.ptr
59 store i32 1, i32* %a.y.ptr
60 store i32 2, i32* %b.x.ptr
61 store i32 3, i32* %b.y.ptr
62 %a.indirect.ptr = getelementptr inbounds %struct.point, %struct.point* %a, i32 0, i32 0
63 %b.indirect.ptr = getelementptr inbounds %struct.point, %struct.point* %b, i32 0, i32 0
64 %a.indirect = load i32, i32* %a.indirect.ptr
65 %b.indirect = load i32, i32* %b.indirect.ptr
66 %0 = add i32 %a.indirect, %b.indirect
67 store i32 %0, i32 addrspace(1)* %out
71 ; Test direct access of a private array inside a loop. The private array
72 ; loads and stores should be lowered to copies, so there shouldn't be any
75 ; FUNC-LABEL: {{^}}direct_loop:
78 define amdgpu_kernel void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) #0 {
80 %prv_array_const = alloca [2 x i32]
81 %prv_array = alloca [2 x i32]
82 %a = load i32, i32 addrspace(1)* %in
83 %b_src_ptr = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
84 %b = load i32, i32 addrspace(1)* %b_src_ptr
85 %a_dst_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0
86 store i32 %a, i32* %a_dst_ptr
87 %b_dst_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 1
88 store i32 %b, i32* %b_dst_ptr
92 %inc = phi i32 [0, %entry], [%count, %for.body]
93 %x_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0
94 %x = load i32, i32* %x_ptr
95 %y_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0
96 %y = load i32, i32* %y_ptr
98 store i32 %xy, i32* %y_ptr
99 %count = add i32 %inc, 1
100 %done = icmp eq i32 %count, 4095
101 br i1 %done, label %for.end, label %for.body
104 %value_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0
105 %value = load i32, i32* %value_ptr
106 store i32 %value, i32 addrspace(1)* %out
110 ; FUNC-LABEL: {{^}}short_array:
113 define amdgpu_kernel void @short_array(i32 addrspace(1)* %out, i32 %index) #0 {
115 %0 = alloca [2 x i16]
116 %1 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 0
117 %2 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 1
120 %3 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 %index
121 %4 = load i16, i16* %3
122 %5 = sext i16 %4 to i32
123 store i32 %5, i32 addrspace(1)* %out
127 ; FUNC-LABEL: {{^}}char_array:
130 define amdgpu_kernel void @char_array(i32 addrspace(1)* %out, i32 %index) #0 {
133 %1 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 0
134 %2 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 1
137 %3 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 %index
139 %5 = sext i8 %4 to i32
140 store i32 %5, i32 addrspace(1)* %out
145 ; Make sure we don't overwrite workitem information with private memory
147 ; FUNC-LABEL: {{^}}work_item_info:
149 ; Additional check in case the move ends up in the last slot
150 ; R600-NOT: MOV * TO.X
151 define amdgpu_kernel void @work_item_info(i32 addrspace(1)* %out, i32 %in) #0 {
153 %0 = alloca [2 x i32]
154 %1 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i32 0, i32 0
155 %2 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i32 0, i32 1
158 %3 = getelementptr inbounds [2 x i32], [2 x i32]* %0, i32 0, i32 %in
159 %4 = load i32, i32* %3
160 %5 = call i32 @llvm.r600.read.tidig.x()
162 store i32 %6, i32 addrspace(1)* %out
166 ; Test that two stack objects are not stored in the same register
167 ; The second stack object should be in T3.X
168 ; FUNC-LABEL: {{^}}no_overlap:
170 ; R600_CHECK: [[CHAN:[XYZW]]]+
171 ; R600-NOT: [[CHAN]]+
172 define amdgpu_kernel void @no_overlap(i32 addrspace(1)* %out, i32 %in) #0 {
174 %0 = alloca [3 x i8], align 1
175 %1 = alloca [2 x i8], align 1
176 %2 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i32 0
177 %3 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i32 1
178 %4 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i32 2
179 %5 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i32 0, i32 0
180 %6 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i32 0, i32 1
186 %7 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i32 %in
187 %8 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i32 0, i32 %in
189 %10 = load i8, i8* %8
191 %12 = sext i8 %11 to i32
192 store i32 %12, i32 addrspace(1)* %out
196 define amdgpu_kernel void @char_array_array(i32 addrspace(1)* %out, i32 %index) #0 {
198 %alloca = alloca [2 x [2 x i8]]
199 %gep0 = getelementptr inbounds [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0
200 %gep1 = getelementptr inbounds [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1
201 store i8 0, i8* %gep0
202 store i8 1, i8* %gep1
203 %gep2 = getelementptr inbounds [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index
204 %load = load i8, i8* %gep2
205 %sext = sext i8 %load to i32
206 store i32 %sext, i32 addrspace(1)* %out
210 define amdgpu_kernel void @i32_array_array(i32 addrspace(1)* %out, i32 %index) #0 {
212 %alloca = alloca [2 x [2 x i32]]
213 %gep0 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0
214 %gep1 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1
215 store i32 0, i32* %gep0
216 store i32 1, i32* %gep1
217 %gep2 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index
218 %load = load i32, i32* %gep2
219 store i32 %load, i32 addrspace(1)* %out
223 define amdgpu_kernel void @i64_array_array(i64 addrspace(1)* %out, i32 %index) #0 {
225 %alloca = alloca [2 x [2 x i64]]
226 %gep0 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0
227 %gep1 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1
228 store i64 0, i64* %gep0
229 store i64 1, i64* %gep1
230 %gep2 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index
231 %load = load i64, i64* %gep2
232 store i64 %load, i64 addrspace(1)* %out
236 %struct.pair32 = type { i32, i32 }
238 define amdgpu_kernel void @struct_array_array(i32 addrspace(1)* %out, i32 %index) #0 {
240 %alloca = alloca [2 x [2 x %struct.pair32]]
241 %gep0 = getelementptr inbounds [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1
242 %gep1 = getelementptr inbounds [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1
243 store i32 0, i32* %gep0
244 store i32 1, i32* %gep1
245 %gep2 = getelementptr inbounds [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0
246 %load = load i32, i32* %gep2
247 store i32 %load, i32 addrspace(1)* %out
251 define amdgpu_kernel void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) #0 {
253 %alloca = alloca [2 x %struct.pair32]
254 %gep0 = getelementptr inbounds [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1
255 %gep1 = getelementptr inbounds [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0
256 store i32 0, i32* %gep0
257 store i32 1, i32* %gep1
258 %gep2 = getelementptr inbounds [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0
259 %load = load i32, i32* %gep2
260 store i32 %load, i32 addrspace(1)* %out
264 define amdgpu_kernel void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
266 %tmp = alloca [2 x i32]
267 %tmp1 = getelementptr inbounds [2 x i32], [2 x i32]* %tmp, i32 0, i32 0
268 %tmp2 = getelementptr inbounds [2 x i32], [2 x i32]* %tmp, i32 0, i32 1
269 store i32 0, i32* %tmp1
270 store i32 1, i32* %tmp2
271 %cmp = icmp eq i32 %in, 0
272 %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
273 %load = load i32, i32* %sel
274 store i32 %load, i32 addrspace(1)* %out
278 ; AMDGPUPromoteAlloca does not know how to handle ptrtoint. When it
279 ; finds one, it should stop trying to promote.
281 ; FUNC-LABEL: ptrtoint:
283 ; SI: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen
284 ; SI: buffer_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ;
285 define amdgpu_kernel void @ptrtoint(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
286 %alloca = alloca [16 x i32]
287 %tmp0 = getelementptr inbounds [16 x i32], [16 x i32]* %alloca, i32 0, i32 %a
288 store i32 5, i32* %tmp0
289 %tmp1 = ptrtoint [16 x i32]* %alloca to i32
290 %tmp2 = add i32 %tmp1, 5
291 %tmp3 = inttoptr i32 %tmp2 to i32*
292 %tmp4 = getelementptr inbounds i32, i32* %tmp3, i32 %b
293 %tmp5 = load i32, i32* %tmp4
294 store i32 %tmp5, i32 addrspace(1)* %out
298 ; OPT: !0 = !{i32 0, i32 257}
299 ; OPT: !1 = !{i32 0, i32 256}
301 attributes #0 = { nounwind "amdgpu-waves-per-eu"="1,2" }