1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=cmov -verify-machineinstrs | FileCheck %s
4 define i32 @func_f(i32 %X) {
6 ; CHECK: # %bb.0: # %entry
7 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
8 ; CHECK-NEXT: incl %eax
9 ; CHECK-NEXT: jns .LBB0_2
10 ; CHECK-NEXT: # %bb.1: # %cond_true
11 ; CHECK-NEXT: calll bar
12 ; CHECK-NEXT: .LBB0_2: # %cond_next
13 ; CHECK-NEXT: jmp baz # TAILCALL
16 %tmp = icmp slt i32 %tmp1, 0
17 br i1 %tmp, label %cond_true, label %cond_next, !prof !1
19 cond_true: ; preds = %entry
20 %tmp2 = tail call i32 (...) @bar( )
23 cond_next: ; preds = %cond_true, %entry
24 %tmp3 = tail call i32 (...) @baz( )
33 define i32 @func_g(i32 %a, i32 %b) nounwind {
34 ; CHECK-LABEL: func_g:
36 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
37 ; CHECK-NEXT: xorl %ecx, %ecx
38 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
39 ; CHECK-NEXT: cmovsl %ecx, %eax
41 %sub = sub nsw i32 %a, %b
42 %cmp = icmp sgt i32 %sub, 0
43 %cond = select i1 %cmp, i32 %sub, i32 0
48 define i32 @func_h(i32 %a, i32 %b) nounwind {
49 ; CHECK-LABEL: func_h:
51 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
52 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
53 ; CHECK-NEXT: xorl %edx, %edx
54 ; CHECK-NEXT: subl %ecx, %eax
55 ; CHECK-NEXT: cmovlel %edx, %eax
57 %cmp = icmp slt i32 %b, %a
58 %sub = sub nsw i32 %a, %b
59 %cond = select i1 %cmp, i32 %sub, i32 0
63 define i32 @func_i(i32 %a, i32 %b) nounwind {
64 ; CHECK-LABEL: func_i:
66 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
67 ; CHECK-NEXT: xorl %ecx, %ecx
68 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
69 ; CHECK-NEXT: cmovlel %ecx, %eax
71 %cmp = icmp sgt i32 %a, %b
72 %sub = sub nsw i32 %a, %b
73 %cond = select i1 %cmp, i32 %sub, i32 0
77 define i32 @func_j(i32 %a, i32 %b) nounwind {
78 ; CHECK-LABEL: func_j:
80 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
81 ; CHECK-NEXT: xorl %ecx, %ecx
82 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
83 ; CHECK-NEXT: cmovbel %ecx, %eax
85 %cmp = icmp ugt i32 %a, %b
87 %cond = select i1 %cmp, i32 %sub, i32 0
91 define i32 @func_k(i32 %a, i32 %b) nounwind {
92 ; CHECK-LABEL: func_k:
94 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
95 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
96 ; CHECK-NEXT: xorl %edx, %edx
97 ; CHECK-NEXT: subl %ecx, %eax
98 ; CHECK-NEXT: cmovbel %edx, %eax
100 %cmp = icmp ult i32 %b, %a
101 %sub = sub i32 %a, %b
102 %cond = select i1 %cmp, i32 %sub, i32 0
106 ; redundant cmp instruction
107 define i32 @func_l(i32 %a, i32 %b) nounwind {
108 ; CHECK-LABEL: func_l:
110 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
111 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
112 ; CHECK-NEXT: movl %edx, %eax
113 ; CHECK-NEXT: subl %ecx, %eax
114 ; CHECK-NEXT: cmovlel %edx, %eax
116 %cmp = icmp slt i32 %b, %a
117 %sub = sub nsw i32 %a, %b
118 %cond = select i1 %cmp, i32 %sub, i32 %a
122 define i32 @func_m(i32 %a, i32 %b) nounwind {
123 ; CHECK-LABEL: func_m:
125 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
126 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
127 ; CHECK-NEXT: subl %ecx, %eax
128 ; CHECK-NEXT: cmovgl %ecx, %eax
130 %cmp = icmp sgt i32 %a, %b
131 %sub = sub nsw i32 %a, %b
132 %cond = select i1 %cmp, i32 %b, i32 %sub
136 ; If EFLAGS is live-out, we can't remove cmp if there exists
138 define i32 @func_l2(i32 %a, i32 %b) nounwind {
139 ; CHECK-LABEL: func_l2:
141 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
142 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
143 ; CHECK-NEXT: movl %eax, %ecx
144 ; CHECK-NEXT: subl %edx, %ecx
145 ; CHECK-NEXT: cmpl %eax, %edx
146 ; CHECK-NEXT: jne .LBB8_2
147 ; CHECK-NEXT: # %bb.1: # %if.then
148 ; CHECK-NEXT: cmovgl %ecx, %eax
150 ; CHECK-NEXT: .LBB8_2: # %if.else
151 ; CHECK-NEXT: movl %ecx, %eax
153 %cmp = icmp eq i32 %b, %a
154 %sub = sub nsw i32 %a, %b
155 br i1 %cmp, label %if.then, label %if.else
158 %cmp2 = icmp sgt i32 %b, %a
159 %sel = select i1 %cmp2, i32 %sub, i32 %a
166 define i32 @func_l3(i32 %a, i32 %b) nounwind {
167 ; CHECK-LABEL: func_l3:
169 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
170 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
171 ; CHECK-NEXT: subl %ecx, %eax
172 ; CHECK-NEXT: jge .LBB9_2
173 ; CHECK-NEXT: # %bb.1: # %if.then
175 ; CHECK-NEXT: .LBB9_2: # %if.else
176 ; CHECK-NEXT: incl %eax
178 %cmp = icmp sgt i32 %b, %a
179 %sub = sub nsw i32 %a, %b
180 br i1 %cmp, label %if.then, label %if.else
186 %add = add nsw i32 %sub, 1
191 ; When Movr0 is between sub and cmp, we need to move "Movr0" before sub.
192 define i32 @func_l4(i32 %a, i32 %b) nounwind {
193 ; CHECK-LABEL: func_l4:
195 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
196 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
197 ; CHECK-NEXT: xorl %edx, %edx
198 ; CHECK-NEXT: subl %ecx, %eax
199 ; CHECK-NEXT: cmovll %edx, %eax
201 %cmp = icmp sgt i32 %b, %a
202 %sub = sub i32 %a, %b
203 %.sub = select i1 %cmp, i32 0, i32 %sub
208 define i32 @func_n(i32 %x, i32 %y) nounwind {
209 ; CHECK-LABEL: func_n:
211 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
212 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
213 ; CHECK-NEXT: cmpl %ecx, %eax
214 ; CHECK-NEXT: cmovsl %ecx, %eax
216 %sub = sub nsw i32 %x, %y
217 %cmp = icmp slt i32 %sub, 0
218 %y.x = select i1 %cmp, i32 %y, i32 %x
223 define void @func_o() nounwind uwtable {
224 ; CHECK-LABEL: func_o:
225 ; CHECK: # %bb.0: # %entry
226 ; CHECK-NEXT: xorl %eax, %eax
227 ; CHECK-NEXT: testb %al, %al
228 ; CHECK-NEXT: je .LBB12_1
229 ; CHECK-NEXT: # %bb.2: # %if.end.i
230 ; CHECK-NEXT: xorl %eax, %eax
231 ; CHECK-NEXT: testb %al, %al
232 ; CHECK-NEXT: jne .LBB12_5
233 ; CHECK-NEXT: # %bb.3: # %sw.bb
234 ; CHECK-NEXT: xorl %eax, %eax
235 ; CHECK-NEXT: testb %al, %al
236 ; CHECK-NEXT: jne .LBB12_8
237 ; CHECK-NEXT: # %bb.4: # %if.end29
238 ; CHECK-NEXT: movzwl (%eax), %eax
239 ; CHECK-NEXT: movzwl %ax, %eax
240 ; CHECK-NEXT: imull $52429, %eax, %ecx # imm = 0xCCCD
241 ; CHECK-NEXT: shrl $19, %ecx
242 ; CHECK-NEXT: addl %ecx, %ecx
243 ; CHECK-NEXT: leal (%ecx,%ecx,4), %ecx
244 ; CHECK-NEXT: cmpw %cx, %ax
245 ; CHECK-NEXT: jne .LBB12_5
246 ; CHECK-NEXT: .LBB12_8: # %if.then44
247 ; CHECK-NEXT: xorl %eax, %eax
248 ; CHECK-NEXT: testb %al, %al
249 ; CHECK-NEXT: je .LBB12_9
250 ; CHECK-NEXT: # %bb.10: # %if.else.i104
252 ; CHECK-NEXT: .LBB12_5: # %sw.default
253 ; CHECK-NEXT: xorl %eax, %eax
254 ; CHECK-NEXT: testb %al, %al
255 ; CHECK-NEXT: jne .LBB12_7
256 ; CHECK-NEXT: # %bb.6: # %if.then.i96
257 ; CHECK-NEXT: .LBB12_1: # %if.then.i
258 ; CHECK-NEXT: .LBB12_9: # %if.then.i103
259 ; CHECK-NEXT: .LBB12_7: # %if.else.i97
261 %0 = load i16, i16* undef, align 2
262 br i1 undef, label %if.then.i, label %if.end.i
264 if.then.i: ; preds = %entry
267 if.end.i: ; preds = %entry
268 br i1 undef, label %sw.bb, label %sw.default
270 sw.bb: ; preds = %if.end.i
271 br i1 undef, label %if.then44, label %if.end29
273 if.end29: ; preds = %sw.bb
275 %cmp25 = icmp eq i16 %1, 0
276 %. = select i1 %cmp25, i16 2, i16 0
277 br i1 %cmp25, label %if.then44, label %sw.default
279 sw.default: ; preds = %if.end29, %if.end.i
280 br i1 undef, label %if.then.i96, label %if.else.i97
282 if.then.i96: ; preds = %sw.default
285 if.else.i97: ; preds = %sw.default
288 if.then44: ; preds = %if.end29, %sw.bb
289 %aModeRefSel.1.ph = phi i16 [ %., %if.end29 ], [ 3, %sw.bb ]
290 br i1 undef, label %if.then.i103, label %if.else.i104
292 if.then.i103: ; preds = %if.then44
295 if.else.i104: ; preds = %if.then44
300 define i32 @func_p(i32 %a, i32 %b) nounwind {
301 ; CHECK-LABEL: func_p:
303 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
304 ; CHECK-NEXT: xorl %ecx, %ecx
305 ; CHECK-NEXT: addl {{[0-9]+}}(%esp), %eax
306 ; CHECK-NEXT: cmovsl %ecx, %eax
308 %add = add nsw i32 %b, %a
309 %cmp = icmp sgt i32 %add, 0
310 %add. = select i1 %cmp, i32 %add, i32 0
315 ; If we have sub a, b and cmp b, a and the result of cmp is used
316 ; by sbb, we should not optimize cmp away.
317 define i32 @func_q(i32 %a0, i32 %a1, i32 %a2) {
318 ; CHECK-LABEL: func_q:
320 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
321 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
322 ; CHECK-NEXT: movl %ecx, %edx
323 ; CHECK-NEXT: subl %eax, %edx
324 ; CHECK-NEXT: cmpl %ecx, %eax
325 ; CHECK-NEXT: sbbl %eax, %eax
326 ; CHECK-NEXT: xorl %edx, %eax
328 %t1 = icmp ult i32 %a0, %a1
329 %t2 = sub i32 %a1, %a0
330 %t3 = select i1 %t1, i32 -1, i32 0
331 %t4 = xor i32 %t2, %t3
336 define i8* @func_r(i8* %base, i32* nocapture %offset, i32 %size) nounwind {
337 ; CHECK-LABEL: func_r:
338 ; CHECK: # %bb.0: # %entry
339 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
340 ; CHECK-NEXT: movl (%edx), %ecx
341 ; CHECK-NEXT: xorl %eax, %eax
342 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %ecx
343 ; CHECK-NEXT: jl .LBB15_2
344 ; CHECK-NEXT: # %bb.1: # %if.end
345 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
346 ; CHECK-NEXT: movl %ecx, (%edx)
347 ; CHECK-NEXT: addl %ecx, %eax
348 ; CHECK-NEXT: .LBB15_2: # %return
351 %0 = load i32, i32* %offset, align 8
352 %cmp = icmp slt i32 %0, %size
353 br i1 %cmp, label %return, label %if.end
356 %sub = sub nsw i32 %0, %size
357 store i32 %sub, i32* %offset, align 8
358 %add.ptr = getelementptr inbounds i8, i8* %base, i32 %sub
362 %retval.0 = phi i8* [ %add.ptr, %if.end ], [ null, %entry ]
366 ; Test optimizations of dec/inc.
367 define i32 @func_dec(i32 %a) nounwind {
368 ; CHECK-LABEL: func_dec:
370 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
371 ; CHECK-NEXT: xorl %ecx, %ecx
372 ; CHECK-NEXT: decl %eax
373 ; CHECK-NEXT: cmovsl %ecx, %eax
375 %sub = sub nsw i32 %a, 1
376 %cmp = icmp sgt i32 %sub, 0
377 %cond = select i1 %cmp, i32 %sub, i32 0
381 define i32 @func_inc(i32 %a) nounwind {
382 ; CHECK-LABEL: func_inc:
384 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
385 ; CHECK-NEXT: xorl %ecx, %ecx
386 ; CHECK-NEXT: incl %eax
387 ; CHECK-NEXT: cmovsl %ecx, %eax
389 %add = add nsw i32 %a, 1
390 %cmp = icmp sgt i32 %add, 0
391 %cond = select i1 %cmp, i32 %add, i32 0
396 @b = common global i32 0, align 4
397 @a = common global i32 0, align 4
398 define i32 @func_test1(i32 %p1) nounwind uwtable {
399 ; CHECK-LABEL: func_test1:
400 ; CHECK: # %bb.0: # %entry
401 ; CHECK-NEXT: movl b, %eax
402 ; CHECK-NEXT: cmpl {{[0-9]+}}(%esp), %eax
403 ; CHECK-NEXT: setb %cl
404 ; CHECK-NEXT: movl a, %eax
405 ; CHECK-NEXT: testb %al, %cl
406 ; CHECK-NEXT: je .LBB18_2
407 ; CHECK-NEXT: # %bb.1: # %if.then
408 ; CHECK-NEXT: decl %eax
409 ; CHECK-NEXT: movl %eax, a
410 ; CHECK-NEXT: .LBB18_2: # %if.end
413 %t0 = load i32, i32* @b, align 4
414 %cmp = icmp ult i32 %t0, %p1
415 %conv = zext i1 %cmp to i32
416 %t1 = load i32, i32* @a, align 4
417 %and = and i32 %conv, %t1
418 %conv1 = trunc i32 %and to i8
419 %t2 = urem i8 %conv1, 3
420 %tobool = icmp eq i8 %t2, 0
421 br i1 %tobool, label %if.end, label %if.then
424 %dec = add nsw i32 %t1, -1
425 store i32 %dec, i32* @a, align 4
432 !1 = !{!"branch_weights", i32 2, i32 1}