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 baz@PLT # TAILCALL
10 ; CHECK-NEXT: # %bb.1: # %cond_true
11 ; CHECK-NEXT: calll bar@PLT
12 ; CHECK-NEXT: jmp baz@PLT # TAILCALL
15 %tmp = icmp slt i32 %tmp1, 0
16 br i1 %tmp, label %cond_true, label %cond_next, !prof !1
18 cond_true: ; preds = %entry
19 %tmp2 = tail call i32 (...) @bar( )
22 cond_next: ; preds = %cond_true, %entry
23 %tmp3 = tail call i32 (...) @baz( )
32 define i32 @func_g(i32 %a, i32 %b) nounwind {
33 ; CHECK-LABEL: func_g:
35 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
36 ; CHECK-NEXT: xorl %ecx, %ecx
37 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
38 ; CHECK-NEXT: cmovsl %ecx, %eax
40 %sub = sub nsw i32 %a, %b
41 %cmp = icmp sgt i32 %sub, 0
42 %cond = select i1 %cmp, i32 %sub, i32 0
47 define i32 @func_h(i32 %a, i32 %b) nounwind {
48 ; CHECK-LABEL: func_h:
50 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
51 ; CHECK-NEXT: xorl %ecx, %ecx
52 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
53 ; CHECK-NEXT: cmovlel %ecx, %eax
55 %cmp = icmp slt i32 %b, %a
56 %sub = sub nsw i32 %a, %b
57 %cond = select i1 %cmp, i32 %sub, i32 0
61 define i32 @func_i(i32 %a, i32 %b) nounwind {
62 ; CHECK-LABEL: func_i:
64 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
65 ; CHECK-NEXT: xorl %ecx, %ecx
66 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
67 ; CHECK-NEXT: cmovlel %ecx, %eax
69 %cmp = icmp sgt i32 %a, %b
70 %sub = sub nsw i32 %a, %b
71 %cond = select i1 %cmp, i32 %sub, i32 0
75 define i32 @func_j(i32 %a, i32 %b) nounwind {
76 ; CHECK-LABEL: func_j:
78 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
79 ; CHECK-NEXT: xorl %ecx, %ecx
80 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
81 ; CHECK-NEXT: cmovbel %ecx, %eax
83 %cmp = icmp ugt i32 %a, %b
85 %cond = select i1 %cmp, i32 %sub, i32 0
89 define i32 @func_k(i32 %a, i32 %b) nounwind {
90 ; CHECK-LABEL: func_k:
92 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
93 ; CHECK-NEXT: xorl %ecx, %ecx
94 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
95 ; CHECK-NEXT: cmovbel %ecx, %eax
97 %cmp = icmp ult i32 %b, %a
99 %cond = select i1 %cmp, i32 %sub, i32 0
103 ; redundant cmp instruction
104 define i32 @func_l(i32 %a, i32 %b) nounwind {
105 ; CHECK-LABEL: func_l:
107 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
108 ; CHECK-NEXT: movl %ecx, %eax
109 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
110 ; CHECK-NEXT: cmovlel %ecx, %eax
112 %cmp = icmp slt i32 %b, %a
113 %sub = sub nsw i32 %a, %b
114 %cond = select i1 %cmp, i32 %sub, i32 %a
118 define i32 @func_m(i32 %a, i32 %b) nounwind {
119 ; CHECK-LABEL: func_m:
121 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
122 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
123 ; CHECK-NEXT: subl %ecx, %eax
124 ; CHECK-NEXT: cmovgl %ecx, %eax
126 %cmp = icmp sgt i32 %a, %b
127 %sub = sub nsw i32 %a, %b
128 %cond = select i1 %cmp, i32 %b, i32 %sub
132 ; (This used to test that an unsafe removal of cmp in bb.0 is not happening,
133 ; but now we can do so safely).
134 define i32 @func_l2(i32 %a, i32 %b) nounwind {
135 ; CHECK-LABEL: func_l2:
137 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
138 ; CHECK-NEXT: movl %eax, %ecx
139 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %ecx
140 ; CHECK-NEXT: jne .LBB8_2
141 ; CHECK-NEXT: # %bb.1: # %if.then
142 ; CHECK-NEXT: cmovll %ecx, %eax
144 ; CHECK-NEXT: .LBB8_2: # %if.else
145 ; CHECK-NEXT: movl %ecx, %eax
147 %cmp = icmp eq i32 %b, %a
148 %sub = sub nsw i32 %a, %b
149 br i1 %cmp, label %if.then, label %if.else
152 %cmp2 = icmp sgt i32 %b, %a
153 %sel = select i1 %cmp2, i32 %sub, i32 %a
160 define i32 @func_l3(i32 %a, i32 %b) nounwind {
161 ; CHECK-LABEL: func_l3:
163 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
164 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
165 ; CHECK-NEXT: jge .LBB9_2
166 ; CHECK-NEXT: # %bb.1: # %if.then
168 ; CHECK-NEXT: .LBB9_2: # %if.else
169 ; CHECK-NEXT: incl %eax
171 %cmp = icmp sgt i32 %b, %a
172 %sub = sub nsw i32 %a, %b
173 br i1 %cmp, label %if.then, label %if.else
179 %add = add nsw i32 %sub, 1
184 ; When Movr0 is between sub and cmp, we need to move "Movr0" before sub.
185 define i32 @func_l4(i32 %a, i32 %b) nounwind {
186 ; CHECK-LABEL: func_l4:
188 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
189 ; CHECK-NEXT: xorl %ecx, %ecx
190 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
191 ; CHECK-NEXT: cmovll %ecx, %eax
193 %cmp = icmp sgt i32 %b, %a
194 %sub = sub i32 %a, %b
195 %.sub = select i1 %cmp, i32 0, i32 %sub
200 define i32 @func_n(i32 %x, i32 %y) nounwind {
201 ; CHECK-LABEL: func_n:
203 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
204 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
205 ; CHECK-NEXT: cmpl %ecx, %eax
206 ; CHECK-NEXT: cmovsl %ecx, %eax
208 %sub = sub nsw i32 %x, %y
209 %cmp = icmp slt i32 %sub, 0
210 %y.x = select i1 %cmp, i32 %y, i32 %x
215 define void @func_o() nounwind uwtable {
216 ; CHECK-LABEL: func_o:
217 ; CHECK: # %bb.0: # %entry
218 ; CHECK-NEXT: xorl %eax, %eax
219 ; CHECK-NEXT: testb %al, %al
220 ; CHECK-NEXT: je .LBB12_1
221 ; CHECK-NEXT: # %bb.2: # %if.end.i
222 ; CHECK-NEXT: xorl %eax, %eax
223 ; CHECK-NEXT: testb %al, %al
224 ; CHECK-NEXT: jne .LBB12_5
225 ; CHECK-NEXT: # %bb.3: # %sw.bb
226 ; CHECK-NEXT: xorl %eax, %eax
227 ; CHECK-NEXT: testb %al, %al
228 ; CHECK-NEXT: jne .LBB12_8
229 ; CHECK-NEXT: # %bb.4: # %if.end29
230 ; CHECK-NEXT: movzwl (%eax), %eax
231 ; CHECK-NEXT: imull $-13107, %eax, %eax # imm = 0xCCCD
232 ; CHECK-NEXT: rorw %ax
233 ; CHECK-NEXT: movzwl %ax, %eax
234 ; CHECK-NEXT: cmpl $6554, %eax # imm = 0x199A
235 ; CHECK-NEXT: jae .LBB12_5
236 ; CHECK-NEXT: .LBB12_8: # %if.then44
237 ; CHECK-NEXT: xorl %eax, %eax
238 ; CHECK-NEXT: testb %al, %al
239 ; CHECK-NEXT: je .LBB12_9
240 ; CHECK-NEXT: # %bb.10: # %if.else.i104
242 ; CHECK-NEXT: .LBB12_5: # %sw.default
243 ; CHECK-NEXT: xorl %eax, %eax
244 ; CHECK-NEXT: testb %al, %al
245 ; CHECK-NEXT: jne .LBB12_7
246 ; CHECK-NEXT: # %bb.6: # %if.then.i96
247 ; CHECK-NEXT: .LBB12_1: # %if.then.i
248 ; CHECK-NEXT: .LBB12_9: # %if.then.i103
249 ; CHECK-NEXT: .LBB12_7: # %if.else.i97
251 %0 = load i16, ptr undef, align 2
252 br i1 undef, label %if.then.i, label %if.end.i
254 if.then.i: ; preds = %entry
257 if.end.i: ; preds = %entry
258 br i1 undef, label %sw.bb, label %sw.default
260 sw.bb: ; preds = %if.end.i
261 br i1 undef, label %if.then44, label %if.end29
263 if.end29: ; preds = %sw.bb
265 %cmp25 = icmp eq i16 %1, 0
266 %. = select i1 %cmp25, i16 2, i16 0
267 br i1 %cmp25, label %if.then44, label %sw.default
269 sw.default: ; preds = %if.end29, %if.end.i
270 br i1 undef, label %if.then.i96, label %if.else.i97
272 if.then.i96: ; preds = %sw.default
275 if.else.i97: ; preds = %sw.default
278 if.then44: ; preds = %if.end29, %sw.bb
279 %aModeRefSel.1.ph = phi i16 [ %., %if.end29 ], [ 3, %sw.bb ]
280 br i1 undef, label %if.then.i103, label %if.else.i104
282 if.then.i103: ; preds = %if.then44
285 if.else.i104: ; preds = %if.then44
290 define i32 @func_p(i32 %a, i32 %b) nounwind {
291 ; CHECK-LABEL: func_p:
293 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
294 ; CHECK-NEXT: xorl %ecx, %ecx
295 ; CHECK-NEXT: addl {{[0-9]+}}(%esp), %eax
296 ; CHECK-NEXT: cmovsl %ecx, %eax
298 %add = add nsw i32 %b, %a
299 %cmp = icmp sgt i32 %add, 0
300 %add. = select i1 %cmp, i32 %add, i32 0
305 ; We don't need an explicit cmp here. A sub/neg combo will do.
307 define i32 @func_q(i32 %a0, i32 %a1, i32 %a2) {
308 ; CHECK-LABEL: func_q:
310 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
311 ; CHECK-NEXT: xorl %ecx, %ecx
312 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %eax
313 ; CHECK-NEXT: sbbl %ecx, %ecx
314 ; CHECK-NEXT: negl %eax
315 ; CHECK-NEXT: xorl %ecx, %eax
317 %t1 = icmp ult i32 %a0, %a1
318 %t2 = sub i32 %a1, %a0
319 %t3 = select i1 %t1, i32 -1, i32 0
320 %t4 = xor i32 %t2, %t3
325 define ptr @func_r(ptr %base, ptr nocapture %offset, i32 %size) nounwind {
326 ; CHECK-LABEL: func_r:
327 ; CHECK: # %bb.0: # %entry
328 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edx
329 ; CHECK-NEXT: movl (%edx), %ecx
330 ; CHECK-NEXT: xorl %eax, %eax
331 ; CHECK-NEXT: subl {{[0-9]+}}(%esp), %ecx
332 ; CHECK-NEXT: jl .LBB15_2
333 ; CHECK-NEXT: # %bb.1: # %if.end
334 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
335 ; CHECK-NEXT: movl %ecx, (%edx)
336 ; CHECK-NEXT: addl %ecx, %eax
337 ; CHECK-NEXT: .LBB15_2: # %return
340 %0 = load i32, ptr %offset, align 8
341 %cmp = icmp slt i32 %0, %size
342 br i1 %cmp, label %return, label %if.end
345 %sub = sub nsw i32 %0, %size
346 store i32 %sub, ptr %offset, align 8
347 %add.ptr = getelementptr inbounds i8, ptr %base, i32 %sub
351 %retval.0 = phi ptr [ %add.ptr, %if.end ], [ null, %entry ]
355 ; Test optimizations of dec/inc.
356 define i32 @func_dec(i32 %a) nounwind {
357 ; CHECK-LABEL: func_dec:
359 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
360 ; CHECK-NEXT: xorl %ecx, %ecx
361 ; CHECK-NEXT: decl %eax
362 ; CHECK-NEXT: cmovsl %ecx, %eax
364 %sub = sub nsw i32 %a, 1
365 %cmp = icmp sgt i32 %sub, 0
366 %cond = select i1 %cmp, i32 %sub, i32 0
370 define i32 @func_inc(i32 %a) nounwind {
371 ; CHECK-LABEL: func_inc:
373 ; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
374 ; CHECK-NEXT: xorl %ecx, %ecx
375 ; CHECK-NEXT: incl %eax
376 ; CHECK-NEXT: cmovsl %ecx, %eax
378 %add = add nsw i32 %a, 1
379 %cmp = icmp sgt i32 %add, 0
380 %cond = select i1 %cmp, i32 %add, i32 0
385 @b = common global i32 0, align 4
386 @a = common global i32 0, align 4
387 define i32 @func_test1(i32 %p1) nounwind uwtable {
388 ; CHECK-LABEL: func_test1:
389 ; CHECK: # %bb.0: # %entry
390 ; CHECK-NEXT: movl b, %eax
391 ; CHECK-NEXT: xorl %ecx, %ecx
392 ; CHECK-NEXT: cmpl {{[0-9]+}}(%esp), %eax
393 ; CHECK-NEXT: setb %cl
394 ; CHECK-NEXT: movl a, %eax
395 ; CHECK-NEXT: testl %eax, %ecx
396 ; CHECK-NEXT: je .LBB18_2
397 ; CHECK-NEXT: # %bb.1: # %if.then
398 ; CHECK-NEXT: decl %eax
399 ; CHECK-NEXT: movl %eax, a
400 ; CHECK-NEXT: .LBB18_2: # %if.end
403 %t0 = load i32, ptr @b, align 4
404 %cmp = icmp ult i32 %t0, %p1
405 %conv = zext i1 %cmp to i32
406 %t1 = load i32, ptr @a, align 4
407 %and = and i32 %conv, %t1
408 %conv1 = trunc i32 %and to i8
409 %t2 = urem i8 %conv1, 3
410 %tobool = icmp eq i8 %t2, 0
411 br i1 %tobool, label %if.end, label %if.then
414 %dec = add nsw i32 %t1, -1
415 store i32 %dec, ptr @a, align 4
422 !1 = !{!"branch_weights", i32 2, i32 1}