R600/SI: Update MUBUF assembly string to match AMD proprietary compiler
[oota-llvm.git] / test / CodeGen / R600 / private-memory.ll
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
4
5 declare i32 @llvm.r600.read.tidig.x() nounwind readnone
6
7 ; FUNC-LABEL: @mova_same_clause
8
9 ; R600: LDS_WRITE
10 ; R600: LDS_WRITE
11 ; R600: LDS_READ
12 ; R600: LDS_READ
13
14 ; SI-PROMOTE: DS_WRITE_B32
15 ; SI-PROMOTE: DS_WRITE_B32
16 ; SI-PROMOTE: DS_READ_B32
17 ; SI-PROMOTE: DS_READ_B32
18
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) {
22 entry:
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
38   ret void
39 }
40
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.
44 ;
45 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
46 ; this.
47
48 ; FUNC-LABEL: @multiple_structs
49 ; R600-NOT: MOVA_INT
50 ; SI-NOT: V_MOVREL
51 ; SI-NOT: V_MOVREL
52 %struct.point = type { i32, i32 }
53
54 define void @multiple_structs(i32 addrspace(1)* %out) {
55 entry:
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
72   ret void
73 }
74
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
77 ; MOVA instructions.
78
79 ; FUNC-LABEL: @direct_loop
80 ; R600-NOT: MOVA_INT
81 ; SI-NOT: V_MOVREL
82
83 define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
84 entry:
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
94   br label %for.body
95
96 for.body:
97   %inc = phi i32 [0, %entry], [%count, %for.body]
98   %x_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
99   %x = load i32* %x_ptr
100   %y_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
101   %y = load i32* %y_ptr
102   %xy = add i32 %x, %y
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
107
108 for.end:
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
112   ret void
113 }
114
115 ; FUNC-LABEL: @short_array
116
117 ; R600: MOVA_INT
118
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) {
124 entry:
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
128   store i16 0, i16* %1
129   store i16 1, i16* %2
130   %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
131   %4 = load i16* %3
132   %5 = sext i16 %4 to i32
133   store i32 %5, i32 addrspace(1)* %out
134   ret void
135 }
136
137 ; FUNC-LABEL: @char_array
138
139 ; R600: MOVA_INT
140
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) {
144 entry:
145   %0 = alloca [2 x i8]
146   %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
147   %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
148   store i8 0, i8* %1
149   store i8 1, i8* %2
150   %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
151   %4 = load i8* %3
152   %5 = sext i8 %4 to i32
153   store i32 %5, i32 addrspace(1)* %out
154   ret void
155
156 }
157
158 ; Make sure we don't overwrite workitem information with private memory
159
160 ; FUNC-LABEL: @work_item_info
161 ; R600-NOT: MOV T0.X
162 ; Additional check in case the move ends up in the last slot
163 ; R600-NOT: MOV * TO.X
164
165 ; SI-NOT: V_MOV_B32_e{{(32|64)}} v0
166 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
167 entry:
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
171   store i32 0, i32* %1
172   store i32 1, i32* %2
173   %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
174   %4 = load i32* %3
175   %5 = call i32 @llvm.r600.read.tidig.x()
176   %6 = add i32 %4, %5
177   store i32 %6, i32 addrspace(1)* %out
178   ret void
179 }
180
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
184 ; R600_CHECK: MOV
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) {
189 entry:
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
197   store i8 0, i8* %2
198   store i8 1, i8* %3
199   store i8 2, i8* %4
200   store i8 1, i8* %5
201   store i8 0, i8* %6
202   %7 = getelementptr [3 x i8]* %0, i32 0, i32 %in
203   %8 = getelementptr [2 x i8]* %1, i32 0, i32 %in
204   %9 = load i8* %7
205   %10 = load i8* %8
206   %11 = add i8 %9, %10
207   %12 = sext i8 %11 to i32
208   store i32 %12, i32 addrspace(1)* %out
209   ret void
210 }
211
212 define void @char_array_array(i32 addrspace(1)* %out, i32 %index) {
213 entry:
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
223   ret void
224 }
225
226 define void @i32_array_array(i32 addrspace(1)* %out, i32 %index) {
227 entry:
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
236   ret void
237 }
238
239 define void @i64_array_array(i64 addrspace(1)* %out, i32 %index) {
240 entry:
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
249   ret void
250 }
251
252 %struct.pair32 = type { i32, i32 }
253
254 define void @struct_array_array(i32 addrspace(1)* %out, i32 %index) {
255 entry:
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
264   ret void
265 }
266
267 define void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) {
268 entry:
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
277   ret void
278 }
279
280 define void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
281 entry:
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
291   ret void
292 }
293