R600: Run private-memory test with and without alloca promote
[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: V_READFIRSTLANE_B32 vcc_lo
20 ; SI-ALLOCA: V_MOVRELD
21 ; SI-ALLOCA: S_CBRANCH
22 ; SI-ALLOCA: V_READFIRSTLANE_B32 vcc_lo
23 ; SI-ALLOCA: V_MOVRELD
24 ; SI-ALLOCA: S_CBRANCH
25 define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
26 entry:
27   %stack = alloca [5 x i32], align 4
28   %0 = load i32 addrspace(1)* %in, align 4
29   %arrayidx1 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %0
30   store i32 4, i32* %arrayidx1, align 4
31   %arrayidx2 = getelementptr inbounds i32 addrspace(1)* %in, i32 1
32   %1 = load i32 addrspace(1)* %arrayidx2, align 4
33   %arrayidx3 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 %1
34   store i32 5, i32* %arrayidx3, align 4
35   %arrayidx10 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 0
36   %2 = load i32* %arrayidx10, align 4
37   store i32 %2, i32 addrspace(1)* %out, align 4
38   %arrayidx12 = getelementptr inbounds [5 x i32]* %stack, i32 0, i32 1
39   %3 = load i32* %arrayidx12
40   %arrayidx13 = getelementptr inbounds i32 addrspace(1)* %out, i32 1
41   store i32 %3, i32 addrspace(1)* %arrayidx13
42   ret void
43 }
44
45 ; This test checks that the stack offset is calculated correctly for structs.
46 ; All register loads/stores should be optimized away, so there shouldn't be
47 ; any MOVA instructions.
48 ;
49 ; XXX: This generated code has unnecessary MOVs, we should be able to optimize
50 ; this.
51
52 ; FUNC-LABEL: @multiple_structs
53 ; R600-NOT: MOVA_INT
54 ; SI-NOT: V_MOVREL
55 ; SI-NOT: V_MOVREL
56 %struct.point = type { i32, i32 }
57
58 define void @multiple_structs(i32 addrspace(1)* %out) {
59 entry:
60   %a = alloca %struct.point
61   %b = alloca %struct.point
62   %a.x.ptr = getelementptr %struct.point* %a, i32 0, i32 0
63   %a.y.ptr = getelementptr %struct.point* %a, i32 0, i32 1
64   %b.x.ptr = getelementptr %struct.point* %b, i32 0, i32 0
65   %b.y.ptr = getelementptr %struct.point* %b, i32 0, i32 1
66   store i32 0, i32* %a.x.ptr
67   store i32 1, i32* %a.y.ptr
68   store i32 2, i32* %b.x.ptr
69   store i32 3, i32* %b.y.ptr
70   %a.indirect.ptr = getelementptr %struct.point* %a, i32 0, i32 0
71   %b.indirect.ptr = getelementptr %struct.point* %b, i32 0, i32 0
72   %a.indirect = load i32* %a.indirect.ptr
73   %b.indirect = load i32* %b.indirect.ptr
74   %0 = add i32 %a.indirect, %b.indirect
75   store i32 %0, i32 addrspace(1)* %out
76   ret void
77 }
78
79 ; Test direct access of a private array inside a loop.  The private array
80 ; loads and stores should be lowered to copies, so there shouldn't be any
81 ; MOVA instructions.
82
83 ; FUNC-LABEL: @direct_loop
84 ; R600-NOT: MOVA_INT
85 ; SI-NOT: V_MOVREL
86
87 define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
88 entry:
89   %prv_array_const = alloca [2 x i32]
90   %prv_array = alloca [2 x i32]
91   %a = load i32 addrspace(1)* %in
92   %b_src_ptr = getelementptr i32 addrspace(1)* %in, i32 1
93   %b = load i32 addrspace(1)* %b_src_ptr
94   %a_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
95   store i32 %a, i32* %a_dst_ptr
96   %b_dst_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 1
97   store i32 %b, i32* %b_dst_ptr
98   br label %for.body
99
100 for.body:
101   %inc = phi i32 [0, %entry], [%count, %for.body]
102   %x_ptr = getelementptr [2 x i32]* %prv_array_const, i32 0, i32 0
103   %x = load i32* %x_ptr
104   %y_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
105   %y = load i32* %y_ptr
106   %xy = add i32 %x, %y
107   store i32 %xy, i32* %y_ptr
108   %count = add i32 %inc, 1
109   %done = icmp eq i32 %count, 4095
110   br i1 %done, label %for.end, label %for.body
111
112 for.end:
113   %value_ptr = getelementptr [2 x i32]* %prv_array, i32 0, i32 0
114   %value = load i32* %value_ptr
115   store i32 %value, i32 addrspace(1)* %out
116   ret void
117 }
118
119 ; FUNC-LABEL: @short_array
120
121 ; R600: MOVA_INT
122
123 ; SI-PROMOTE: V_MOVRELS_B32_e32
124 define void @short_array(i32 addrspace(1)* %out, i32 %index) {
125 entry:
126   %0 = alloca [2 x i16]
127   %1 = getelementptr [2 x i16]* %0, i32 0, i32 0
128   %2 = getelementptr [2 x i16]* %0, i32 0, i32 1
129   store i16 0, i16* %1
130   store i16 1, i16* %2
131   %3 = getelementptr [2 x i16]* %0, i32 0, i32 %index
132   %4 = load i16* %3
133   %5 = sext i16 %4 to i32
134   store i32 %5, i32 addrspace(1)* %out
135   ret void
136 }
137
138 ; FUNC-LABEL: @char_array
139
140 ; R600: MOVA_INT
141
142 ; SI: V_OR_B32_e32 v{{[0-9]}}, 0x100
143 ; SI: V_MOVRELS_B32_e32
144 define void @char_array(i32 addrspace(1)* %out, i32 %index) {
145 entry:
146   %0 = alloca [2 x i8]
147   %1 = getelementptr [2 x i8]* %0, i32 0, i32 0
148   %2 = getelementptr [2 x i8]* %0, i32 0, i32 1
149   store i8 0, i8* %1
150   store i8 1, i8* %2
151   %3 = getelementptr [2 x i8]* %0, i32 0, i32 %index
152   %4 = load i8* %3
153   %5 = sext i8 %4 to i32
154   store i32 %5, i32 addrspace(1)* %out
155   ret void
156
157 }
158
159 ; Make sure we don't overwrite workitem information with private memory
160
161 ; FUNC-LABEL: @work_item_info
162 ; R600-NOT: MOV T0.X
163 ; Additional check in case the move ends up in the last slot
164 ; R600-NOT: MOV * TO.X
165
166 ; SI-NOT: V_MOV_B32_e{{(32|64)}} v0
167 define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
168 entry:
169   %0 = alloca [2 x i32]
170   %1 = getelementptr [2 x i32]* %0, i32 0, i32 0
171   %2 = getelementptr [2 x i32]* %0, i32 0, i32 1
172   store i32 0, i32* %1
173   store i32 1, i32* %2
174   %3 = getelementptr [2 x i32]* %0, i32 0, i32 %in
175   %4 = load i32* %3
176   %5 = call i32 @llvm.r600.read.tidig.x()
177   %6 = add i32 %4, %5
178   store i32 %6, i32 addrspace(1)* %out
179   ret void
180 }
181
182 ; Test that two stack objects are not stored in the same register
183 ; The second stack object should be in T3.X
184 ; FUNC-LABEL: @no_overlap
185 ; R600_CHECK: MOV
186 ; R600_CHECK: [[CHAN:[XYZW]]]+
187 ; R600-NOT: [[CHAN]]+
188 ; SI: V_MOV_B32_e32 v3
189 define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
190 entry:
191   %0 = alloca [3 x i8], align 1
192   %1 = alloca [2 x i8], align 1
193   %2 = getelementptr [3 x i8]* %0, i32 0, i32 0
194   %3 = getelementptr [3 x i8]* %0, i32 0, i32 1
195   %4 = getelementptr [3 x i8]* %0, i32 0, i32 2
196   %5 = getelementptr [2 x i8]* %1, i32 0, i32 0
197   %6 = getelementptr [2 x i8]* %1, i32 0, i32 1
198   store i8 0, i8* %2
199   store i8 1, i8* %3
200   store i8 2, i8* %4
201   store i8 1, i8* %5
202   store i8 0, i8* %6
203   %7 = getelementptr [3 x i8]* %0, i32 0, i32 %in
204   %8 = getelementptr [2 x i8]* %1, i32 0, i32 %in
205   %9 = load i8* %7
206   %10 = load i8* %8
207   %11 = add i8 %9, %10
208   %12 = sext i8 %11 to i32
209   store i32 %12, i32 addrspace(1)* %out
210   ret void
211 }
212
213 define void @char_array_array(i32 addrspace(1)* %out, i32 %index) {
214 entry:
215   %alloca = alloca [2 x [2 x i8]]
216   %gep0 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0
217   %gep1 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1
218   store i8 0, i8* %gep0
219   store i8 1, i8* %gep1
220   %gep2 = getelementptr [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index
221   %load = load i8* %gep2
222   %sext = sext i8 %load to i32
223   store i32 %sext, i32 addrspace(1)* %out
224   ret void
225 }
226
227 define void @i32_array_array(i32 addrspace(1)* %out, i32 %index) {
228 entry:
229   %alloca = alloca [2 x [2 x i32]]
230   %gep0 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0
231   %gep1 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1
232   store i32 0, i32* %gep0
233   store i32 1, i32* %gep1
234   %gep2 = getelementptr [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index
235   %load = load i32* %gep2
236   store i32 %load, i32 addrspace(1)* %out
237   ret void
238 }
239
240 define void @i64_array_array(i64 addrspace(1)* %out, i32 %index) {
241 entry:
242   %alloca = alloca [2 x [2 x i64]]
243   %gep0 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0
244   %gep1 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1
245   store i64 0, i64* %gep0
246   store i64 1, i64* %gep1
247   %gep2 = getelementptr [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index
248   %load = load i64* %gep2
249   store i64 %load, i64 addrspace(1)* %out
250   ret void
251 }
252
253 %struct.pair32 = type { i32, i32 }
254
255 define void @struct_array_array(i32 addrspace(1)* %out, i32 %index) {
256 entry:
257   %alloca = alloca [2 x [2 x %struct.pair32]]
258   %gep0 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1
259   %gep1 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1
260   store i32 0, i32* %gep0
261   store i32 1, i32* %gep1
262   %gep2 = getelementptr [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0
263   %load = load i32* %gep2
264   store i32 %load, i32 addrspace(1)* %out
265   ret void
266 }
267
268 define void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) {
269 entry:
270   %alloca = alloca [2 x %struct.pair32]
271   %gep0 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1
272   %gep1 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0
273   store i32 0, i32* %gep0
274   store i32 1, i32* %gep1
275   %gep2 = getelementptr [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0
276   %load = load i32* %gep2
277   store i32 %load, i32 addrspace(1)* %out
278   ret void
279 }
280
281 define void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
282 entry:
283   %tmp = alloca [2 x i32]
284   %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
285   %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
286   store i32 0, i32* %tmp1
287   store i32 1, i32* %tmp2
288   %cmp = icmp eq i32 %in, 0
289   %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
290   %load = load i32* %sel
291   store i32 %load, i32 addrspace(1)* %out
292   ret void
293 }
294