R600/SI: Fix assertion on sign extend of 3 vectors
[oota-llvm.git] / test / CodeGen / R600 / setcc.ll
1 ; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=R600 -check-prefix=FUNC %s
2 ; RUN: llc -march=r600 -mcpu=SI -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
3
4 declare i32 @llvm.r600.read.tidig.x() nounwind readnone
5
6 ; FUNC-LABEL: {{^}}setcc_v2i32:
7 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW]}}, KC0[3].X, KC0[3].Z
8 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW]}}, KC0[2].W, KC0[3].Y
9
10 define void @setcc_v2i32(<2 x i32> addrspace(1)* %out, <2 x i32> %a, <2 x i32> %b) {
11   %result = icmp eq <2 x i32> %a, %b
12   %sext = sext <2 x i1> %result to <2 x i32>
13   store <2 x i32> %sext, <2 x i32> addrspace(1)* %out
14   ret void
15 }
16
17 ; FUNC-LABEL: {{^}}setcc_v4i32:
18 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
19 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
20 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
21 ; R600-DAG: SETE_INT * T{{[0-9]+\.[XYZW], T[0-9]+\.[XYZW], T[0-9]+\.[XYZW]}}
22
23 define void @setcc_v4i32(<4 x i32> addrspace(1)* %out, <4 x i32> addrspace(1)* %in) {
24   %b_ptr = getelementptr <4 x i32> addrspace(1)* %in, i32 1
25   %a = load <4 x i32> addrspace(1) * %in
26   %b = load <4 x i32> addrspace(1) * %b_ptr
27   %result = icmp eq <4 x i32> %a, %b
28   %sext = sext <4 x i1> %result to <4 x i32>
29   store <4 x i32> %sext, <4 x i32> addrspace(1)* %out
30   ret void
31 }
32
33 ;;;==========================================================================;;;
34 ;; Float comparisons
35 ;;;==========================================================================;;;
36
37 ; FUNC-LABEL: {{^}}f32_oeq:
38 ; R600: SETE_DX10
39 ; SI: v_cmp_eq_f32
40 define void @f32_oeq(i32 addrspace(1)* %out, float %a, float %b) {
41 entry:
42   %0 = fcmp oeq float %a, %b
43   %1 = sext i1 %0 to i32
44   store i32 %1, i32 addrspace(1)* %out
45   ret void
46 }
47
48 ; FUNC-LABEL: {{^}}f32_ogt:
49 ; R600: SETGT_DX10
50 ; SI: v_cmp_gt_f32
51 define void @f32_ogt(i32 addrspace(1)* %out, float %a, float %b) {
52 entry:
53   %0 = fcmp ogt float %a, %b
54   %1 = sext i1 %0 to i32
55   store i32 %1, i32 addrspace(1)* %out
56   ret void
57 }
58
59 ; FUNC-LABEL: {{^}}f32_oge:
60 ; R600: SETGE_DX10
61 ; SI: v_cmp_ge_f32
62 define void @f32_oge(i32 addrspace(1)* %out, float %a, float %b) {
63 entry:
64   %0 = fcmp oge float %a, %b
65   %1 = sext i1 %0 to i32
66   store i32 %1, i32 addrspace(1)* %out
67   ret void
68 }
69
70 ; FUNC-LABEL: {{^}}f32_olt:
71 ; R600: SETGT_DX10
72 ; SI: v_cmp_lt_f32
73 define void @f32_olt(i32 addrspace(1)* %out, float %a, float %b) {
74 entry:
75   %0 = fcmp olt float %a, %b
76   %1 = sext i1 %0 to i32
77   store i32 %1, i32 addrspace(1)* %out
78   ret void
79 }
80
81 ; FUNC-LABEL: {{^}}f32_ole:
82 ; R600: SETGE_DX10
83 ; SI: v_cmp_le_f32
84 define void @f32_ole(i32 addrspace(1)* %out, float %a, float %b) {
85 entry:
86   %0 = fcmp ole float %a, %b
87   %1 = sext i1 %0 to i32
88   store i32 %1, i32 addrspace(1)* %out
89   ret void
90 }
91
92 ; FUNC-LABEL: {{^}}f32_one:
93 ; R600-DAG: SETE_DX10
94 ; R600-DAG: SETE_DX10
95 ; R600-DAG: AND_INT
96 ; R600-DAG: SETNE_DX10
97 ; R600-DAG: AND_INT
98 ; R600-DAG: SETNE_INT
99 ; SI: v_cmp_o_f32
100 ; SI: v_cmp_neq_f32
101 ; SI: v_cndmask_b32_e64
102 ; SI: v_cndmask_b32_e64
103 ; SI: v_and_b32_e32
104 define void @f32_one(i32 addrspace(1)* %out, float %a, float %b) {
105 entry:
106   %0 = fcmp one float %a, %b
107   %1 = sext i1 %0 to i32
108   store i32 %1, i32 addrspace(1)* %out
109   ret void
110 }
111
112 ; FUNC-LABEL: {{^}}f32_ord:
113 ; R600-DAG: SETE_DX10
114 ; R600-DAG: SETE_DX10
115 ; R600-DAG: AND_INT
116 ; R600-DAG: SETNE_INT
117 ; SI: v_cmp_o_f32
118 define void @f32_ord(i32 addrspace(1)* %out, float %a, float %b) {
119 entry:
120   %0 = fcmp ord float %a, %b
121   %1 = sext i1 %0 to i32
122   store i32 %1, i32 addrspace(1)* %out
123   ret void
124 }
125
126 ; FUNC-LABEL: {{^}}f32_ueq:
127 ; R600-DAG: SETNE_DX10
128 ; R600-DAG: SETNE_DX10
129 ; R600-DAG: OR_INT
130 ; R600-DAG: SETE_DX10
131 ; R600-DAG: OR_INT
132 ; R600-DAG: SETNE_INT
133 ; SI: v_cmp_u_f32
134 ; SI: v_cmp_eq_f32
135 ; SI: v_cndmask_b32_e64
136 ; SI: v_cndmask_b32_e64
137 ; SI: v_or_b32_e32
138 define void @f32_ueq(i32 addrspace(1)* %out, float %a, float %b) {
139 entry:
140   %0 = fcmp ueq float %a, %b
141   %1 = sext i1 %0 to i32
142   store i32 %1, i32 addrspace(1)* %out
143   ret void
144 }
145
146 ; FUNC-LABEL: {{^}}f32_ugt:
147 ; R600: SETGE
148 ; R600: SETE_DX10
149 ; SI: v_cmp_u_f32
150 ; SI: v_cmp_gt_f32
151 ; SI: v_cndmask_b32_e64
152 ; SI: v_cndmask_b32_e64
153 ; SI: v_or_b32_e32
154 define void @f32_ugt(i32 addrspace(1)* %out, float %a, float %b) {
155 entry:
156   %0 = fcmp ugt float %a, %b
157   %1 = sext i1 %0 to i32
158   store i32 %1, i32 addrspace(1)* %out
159   ret void
160 }
161
162 ; FUNC-LABEL: {{^}}f32_uge:
163 ; R600: SETGT
164 ; R600: SETE_DX10
165 ; SI: v_cmp_u_f32
166 ; SI: v_cmp_ge_f32
167 ; SI: v_cndmask_b32_e64
168 ; SI: v_cndmask_b32_e64
169 ; SI: v_or_b32_e32
170 define void @f32_uge(i32 addrspace(1)* %out, float %a, float %b) {
171 entry:
172   %0 = fcmp uge float %a, %b
173   %1 = sext i1 %0 to i32
174   store i32 %1, i32 addrspace(1)* %out
175   ret void
176 }
177
178 ; FUNC-LABEL: {{^}}f32_ult:
179 ; R600: SETGE
180 ; R600: SETE_DX10
181 ; SI: v_cmp_u_f32
182 ; SI: v_cmp_lt_f32
183 ; SI: v_cndmask_b32_e64
184 ; SI: v_cndmask_b32_e64
185 ; SI: v_or_b32_e32
186 define void @f32_ult(i32 addrspace(1)* %out, float %a, float %b) {
187 entry:
188   %0 = fcmp ult float %a, %b
189   %1 = sext i1 %0 to i32
190   store i32 %1, i32 addrspace(1)* %out
191   ret void
192 }
193
194 ; FUNC-LABEL: {{^}}f32_ule:
195 ; R600: SETGT
196 ; R600: SETE_DX10
197 ; SI: v_cmp_u_f32
198 ; SI: v_cmp_le_f32
199 ; SI: v_cndmask_b32_e64
200 ; SI: v_cndmask_b32_e64
201 ; SI: v_or_b32_e32
202 define void @f32_ule(i32 addrspace(1)* %out, float %a, float %b) {
203 entry:
204   %0 = fcmp ule float %a, %b
205   %1 = sext i1 %0 to i32
206   store i32 %1, i32 addrspace(1)* %out
207   ret void
208 }
209
210 ; FUNC-LABEL: {{^}}f32_une:
211 ; R600: SETNE_DX10
212 ; SI: v_cmp_neq_f32
213 define void @f32_une(i32 addrspace(1)* %out, float %a, float %b) {
214 entry:
215   %0 = fcmp une float %a, %b
216   %1 = sext i1 %0 to i32
217   store i32 %1, i32 addrspace(1)* %out
218   ret void
219 }
220
221 ; FUNC-LABEL: {{^}}f32_uno:
222 ; R600: SETNE_DX10
223 ; R600: SETNE_DX10
224 ; R600: OR_INT
225 ; R600: SETNE_INT
226 ; SI: v_cmp_u_f32
227 define void @f32_uno(i32 addrspace(1)* %out, float %a, float %b) {
228 entry:
229   %0 = fcmp uno float %a, %b
230   %1 = sext i1 %0 to i32
231   store i32 %1, i32 addrspace(1)* %out
232   ret void
233 }
234
235 ;;;==========================================================================;;;
236 ;; 32-bit integer comparisons
237 ;;;==========================================================================;;;
238
239 ; FUNC-LABEL: {{^}}i32_eq:
240 ; R600: SETE_INT
241 ; SI: v_cmp_eq_i32
242 define void @i32_eq(i32 addrspace(1)* %out, i32 %a, i32 %b) {
243 entry:
244   %0 = icmp eq i32 %a, %b
245   %1 = sext i1 %0 to i32
246   store i32 %1, i32 addrspace(1)* %out
247   ret void
248 }
249
250 ; FUNC-LABEL: {{^}}i32_ne:
251 ; R600: SETNE_INT
252 ; SI: v_cmp_ne_i32
253 define void @i32_ne(i32 addrspace(1)* %out, i32 %a, i32 %b) {
254 entry:
255   %0 = icmp ne i32 %a, %b
256   %1 = sext i1 %0 to i32
257   store i32 %1, i32 addrspace(1)* %out
258   ret void
259 }
260
261 ; FUNC-LABEL: {{^}}i32_ugt:
262 ; R600: SETGT_UINT
263 ; SI: v_cmp_gt_u32
264 define void @i32_ugt(i32 addrspace(1)* %out, i32 %a, i32 %b) {
265 entry:
266   %0 = icmp ugt i32 %a, %b
267   %1 = sext i1 %0 to i32
268   store i32 %1, i32 addrspace(1)* %out
269   ret void
270 }
271
272 ; FUNC-LABEL: {{^}}i32_uge:
273 ; R600: SETGE_UINT
274 ; SI: v_cmp_ge_u32
275 define void @i32_uge(i32 addrspace(1)* %out, i32 %a, i32 %b) {
276 entry:
277   %0 = icmp uge i32 %a, %b
278   %1 = sext i1 %0 to i32
279   store i32 %1, i32 addrspace(1)* %out
280   ret void
281 }
282
283 ; FUNC-LABEL: {{^}}i32_ult:
284 ; R600: SETGT_UINT
285 ; SI: v_cmp_lt_u32
286 define void @i32_ult(i32 addrspace(1)* %out, i32 %a, i32 %b) {
287 entry:
288   %0 = icmp ult i32 %a, %b
289   %1 = sext i1 %0 to i32
290   store i32 %1, i32 addrspace(1)* %out
291   ret void
292 }
293
294 ; FUNC-LABEL: {{^}}i32_ule:
295 ; R600: SETGE_UINT
296 ; SI: v_cmp_le_u32
297 define void @i32_ule(i32 addrspace(1)* %out, i32 %a, i32 %b) {
298 entry:
299   %0 = icmp ule i32 %a, %b
300   %1 = sext i1 %0 to i32
301   store i32 %1, i32 addrspace(1)* %out
302   ret void
303 }
304
305 ; FUNC-LABEL: {{^}}i32_sgt:
306 ; R600: SETGT_INT
307 ; SI: v_cmp_gt_i32
308 define void @i32_sgt(i32 addrspace(1)* %out, i32 %a, i32 %b) {
309 entry:
310   %0 = icmp sgt i32 %a, %b
311   %1 = sext i1 %0 to i32
312   store i32 %1, i32 addrspace(1)* %out
313   ret void
314 }
315
316 ; FUNC-LABEL: {{^}}i32_sge:
317 ; R600: SETGE_INT
318 ; SI: v_cmp_ge_i32
319 define void @i32_sge(i32 addrspace(1)* %out, i32 %a, i32 %b) {
320 entry:
321   %0 = icmp sge i32 %a, %b
322   %1 = sext i1 %0 to i32
323   store i32 %1, i32 addrspace(1)* %out
324   ret void
325 }
326
327 ; FUNC-LABEL: {{^}}i32_slt:
328 ; R600: SETGT_INT
329 ; SI: v_cmp_lt_i32
330 define void @i32_slt(i32 addrspace(1)* %out, i32 %a, i32 %b) {
331 entry:
332   %0 = icmp slt i32 %a, %b
333   %1 = sext i1 %0 to i32
334   store i32 %1, i32 addrspace(1)* %out
335   ret void
336 }
337
338 ; FUNC-LABEL: {{^}}i32_sle:
339 ; R600: SETGE_INT
340 ; SI: v_cmp_le_i32
341 define void @i32_sle(i32 addrspace(1)* %out, i32 %a, i32 %b) {
342 entry:
343   %0 = icmp sle i32 %a, %b
344   %1 = sext i1 %0 to i32
345   store i32 %1, i32 addrspace(1)* %out
346   ret void
347 }
348
349 ; FIXME: This does 4 compares
350 ; FUNC-LABEL: {{^}}v3i32_eq:
351 ; SI-DAG: v_cmp_eq_i32
352 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
353 ; SI-DAG: v_cmp_eq_i32
354 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
355 ; SI-DAG: v_cmp_eq_i32
356 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
357 ; SI: s_endpgm
358 define void @v3i32_eq(<3 x i32> addrspace(1)* %out, <3 x i32> addrspace(1)* %ptra, <3 x i32> addrspace(1)* %ptrb) {
359   %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
360   %gep.a = getelementptr <3 x i32> addrspace(1)* %ptra, i32 %tid
361   %gep.b = getelementptr <3 x i32> addrspace(1)* %ptrb, i32 %tid
362   %gep.out = getelementptr <3 x i32> addrspace(1)* %out, i32 %tid
363   %a = load <3 x i32> addrspace(1)* %gep.a
364   %b = load <3 x i32> addrspace(1)* %gep.b
365   %cmp = icmp eq <3 x i32> %a, %b
366   %ext = sext <3 x i1> %cmp to <3 x i32>
367   store <3 x i32> %ext, <3 x i32> addrspace(1)* %gep.out
368   ret void
369 }
370
371 ; FUNC-LABEL: {{^}}v3i8_eq:
372 ; SI-DAG: v_cmp_eq_i32
373 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
374 ; SI-DAG: v_cmp_eq_i32
375 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
376 ; SI-DAG: v_cmp_eq_i32
377 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
378 ; SI: s_endpgm
379 define void @v3i8_eq(<3 x i8> addrspace(1)* %out, <3 x i8> addrspace(1)* %ptra, <3 x i8> addrspace(1)* %ptrb) {
380   %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
381   %gep.a = getelementptr <3 x i8> addrspace(1)* %ptra, i32 %tid
382   %gep.b = getelementptr <3 x i8> addrspace(1)* %ptrb, i32 %tid
383   %gep.out = getelementptr <3 x i8> addrspace(1)* %out, i32 %tid
384   %a = load <3 x i8> addrspace(1)* %gep.a
385   %b = load <3 x i8> addrspace(1)* %gep.b
386   %cmp = icmp eq <3 x i8> %a, %b
387   %ext = sext <3 x i1> %cmp to <3 x i8>
388   store <3 x i8> %ext, <3 x i8> addrspace(1)* %gep.out
389   ret void
390 }