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@PLT
12 ; CHECK-NEXT: .LBB0_2: # %cond_next
13 ; CHECK-NEXT: jmp baz@PLT # 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), %eax
52 ; CHECK-NEXT: xorl %ecx, %ecx
53 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
54 ; CHECK-NEXT: cmovlel %ecx, %eax
56 %cmp = icmp slt i32 %b, %a
57 %sub = sub nsw i32 %a, %b
58 %cond = select i1 %cmp, i32 %sub, i32 0
62 define i32 @func_i(i32 %a, i32 %b) nounwind {
63 ; CHECK-LABEL: func_i:
65 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
66 ; CHECK-NEXT: xorl %ecx, %ecx
67 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
68 ; CHECK-NEXT: cmovlel %ecx, %eax
70 %cmp = icmp sgt i32 %a, %b
71 %sub = sub nsw i32 %a, %b
72 %cond = select i1 %cmp, i32 %sub, i32 0
76 define i32 @func_j(i32 %a, i32 %b) nounwind {
77 ; CHECK-LABEL: func_j:
79 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
80 ; CHECK-NEXT: xorl %ecx, %ecx
81 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
82 ; CHECK-NEXT: cmovbel %ecx, %eax
84 %cmp = icmp ugt i32 %a, %b
86 %cond = select i1 %cmp, i32 %sub, i32 0
90 define i32 @func_k(i32 %a, i32 %b) nounwind {
91 ; CHECK-LABEL: func_k:
93 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
94 ; CHECK-NEXT: xorl %ecx, %ecx
95 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
96 ; CHECK-NEXT: cmovbel %ecx, %eax
98 %cmp = icmp ult i32 %b, %a
100 %cond = select i1 %cmp, i32 %sub, i32 0
104 ; redundant cmp instruction
105 define i32 @func_l(i32 %a, i32 %b) nounwind {
106 ; CHECK-LABEL: func_l:
108 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
109 ; CHECK-NEXT: movl %ecx, %eax
110 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
111 ; CHECK-NEXT: cmovlel %ecx, %eax
113 %cmp = icmp slt i32 %b, %a
114 %sub = sub nsw i32 %a, %b
115 %cond = select i1 %cmp, i32 %sub, i32 %a
119 define i32 @func_m(i32 %a, i32 %b) nounwind {
120 ; CHECK-LABEL: func_m:
122 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
123 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
124 ; CHECK-NEXT: subl %ecx, %eax
125 ; CHECK-NEXT: cmovgl %ecx, %eax
127 %cmp = icmp sgt i32 %a, %b
128 %sub = sub nsw i32 %a, %b
129 %cond = select i1 %cmp, i32 %b, i32 %sub
133 ; (This used to test that an unsafe removal of cmp in bb.0 is not happening,
134 ; but now we can do so safely).
135 define i32 @func_l2(i32 %a, i32 %b) nounwind {
136 ; CHECK-LABEL: func_l2:
138 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
139 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
140 ; CHECK-NEXT: movl %eax, %ecx
141 ; CHECK-NEXT: subl %edx, %ecx
142 ; CHECK-NEXT: jne .LBB8_2
143 ; CHECK-NEXT: # %bb.1: # %if.then
144 ; CHECK-NEXT: cmovll %ecx, %eax
146 ; CHECK-NEXT: .LBB8_2: # %if.else
147 ; CHECK-NEXT: movl %ecx, %eax
149 %cmp = icmp eq i32 %b, %a
150 %sub = sub nsw i32 %a, %b
151 br i1 %cmp, label %if.then, label %if.else
154 %cmp2 = icmp sgt i32 %b, %a
155 %sel = select i1 %cmp2, i32 %sub, i32 %a
162 define i32 @func_l3(i32 %a, i32 %b) nounwind {
163 ; CHECK-LABEL: func_l3:
165 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
166 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
167 ; CHECK-NEXT: jge .LBB9_2
168 ; CHECK-NEXT: # %bb.1: # %if.then
170 ; CHECK-NEXT: .LBB9_2: # %if.else
171 ; CHECK-NEXT: incl %eax
173 %cmp = icmp sgt i32 %b, %a
174 %sub = sub nsw i32 %a, %b
175 br i1 %cmp, label %if.then, label %if.else
181 %add = add nsw i32 %sub, 1
186 ; When Movr0 is between sub and cmp, we need to move "Movr0" before sub.
187 define i32 @func_l4(i32 %a, i32 %b) nounwind {
188 ; CHECK-LABEL: func_l4:
190 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
191 ; CHECK-NEXT: xorl %ecx, %ecx
192 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
193 ; CHECK-NEXT: cmovll %ecx, %eax
195 %cmp = icmp sgt i32 %b, %a
196 %sub = sub i32 %a, %b
197 %.sub = select i1 %cmp, i32 0, i32 %sub
202 define i32 @func_n(i32 %x, i32 %y) nounwind {
203 ; CHECK-LABEL: func_n:
205 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
206 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
207 ; CHECK-NEXT: cmpl %ecx, %eax
208 ; CHECK-NEXT: cmovsl %ecx, %eax
210 %sub = sub nsw i32 %x, %y
211 %cmp = icmp slt i32 %sub, 0
212 %y.x = select i1 %cmp, i32 %y, i32 %x
217 define void @func_o() nounwind uwtable {
218 ; CHECK-LABEL: func_o:
219 ; CHECK: # %bb.0: # %entry
220 ; CHECK-NEXT: xorl %eax, %eax
221 ; CHECK-NEXT: testb %al, %al
222 ; CHECK-NEXT: je .LBB12_1
223 ; CHECK-NEXT: # %bb.2: # %if.end.i
224 ; CHECK-NEXT: xorl %eax, %eax
225 ; CHECK-NEXT: testb %al, %al
226 ; CHECK-NEXT: jne .LBB12_5
227 ; CHECK-NEXT: # %bb.3: # %sw.bb
228 ; CHECK-NEXT: xorl %eax, %eax
229 ; CHECK-NEXT: testb %al, %al
230 ; CHECK-NEXT: jne .LBB12_8
231 ; CHECK-NEXT: # %bb.4: # %if.end29
232 ; CHECK-NEXT: movzwl (%eax), %eax
233 ; CHECK-NEXT: imull $-13107, %eax, %eax # imm = 0xCCCD
234 ; CHECK-NEXT: rorw %ax
235 ; CHECK-NEXT: movzwl %ax, %eax
236 ; CHECK-NEXT: cmpl $6554, %eax # imm = 0x199A
237 ; CHECK-NEXT: jae .LBB12_5
238 ; CHECK-NEXT: .LBB12_8: # %if.then44
239 ; CHECK-NEXT: xorl %eax, %eax
240 ; CHECK-NEXT: testb %al, %al
241 ; CHECK-NEXT: je .LBB12_9
242 ; CHECK-NEXT: # %bb.10: # %if.else.i104
244 ; CHECK-NEXT: .LBB12_5: # %sw.default
245 ; CHECK-NEXT: xorl %eax, %eax
246 ; CHECK-NEXT: testb %al, %al
247 ; CHECK-NEXT: jne .LBB12_7
248 ; CHECK-NEXT: # %bb.6: # %if.then.i96
249 ; CHECK-NEXT: .LBB12_1: # %if.then.i
250 ; CHECK-NEXT: .LBB12_9: # %if.then.i103
251 ; CHECK-NEXT: .LBB12_7: # %if.else.i97
253 %0 = load i16, ptr undef, align 2
254 br i1 undef, label %if.then.i, label %if.end.i
256 if.then.i: ; preds = %entry
259 if.end.i: ; preds = %entry
260 br i1 undef, label %sw.bb, label %sw.default
262 sw.bb: ; preds = %if.end.i
263 br i1 undef, label %if.then44, label %if.end29
265 if.end29: ; preds = %sw.bb
267 %cmp25 = icmp eq i16 %1, 0
268 %. = select i1 %cmp25, i16 2, i16 0
269 br i1 %cmp25, label %if.then44, label %sw.default
271 sw.default: ; preds = %if.end29, %if.end.i
272 br i1 undef, label %if.then.i96, label %if.else.i97
274 if.then.i96: ; preds = %sw.default
277 if.else.i97: ; preds = %sw.default
280 if.then44: ; preds = %if.end29, %sw.bb
281 %aModeRefSel.1.ph = phi i16 [ %., %if.end29 ], [ 3, %sw.bb ]
282 br i1 undef, label %if.then.i103, label %if.else.i104
284 if.then.i103: ; preds = %if.then44
287 if.else.i104: ; preds = %if.then44
292 define i32 @func_p(i32 %a, i32 %b) nounwind {
293 ; CHECK-LABEL: func_p:
295 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
296 ; CHECK-NEXT: xorl %ecx, %ecx
297 ; CHECK-NEXT: addl {{[0-9]+}}(%esp), %eax
298 ; CHECK-NEXT: cmovsl %ecx, %eax
300 %add = add nsw i32 %b, %a
301 %cmp = icmp sgt i32 %add, 0
302 %add. = select i1 %cmp, i32 %add, i32 0
307 ; We don't need an explicit cmp here. A sub/neg combo will do.
309 define i32 @func_q(i32 %a0, i32 %a1, i32 %a2) {
310 ; CHECK-LABEL: func_q:
312 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
313 ; CHECK-NEXT: xorl %ecx, %ecx
314 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
315 ; CHECK-NEXT: sbbl %ecx, %ecx
316 ; CHECK-NEXT: negl %eax
317 ; CHECK-NEXT: xorl %ecx, %eax
319 %t1 = icmp ult i32 %a0, %a1
320 %t2 = sub i32 %a1, %a0
321 %t3 = select i1 %t1, i32 -1, i32 0
322 %t4 = xor i32 %t2, %t3
327 define ptr @func_r(ptr %base, ptr nocapture %offset, i32 %size) nounwind {
328 ; CHECK-LABEL: func_r:
329 ; CHECK: # %bb.0: # %entry
330 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
331 ; CHECK-NEXT: movl (%edx), %ecx
332 ; CHECK-NEXT: xorl %eax, %eax
333 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %ecx
334 ; CHECK-NEXT: jl .LBB15_2
335 ; CHECK-NEXT: # %bb.1: # %if.end
336 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
337 ; CHECK-NEXT: movl %ecx, (%edx)
338 ; CHECK-NEXT: addl %ecx, %eax
339 ; CHECK-NEXT: .LBB15_2: # %return
342 %0 = load i32, ptr %offset, align 8
343 %cmp = icmp slt i32 %0, %size
344 br i1 %cmp, label %return, label %if.end
347 %sub = sub nsw i32 %0, %size
348 store i32 %sub, ptr %offset, align 8
349 %add.ptr = getelementptr inbounds i8, ptr %base, i32 %sub
353 %retval.0 = phi ptr [ %add.ptr, %if.end ], [ null, %entry ]
357 ; Test optimizations of dec/inc.
358 define i32 @func_dec(i32 %a) nounwind {
359 ; CHECK-LABEL: func_dec:
361 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
362 ; CHECK-NEXT: xorl %ecx, %ecx
363 ; CHECK-NEXT: decl %eax
364 ; CHECK-NEXT: cmovsl %ecx, %eax
366 %sub = sub nsw i32 %a, 1
367 %cmp = icmp sgt i32 %sub, 0
368 %cond = select i1 %cmp, i32 %sub, i32 0
372 define i32 @func_inc(i32 %a) nounwind {
373 ; CHECK-LABEL: func_inc:
375 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
376 ; CHECK-NEXT: xorl %ecx, %ecx
377 ; CHECK-NEXT: incl %eax
378 ; CHECK-NEXT: cmovsl %ecx, %eax
380 %add = add nsw i32 %a, 1
381 %cmp = icmp sgt i32 %add, 0
382 %cond = select i1 %cmp, i32 %add, i32 0
387 @b = common global i32 0, align 4
388 @a = common global i32 0, align 4
389 define i32 @func_test1(i32 %p1) nounwind uwtable {
390 ; CHECK-LABEL: func_test1:
391 ; CHECK: # %bb.0: # %entry
392 ; CHECK-NEXT: movl b, %eax
393 ; CHECK-NEXT: xorl %ecx, %ecx
394 ; CHECK-NEXT: cmpl {{[0-9]+}}(%esp), %eax
395 ; CHECK-NEXT: setb %cl
396 ; CHECK-NEXT: movl a, %eax
397 ; CHECK-NEXT: testl %eax, %ecx
398 ; CHECK-NEXT: je .LBB18_2
399 ; CHECK-NEXT: # %bb.1: # %if.then
400 ; CHECK-NEXT: decl %eax
401 ; CHECK-NEXT: movl %eax, a
402 ; CHECK-NEXT: .LBB18_2: # %if.end
405 %t0 = load i32, ptr @b, align 4
406 %cmp = icmp ult i32 %t0, %p1
407 %conv = zext i1 %cmp to i32
408 %t1 = load i32, ptr @a, align 4
409 %and = and i32 %conv, %t1
410 %conv1 = trunc i32 %and to i8
411 %t2 = urem i8 %conv1, 3
412 %tobool = icmp eq i8 %t2, 0
413 br i1 %tobool, label %if.end, label %if.then
416 %dec = add nsw i32 %t1, -1
417 store i32 %dec, ptr @a, align 4
424 !1 = !{!"branch_weights", i32 2, i32 1}