R600/SI: Remove i1 pseudo VALU ops
[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
100 ; SI-DAG: v_cmp_o_f32_e32 vcc
101 ; SI-DAG: v_cmp_neq_f32_e64 [[CMP1:s\[[0-9]+:[0-9]+\]]]
102 ; SI: s_and_b64 [[AND:s\[[0-9]+:[0-9]+\]]], [[CMP1]], vcc
103 ; SI: v_cndmask_b32_e64 [[VRESULT:v[0-9]+]], 0, -1, [[AND]]
104 ; SI: buffer_store_dword [[VRESULT]]
105 define void @f32_one(i32 addrspace(1)* %out, float %a, float %b) {
106 entry:
107   %0 = fcmp one float %a, %b
108   %1 = sext i1 %0 to i32
109   store i32 %1, i32 addrspace(1)* %out
110   ret void
111 }
112
113 ; FUNC-LABEL: {{^}}f32_ord:
114 ; R600-DAG: SETE_DX10
115 ; R600-DAG: SETE_DX10
116 ; R600-DAG: AND_INT
117 ; R600-DAG: SETNE_INT
118 ; SI: v_cmp_o_f32
119 define void @f32_ord(i32 addrspace(1)* %out, float %a, float %b) {
120 entry:
121   %0 = fcmp ord float %a, %b
122   %1 = sext i1 %0 to i32
123   store i32 %1, i32 addrspace(1)* %out
124   ret void
125 }
126
127 ; FUNC-LABEL: {{^}}f32_ueq:
128 ; R600-DAG: SETNE_DX10
129 ; R600-DAG: SETNE_DX10
130 ; R600-DAG: OR_INT
131 ; R600-DAG: SETE_DX10
132 ; R600-DAG: OR_INT
133 ; R600-DAG: SETNE_INT
134
135 ; SI-DAG: v_cmp_u_f32_e32 vcc
136 ; SI-DAG: v_cmp_eq_f32_e64 [[CMP1:s\[[0-9]+:[0-9]+\]]]
137 ; SI: s_or_b64 [[OR:s\[[0-9]+:[0-9]+\]]], [[CMP1]], vcc
138 ; SI: v_cndmask_b32_e64 [[VRESULT:v[0-9]+]], 0, -1, [[OR]]
139 ; SI: buffer_store_dword [[VRESULT]]
140 define void @f32_ueq(i32 addrspace(1)* %out, float %a, float %b) {
141 entry:
142   %0 = fcmp ueq float %a, %b
143   %1 = sext i1 %0 to i32
144   store i32 %1, i32 addrspace(1)* %out
145   ret void
146 }
147
148 ; FUNC-LABEL: {{^}}f32_ugt:
149 ; R600: SETGE
150 ; R600: SETE_DX10
151 ; SI: v_cmp_u_f32
152 ; SI: v_cmp_gt_f32
153 ; SI: s_or_b64
154 ; SI: v_cndmask_b32
155 define void @f32_ugt(i32 addrspace(1)* %out, float %a, float %b) {
156 entry:
157   %0 = fcmp ugt float %a, %b
158   %1 = sext i1 %0 to i32
159   store i32 %1, i32 addrspace(1)* %out
160   ret void
161 }
162
163 ; FUNC-LABEL: {{^}}f32_uge:
164 ; R600: SETGT
165 ; R600: SETE_DX10
166 ; SI: v_cmp_u_f32
167 ; SI: v_cmp_ge_f32
168 ; SI: s_or_b64
169 ; SI: v_cndmask_b32
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: s_or_b64
184 ; SI: v_cndmask_b32
185 define void @f32_ult(i32 addrspace(1)* %out, float %a, float %b) {
186 entry:
187   %0 = fcmp ult float %a, %b
188   %1 = sext i1 %0 to i32
189   store i32 %1, i32 addrspace(1)* %out
190   ret void
191 }
192
193 ; FUNC-LABEL: {{^}}f32_ule:
194 ; R600: SETGT
195 ; R600: SETE_DX10
196 ; SI: v_cmp_u_f32
197 ; SI: v_cmp_le_f32
198 ; SI: s_or_b64
199 ; SI: v_cndmask_b32
200 define void @f32_ule(i32 addrspace(1)* %out, float %a, float %b) {
201 entry:
202   %0 = fcmp ule float %a, %b
203   %1 = sext i1 %0 to i32
204   store i32 %1, i32 addrspace(1)* %out
205   ret void
206 }
207
208 ; FUNC-LABEL: {{^}}f32_une:
209 ; R600: SETNE_DX10
210 ; SI: v_cmp_neq_f32
211 define void @f32_une(i32 addrspace(1)* %out, float %a, float %b) {
212 entry:
213   %0 = fcmp une float %a, %b
214   %1 = sext i1 %0 to i32
215   store i32 %1, i32 addrspace(1)* %out
216   ret void
217 }
218
219 ; FUNC-LABEL: {{^}}f32_uno:
220 ; R600: SETNE_DX10
221 ; R600: SETNE_DX10
222 ; R600: OR_INT
223 ; R600: SETNE_INT
224 ; SI: v_cmp_u_f32
225 define void @f32_uno(i32 addrspace(1)* %out, float %a, float %b) {
226 entry:
227   %0 = fcmp uno float %a, %b
228   %1 = sext i1 %0 to i32
229   store i32 %1, i32 addrspace(1)* %out
230   ret void
231 }
232
233 ;;;==========================================================================;;;
234 ;; 32-bit integer comparisons
235 ;;;==========================================================================;;;
236
237 ; FUNC-LABEL: {{^}}i32_eq:
238 ; R600: SETE_INT
239 ; SI: v_cmp_eq_i32
240 define void @i32_eq(i32 addrspace(1)* %out, i32 %a, i32 %b) {
241 entry:
242   %0 = icmp eq i32 %a, %b
243   %1 = sext i1 %0 to i32
244   store i32 %1, i32 addrspace(1)* %out
245   ret void
246 }
247
248 ; FUNC-LABEL: {{^}}i32_ne:
249 ; R600: SETNE_INT
250 ; SI: v_cmp_ne_i32
251 define void @i32_ne(i32 addrspace(1)* %out, i32 %a, i32 %b) {
252 entry:
253   %0 = icmp ne i32 %a, %b
254   %1 = sext i1 %0 to i32
255   store i32 %1, i32 addrspace(1)* %out
256   ret void
257 }
258
259 ; FUNC-LABEL: {{^}}i32_ugt:
260 ; R600: SETGT_UINT
261 ; SI: v_cmp_gt_u32
262 define void @i32_ugt(i32 addrspace(1)* %out, i32 %a, i32 %b) {
263 entry:
264   %0 = icmp ugt i32 %a, %b
265   %1 = sext i1 %0 to i32
266   store i32 %1, i32 addrspace(1)* %out
267   ret void
268 }
269
270 ; FUNC-LABEL: {{^}}i32_uge:
271 ; R600: SETGE_UINT
272 ; SI: v_cmp_ge_u32
273 define void @i32_uge(i32 addrspace(1)* %out, i32 %a, i32 %b) {
274 entry:
275   %0 = icmp uge i32 %a, %b
276   %1 = sext i1 %0 to i32
277   store i32 %1, i32 addrspace(1)* %out
278   ret void
279 }
280
281 ; FUNC-LABEL: {{^}}i32_ult:
282 ; R600: SETGT_UINT
283 ; SI: v_cmp_lt_u32
284 define void @i32_ult(i32 addrspace(1)* %out, i32 %a, i32 %b) {
285 entry:
286   %0 = icmp ult i32 %a, %b
287   %1 = sext i1 %0 to i32
288   store i32 %1, i32 addrspace(1)* %out
289   ret void
290 }
291
292 ; FUNC-LABEL: {{^}}i32_ule:
293 ; R600: SETGE_UINT
294 ; SI: v_cmp_le_u32
295 define void @i32_ule(i32 addrspace(1)* %out, i32 %a, i32 %b) {
296 entry:
297   %0 = icmp ule i32 %a, %b
298   %1 = sext i1 %0 to i32
299   store i32 %1, i32 addrspace(1)* %out
300   ret void
301 }
302
303 ; FUNC-LABEL: {{^}}i32_sgt:
304 ; R600: SETGT_INT
305 ; SI: v_cmp_gt_i32
306 define void @i32_sgt(i32 addrspace(1)* %out, i32 %a, i32 %b) {
307 entry:
308   %0 = icmp sgt i32 %a, %b
309   %1 = sext i1 %0 to i32
310   store i32 %1, i32 addrspace(1)* %out
311   ret void
312 }
313
314 ; FUNC-LABEL: {{^}}i32_sge:
315 ; R600: SETGE_INT
316 ; SI: v_cmp_ge_i32
317 define void @i32_sge(i32 addrspace(1)* %out, i32 %a, i32 %b) {
318 entry:
319   %0 = icmp sge i32 %a, %b
320   %1 = sext i1 %0 to i32
321   store i32 %1, i32 addrspace(1)* %out
322   ret void
323 }
324
325 ; FUNC-LABEL: {{^}}i32_slt:
326 ; R600: SETGT_INT
327 ; SI: v_cmp_lt_i32
328 define void @i32_slt(i32 addrspace(1)* %out, i32 %a, i32 %b) {
329 entry:
330   %0 = icmp slt i32 %a, %b
331   %1 = sext i1 %0 to i32
332   store i32 %1, i32 addrspace(1)* %out
333   ret void
334 }
335
336 ; FUNC-LABEL: {{^}}i32_sle:
337 ; R600: SETGE_INT
338 ; SI: v_cmp_le_i32
339 define void @i32_sle(i32 addrspace(1)* %out, i32 %a, i32 %b) {
340 entry:
341   %0 = icmp sle i32 %a, %b
342   %1 = sext i1 %0 to i32
343   store i32 %1, i32 addrspace(1)* %out
344   ret void
345 }
346
347 ; FIXME: This does 4 compares
348 ; FUNC-LABEL: {{^}}v3i32_eq:
349 ; SI-DAG: v_cmp_eq_i32
350 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
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: s_endpgm
356 define void @v3i32_eq(<3 x i32> addrspace(1)* %out, <3 x i32> addrspace(1)* %ptra, <3 x i32> addrspace(1)* %ptrb) {
357   %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
358   %gep.a = getelementptr <3 x i32> addrspace(1)* %ptra, i32 %tid
359   %gep.b = getelementptr <3 x i32> addrspace(1)* %ptrb, i32 %tid
360   %gep.out = getelementptr <3 x i32> addrspace(1)* %out, i32 %tid
361   %a = load <3 x i32> addrspace(1)* %gep.a
362   %b = load <3 x i32> addrspace(1)* %gep.b
363   %cmp = icmp eq <3 x i32> %a, %b
364   %ext = sext <3 x i1> %cmp to <3 x i32>
365   store <3 x i32> %ext, <3 x i32> addrspace(1)* %gep.out
366   ret void
367 }
368
369 ; FUNC-LABEL: {{^}}v3i8_eq:
370 ; SI-DAG: v_cmp_eq_i32
371 ; SI-DAG: v_cndmask_b32_e64 {{v[0-9]+}}, 0, -1,
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: s_endpgm
377 define void @v3i8_eq(<3 x i8> addrspace(1)* %out, <3 x i8> addrspace(1)* %ptra, <3 x i8> addrspace(1)* %ptrb) {
378   %tid = call i32 @llvm.r600.read.tidig.x() nounwind readnone
379   %gep.a = getelementptr <3 x i8> addrspace(1)* %ptra, i32 %tid
380   %gep.b = getelementptr <3 x i8> addrspace(1)* %ptrb, i32 %tid
381   %gep.out = getelementptr <3 x i8> addrspace(1)* %out, i32 %tid
382   %a = load <3 x i8> addrspace(1)* %gep.a
383   %b = load <3 x i8> addrspace(1)* %gep.b
384   %cmp = icmp eq <3 x i8> %a, %b
385   %ext = sext <3 x i1> %cmp to <3 x i8>
386   store <3 x i8> %ext, <3 x i8> addrspace(1)* %gep.out
387   ret void
388 }