1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86
5 ; These test cases are inspired by C++2a std::midpoint().
6 ; See https://bugs.llvm.org/show_bug.cgi?id=40965
8 ; ---------------------------------------------------------------------------- ;
10 ; ---------------------------------------------------------------------------- ;
12 ; Values come from regs
14 define i32 @scalar_i32_signed_reg_reg(i32 %a1, i32 %a2) nounwind {
15 ; X64-LABEL: scalar_i32_signed_reg_reg:
17 ; X64-NEXT: xorl %eax, %eax
18 ; X64-NEXT: cmpl %esi, %edi
20 ; X64-NEXT: leal -1(%rax,%rax), %eax
21 ; X64-NEXT: movl %edi, %ecx
22 ; X64-NEXT: cmovgl %esi, %ecx
23 ; X64-NEXT: cmovgl %edi, %esi
24 ; X64-NEXT: subl %ecx, %esi
26 ; X64-NEXT: imull %esi, %eax
27 ; X64-NEXT: addl %edi, %eax
30 ; X86-LABEL: scalar_i32_signed_reg_reg:
32 ; X86-NEXT: pushl %esi
33 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
34 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
35 ; X86-NEXT: xorl %edx, %edx
36 ; X86-NEXT: cmpl %eax, %ecx
38 ; X86-NEXT: leal -1(%edx,%edx), %edx
39 ; X86-NEXT: jg .LBB0_1
41 ; X86-NEXT: movl %ecx, %esi
42 ; X86-NEXT: jmp .LBB0_3
44 ; X86-NEXT: movl %eax, %esi
45 ; X86-NEXT: movl %ecx, %eax
47 ; X86-NEXT: subl %esi, %eax
49 ; X86-NEXT: imull %edx, %eax
50 ; X86-NEXT: addl %ecx, %eax
53 %t3 = icmp sgt i32 %a1, %a2 ; signed
54 %t4 = select i1 %t3, i32 -1, i32 1
55 %t5 = select i1 %t3, i32 %a2, i32 %a1
56 %t6 = select i1 %t3, i32 %a1, i32 %a2
57 %t7 = sub i32 %t6, %t5
59 %t9 = mul nsw i32 %t8, %t4 ; signed
60 %a10 = add nsw i32 %t9, %a1 ; signed
64 define i32 @scalar_i32_unsigned_reg_reg(i32 %a1, i32 %a2) nounwind {
65 ; X64-LABEL: scalar_i32_unsigned_reg_reg:
67 ; X64-NEXT: xorl %eax, %eax
68 ; X64-NEXT: cmpl %esi, %edi
70 ; X64-NEXT: leal -1(%rax,%rax), %eax
71 ; X64-NEXT: movl %edi, %ecx
72 ; X64-NEXT: cmoval %esi, %ecx
73 ; X64-NEXT: cmoval %edi, %esi
74 ; X64-NEXT: subl %ecx, %esi
76 ; X64-NEXT: imull %esi, %eax
77 ; X64-NEXT: addl %edi, %eax
80 ; X86-LABEL: scalar_i32_unsigned_reg_reg:
82 ; X86-NEXT: pushl %esi
83 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
84 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
85 ; X86-NEXT: xorl %edx, %edx
86 ; X86-NEXT: cmpl %eax, %ecx
88 ; X86-NEXT: leal -1(%edx,%edx), %edx
89 ; X86-NEXT: ja .LBB1_1
91 ; X86-NEXT: movl %ecx, %esi
92 ; X86-NEXT: jmp .LBB1_3
94 ; X86-NEXT: movl %eax, %esi
95 ; X86-NEXT: movl %ecx, %eax
97 ; X86-NEXT: subl %esi, %eax
99 ; X86-NEXT: imull %edx, %eax
100 ; X86-NEXT: addl %ecx, %eax
101 ; X86-NEXT: popl %esi
103 %t3 = icmp ugt i32 %a1, %a2
104 %t4 = select i1 %t3, i32 -1, i32 1
105 %t5 = select i1 %t3, i32 %a2, i32 %a1
106 %t6 = select i1 %t3, i32 %a1, i32 %a2
107 %t7 = sub i32 %t6, %t5
108 %t8 = lshr i32 %t7, 1
109 %t9 = mul i32 %t8, %t4
110 %a10 = add i32 %t9, %a1
114 ; Values are loaded. Only check signed case.
116 define i32 @scalar_i32_signed_mem_reg(ptr %a1_addr, i32 %a2) nounwind {
117 ; X64-LABEL: scalar_i32_signed_mem_reg:
119 ; X64-NEXT: movl (%rdi), %ecx
120 ; X64-NEXT: xorl %eax, %eax
121 ; X64-NEXT: cmpl %esi, %ecx
122 ; X64-NEXT: setle %al
123 ; X64-NEXT: leal -1(%rax,%rax), %eax
124 ; X64-NEXT: movl %ecx, %edx
125 ; X64-NEXT: cmovgl %esi, %edx
126 ; X64-NEXT: cmovgl %ecx, %esi
127 ; X64-NEXT: subl %edx, %esi
128 ; X64-NEXT: shrl %esi
129 ; X64-NEXT: imull %esi, %eax
130 ; X64-NEXT: addl %ecx, %eax
133 ; X86-LABEL: scalar_i32_signed_mem_reg:
135 ; X86-NEXT: pushl %esi
136 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
137 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
138 ; X86-NEXT: movl (%ecx), %ecx
139 ; X86-NEXT: xorl %edx, %edx
140 ; X86-NEXT: cmpl %eax, %ecx
141 ; X86-NEXT: setle %dl
142 ; X86-NEXT: leal -1(%edx,%edx), %edx
143 ; X86-NEXT: jg .LBB2_1
145 ; X86-NEXT: movl %ecx, %esi
146 ; X86-NEXT: jmp .LBB2_3
148 ; X86-NEXT: movl %eax, %esi
149 ; X86-NEXT: movl %ecx, %eax
151 ; X86-NEXT: subl %esi, %eax
152 ; X86-NEXT: shrl %eax
153 ; X86-NEXT: imull %edx, %eax
154 ; X86-NEXT: addl %ecx, %eax
155 ; X86-NEXT: popl %esi
157 %a1 = load i32, ptr %a1_addr
158 %t3 = icmp sgt i32 %a1, %a2 ; signed
159 %t4 = select i1 %t3, i32 -1, i32 1
160 %t5 = select i1 %t3, i32 %a2, i32 %a1
161 %t6 = select i1 %t3, i32 %a1, i32 %a2
162 %t7 = sub i32 %t6, %t5
163 %t8 = lshr i32 %t7, 1
164 %t9 = mul nsw i32 %t8, %t4 ; signed
165 %a10 = add nsw i32 %t9, %a1 ; signed
169 define i32 @scalar_i32_signed_reg_mem(i32 %a1, ptr %a2_addr) nounwind {
170 ; X64-LABEL: scalar_i32_signed_reg_mem:
172 ; X64-NEXT: movl (%rsi), %eax
173 ; X64-NEXT: xorl %ecx, %ecx
174 ; X64-NEXT: cmpl %eax, %edi
175 ; X64-NEXT: setle %cl
176 ; X64-NEXT: leal -1(%rcx,%rcx), %ecx
177 ; X64-NEXT: movl %edi, %edx
178 ; X64-NEXT: cmovgl %eax, %edx
179 ; X64-NEXT: cmovgl %edi, %eax
180 ; X64-NEXT: subl %edx, %eax
181 ; X64-NEXT: shrl %eax
182 ; X64-NEXT: imull %ecx, %eax
183 ; X64-NEXT: addl %edi, %eax
186 ; X86-LABEL: scalar_i32_signed_reg_mem:
188 ; X86-NEXT: pushl %esi
189 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
190 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
191 ; X86-NEXT: movl (%eax), %eax
192 ; X86-NEXT: xorl %edx, %edx
193 ; X86-NEXT: cmpl %eax, %ecx
194 ; X86-NEXT: setle %dl
195 ; X86-NEXT: leal -1(%edx,%edx), %edx
196 ; X86-NEXT: jg .LBB3_1
198 ; X86-NEXT: movl %ecx, %esi
199 ; X86-NEXT: jmp .LBB3_3
201 ; X86-NEXT: movl %eax, %esi
202 ; X86-NEXT: movl %ecx, %eax
204 ; X86-NEXT: subl %esi, %eax
205 ; X86-NEXT: shrl %eax
206 ; X86-NEXT: imull %edx, %eax
207 ; X86-NEXT: addl %ecx, %eax
208 ; X86-NEXT: popl %esi
210 %a2 = load i32, ptr %a2_addr
211 %t3 = icmp sgt i32 %a1, %a2 ; signed
212 %t4 = select i1 %t3, i32 -1, i32 1
213 %t5 = select i1 %t3, i32 %a2, i32 %a1
214 %t6 = select i1 %t3, i32 %a1, i32 %a2
215 %t7 = sub i32 %t6, %t5
216 %t8 = lshr i32 %t7, 1
217 %t9 = mul nsw i32 %t8, %t4 ; signed
218 %a10 = add nsw i32 %t9, %a1 ; signed
222 define i32 @scalar_i32_signed_mem_mem(ptr %a1_addr, ptr %a2_addr) nounwind {
223 ; X64-LABEL: scalar_i32_signed_mem_mem:
225 ; X64-NEXT: movl (%rdi), %ecx
226 ; X64-NEXT: movl (%rsi), %eax
227 ; X64-NEXT: xorl %edx, %edx
228 ; X64-NEXT: cmpl %eax, %ecx
229 ; X64-NEXT: setle %dl
230 ; X64-NEXT: leal -1(%rdx,%rdx), %edx
231 ; X64-NEXT: movl %ecx, %esi
232 ; X64-NEXT: cmovgl %eax, %esi
233 ; X64-NEXT: cmovgl %ecx, %eax
234 ; X64-NEXT: subl %esi, %eax
235 ; X64-NEXT: shrl %eax
236 ; X64-NEXT: imull %edx, %eax
237 ; X64-NEXT: addl %ecx, %eax
240 ; X86-LABEL: scalar_i32_signed_mem_mem:
242 ; X86-NEXT: pushl %esi
243 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
244 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
245 ; X86-NEXT: movl (%ecx), %ecx
246 ; X86-NEXT: movl (%eax), %eax
247 ; X86-NEXT: xorl %edx, %edx
248 ; X86-NEXT: cmpl %eax, %ecx
249 ; X86-NEXT: setle %dl
250 ; X86-NEXT: leal -1(%edx,%edx), %edx
251 ; X86-NEXT: jg .LBB4_1
253 ; X86-NEXT: movl %ecx, %esi
254 ; X86-NEXT: jmp .LBB4_3
256 ; X86-NEXT: movl %eax, %esi
257 ; X86-NEXT: movl %ecx, %eax
259 ; X86-NEXT: subl %esi, %eax
260 ; X86-NEXT: shrl %eax
261 ; X86-NEXT: imull %edx, %eax
262 ; X86-NEXT: addl %ecx, %eax
263 ; X86-NEXT: popl %esi
265 %a1 = load i32, ptr %a1_addr
266 %a2 = load i32, ptr %a2_addr
267 %t3 = icmp sgt i32 %a1, %a2 ; signed
268 %t4 = select i1 %t3, i32 -1, i32 1
269 %t5 = select i1 %t3, i32 %a2, i32 %a1
270 %t6 = select i1 %t3, i32 %a1, i32 %a2
271 %t7 = sub i32 %t6, %t5
272 %t8 = lshr i32 %t7, 1
273 %t9 = mul nsw i32 %t8, %t4 ; signed
274 %a10 = add nsw i32 %t9, %a1 ; signed
278 ; ---------------------------------------------------------------------------- ;
280 ; ---------------------------------------------------------------------------- ;
282 ; Values come from regs
284 define i64 @scalar_i64_signed_reg_reg(i64 %a1, i64 %a2) nounwind {
285 ; X64-LABEL: scalar_i64_signed_reg_reg:
287 ; X64-NEXT: xorl %eax, %eax
288 ; X64-NEXT: cmpq %rsi, %rdi
289 ; X64-NEXT: setle %al
290 ; X64-NEXT: leaq -1(%rax,%rax), %rax
291 ; X64-NEXT: movq %rdi, %rcx
292 ; X64-NEXT: cmovgq %rsi, %rcx
293 ; X64-NEXT: cmovgq %rdi, %rsi
294 ; X64-NEXT: subq %rcx, %rsi
295 ; X64-NEXT: shrq %rsi
296 ; X64-NEXT: imulq %rsi, %rax
297 ; X64-NEXT: addq %rdi, %rax
300 ; X86-LABEL: scalar_i64_signed_reg_reg:
302 ; X86-NEXT: pushl %ebp
303 ; X86-NEXT: pushl %ebx
304 ; X86-NEXT: pushl %edi
305 ; X86-NEXT: pushl %esi
306 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
307 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
308 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
309 ; X86-NEXT: cmpl {{[0-9]+}}(%esp), %eax
310 ; X86-NEXT: movl %edi, %edx
311 ; X86-NEXT: sbbl %ebp, %edx
313 ; X86-NEXT: movzbl %dl, %ebx
314 ; X86-NEXT: jl .LBB5_1
316 ; X86-NEXT: movl %ebp, %ecx
317 ; X86-NEXT: movl %ebp, %edx
318 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
319 ; X86-NEXT: jmp .LBB5_3
321 ; X86-NEXT: movl %edi, %edx
322 ; X86-NEXT: movl %eax, %esi
323 ; X86-NEXT: movl %ebp, %ecx
324 ; X86-NEXT: movl %ebp, %edi
325 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
327 ; X86-NEXT: negl %ebx
328 ; X86-NEXT: movl %ebx, %ebp
329 ; X86-NEXT: orl $1, %ebp
330 ; X86-NEXT: subl %esi, %eax
331 ; X86-NEXT: sbbl %edx, %edi
332 ; X86-NEXT: shrdl $1, %edi, %eax
333 ; X86-NEXT: imull %eax, %ebx
334 ; X86-NEXT: mull %ebp
335 ; X86-NEXT: addl %ebx, %edx
336 ; X86-NEXT: shrl %edi
337 ; X86-NEXT: imull %ebp, %edi
338 ; X86-NEXT: addl %edi, %edx
339 ; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
340 ; X86-NEXT: adcl %ecx, %edx
341 ; X86-NEXT: popl %esi
342 ; X86-NEXT: popl %edi
343 ; X86-NEXT: popl %ebx
344 ; X86-NEXT: popl %ebp
346 %t3 = icmp sgt i64 %a1, %a2 ; signed
347 %t4 = select i1 %t3, i64 -1, i64 1
348 %t5 = select i1 %t3, i64 %a2, i64 %a1
349 %t6 = select i1 %t3, i64 %a1, i64 %a2
350 %t7 = sub i64 %t6, %t5
351 %t8 = lshr i64 %t7, 1
352 %t9 = mul nsw i64 %t8, %t4 ; signed
353 %a10 = add nsw i64 %t9, %a1 ; signed
357 define i64 @scalar_i64_unsigned_reg_reg(i64 %a1, i64 %a2) nounwind {
358 ; X64-LABEL: scalar_i64_unsigned_reg_reg:
360 ; X64-NEXT: xorl %eax, %eax
361 ; X64-NEXT: cmpq %rsi, %rdi
362 ; X64-NEXT: setbe %al
363 ; X64-NEXT: leaq -1(%rax,%rax), %rax
364 ; X64-NEXT: movq %rdi, %rcx
365 ; X64-NEXT: cmovaq %rsi, %rcx
366 ; X64-NEXT: cmovaq %rdi, %rsi
367 ; X64-NEXT: subq %rcx, %rsi
368 ; X64-NEXT: shrq %rsi
369 ; X64-NEXT: imulq %rsi, %rax
370 ; X64-NEXT: addq %rdi, %rax
373 ; X86-LABEL: scalar_i64_unsigned_reg_reg:
375 ; X86-NEXT: pushl %ebp
376 ; X86-NEXT: pushl %ebx
377 ; X86-NEXT: pushl %edi
378 ; X86-NEXT: pushl %esi
379 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
380 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
381 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
382 ; X86-NEXT: xorl %ebx, %ebx
383 ; X86-NEXT: cmpl {{[0-9]+}}(%esp), %eax
384 ; X86-NEXT: movl %edi, %edx
385 ; X86-NEXT: sbbl %ebp, %edx
387 ; X86-NEXT: sbbl %ebx, %ebx
388 ; X86-NEXT: testb %dl, %dl
389 ; X86-NEXT: jne .LBB6_1
391 ; X86-NEXT: movl %ebp, %ecx
392 ; X86-NEXT: movl %ebp, %edx
393 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
394 ; X86-NEXT: jmp .LBB6_3
396 ; X86-NEXT: movl %edi, %edx
397 ; X86-NEXT: movl %eax, %esi
398 ; X86-NEXT: movl %ebp, %ecx
399 ; X86-NEXT: movl %ebp, %edi
400 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
402 ; X86-NEXT: movl %ebx, %ebp
403 ; X86-NEXT: orl $1, %ebp
404 ; X86-NEXT: subl %esi, %eax
405 ; X86-NEXT: sbbl %edx, %edi
406 ; X86-NEXT: shrdl $1, %edi, %eax
407 ; X86-NEXT: imull %eax, %ebx
408 ; X86-NEXT: mull %ebp
409 ; X86-NEXT: addl %ebx, %edx
410 ; X86-NEXT: shrl %edi
411 ; X86-NEXT: imull %ebp, %edi
412 ; X86-NEXT: addl %edi, %edx
413 ; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
414 ; X86-NEXT: adcl %ecx, %edx
415 ; X86-NEXT: popl %esi
416 ; X86-NEXT: popl %edi
417 ; X86-NEXT: popl %ebx
418 ; X86-NEXT: popl %ebp
420 %t3 = icmp ugt i64 %a1, %a2
421 %t4 = select i1 %t3, i64 -1, i64 1
422 %t5 = select i1 %t3, i64 %a2, i64 %a1
423 %t6 = select i1 %t3, i64 %a1, i64 %a2
424 %t7 = sub i64 %t6, %t5
425 %t8 = lshr i64 %t7, 1
426 %t9 = mul i64 %t8, %t4
427 %a10 = add i64 %t9, %a1
431 ; Values are loaded. Only check signed case.
433 define i64 @scalar_i64_signed_mem_reg(ptr %a1_addr, i64 %a2) nounwind {
434 ; X64-LABEL: scalar_i64_signed_mem_reg:
436 ; X64-NEXT: movq (%rdi), %rcx
437 ; X64-NEXT: xorl %eax, %eax
438 ; X64-NEXT: cmpq %rsi, %rcx
439 ; X64-NEXT: setle %al
440 ; X64-NEXT: leaq -1(%rax,%rax), %rax
441 ; X64-NEXT: movq %rcx, %rdx
442 ; X64-NEXT: cmovgq %rsi, %rdx
443 ; X64-NEXT: cmovgq %rcx, %rsi
444 ; X64-NEXT: subq %rdx, %rsi
445 ; X64-NEXT: shrq %rsi
446 ; X64-NEXT: imulq %rsi, %rax
447 ; X64-NEXT: addq %rcx, %rax
450 ; X86-LABEL: scalar_i64_signed_mem_reg:
452 ; X86-NEXT: pushl %ebp
453 ; X86-NEXT: pushl %ebx
454 ; X86-NEXT: pushl %edi
455 ; X86-NEXT: pushl %esi
456 ; X86-NEXT: pushl %eax
457 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
458 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
459 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
460 ; X86-NEXT: movl (%ecx), %esi
461 ; X86-NEXT: movl 4(%ecx), %ecx
462 ; X86-NEXT: cmpl %esi, %eax
463 ; X86-NEXT: movl %edi, %edx
464 ; X86-NEXT: sbbl %ecx, %edx
466 ; X86-NEXT: movzbl %dl, %ebx
467 ; X86-NEXT: jl .LBB7_1
469 ; X86-NEXT: movl %ecx, (%esp) # 4-byte Spill
470 ; X86-NEXT: movl %esi, %edx
471 ; X86-NEXT: jmp .LBB7_3
473 ; X86-NEXT: movl %edi, (%esp) # 4-byte Spill
474 ; X86-NEXT: movl %eax, %edx
475 ; X86-NEXT: movl %ecx, %edi
476 ; X86-NEXT: movl %esi, %eax
478 ; X86-NEXT: negl %ebx
479 ; X86-NEXT: movl %ebx, %ebp
480 ; X86-NEXT: orl $1, %ebp
481 ; X86-NEXT: subl %edx, %eax
482 ; X86-NEXT: sbbl (%esp), %edi # 4-byte Folded Reload
483 ; X86-NEXT: shrdl $1, %edi, %eax
484 ; X86-NEXT: imull %eax, %ebx
485 ; X86-NEXT: mull %ebp
486 ; X86-NEXT: addl %ebx, %edx
487 ; X86-NEXT: shrl %edi
488 ; X86-NEXT: imull %ebp, %edi
489 ; X86-NEXT: addl %edi, %edx
490 ; X86-NEXT: addl %esi, %eax
491 ; X86-NEXT: adcl %ecx, %edx
492 ; X86-NEXT: addl $4, %esp
493 ; X86-NEXT: popl %esi
494 ; X86-NEXT: popl %edi
495 ; X86-NEXT: popl %ebx
496 ; X86-NEXT: popl %ebp
498 %a1 = load i64, ptr %a1_addr
499 %t3 = icmp sgt i64 %a1, %a2 ; signed
500 %t4 = select i1 %t3, i64 -1, i64 1
501 %t5 = select i1 %t3, i64 %a2, i64 %a1
502 %t6 = select i1 %t3, i64 %a1, i64 %a2
503 %t7 = sub i64 %t6, %t5
504 %t8 = lshr i64 %t7, 1
505 %t9 = mul nsw i64 %t8, %t4 ; signed
506 %a10 = add nsw i64 %t9, %a1 ; signed
510 define i64 @scalar_i64_signed_reg_mem(i64 %a1, ptr %a2_addr) nounwind {
511 ; X64-LABEL: scalar_i64_signed_reg_mem:
513 ; X64-NEXT: movq (%rsi), %rax
514 ; X64-NEXT: xorl %ecx, %ecx
515 ; X64-NEXT: cmpq %rax, %rdi
516 ; X64-NEXT: setle %cl
517 ; X64-NEXT: leaq -1(%rcx,%rcx), %rcx
518 ; X64-NEXT: movq %rdi, %rdx
519 ; X64-NEXT: cmovgq %rax, %rdx
520 ; X64-NEXT: cmovgq %rdi, %rax
521 ; X64-NEXT: subq %rdx, %rax
522 ; X64-NEXT: shrq %rax
523 ; X64-NEXT: imulq %rcx, %rax
524 ; X64-NEXT: addq %rdi, %rax
527 ; X86-LABEL: scalar_i64_signed_reg_mem:
529 ; X86-NEXT: pushl %ebp
530 ; X86-NEXT: pushl %ebx
531 ; X86-NEXT: pushl %edi
532 ; X86-NEXT: pushl %esi
533 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebp
534 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
535 ; X86-NEXT: movl (%edx), %eax
536 ; X86-NEXT: movl 4(%edx), %edi
537 ; X86-NEXT: cmpl {{[0-9]+}}(%esp), %eax
538 ; X86-NEXT: movl %edi, %edx
539 ; X86-NEXT: sbbl %ebp, %edx
541 ; X86-NEXT: movzbl %dl, %ebx
542 ; X86-NEXT: jl .LBB8_1
544 ; X86-NEXT: movl %ebp, %ecx
545 ; X86-NEXT: movl %ebp, %edx
546 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
547 ; X86-NEXT: jmp .LBB8_3
549 ; X86-NEXT: movl %edi, %edx
550 ; X86-NEXT: movl %eax, %esi
551 ; X86-NEXT: movl %ebp, %ecx
552 ; X86-NEXT: movl %ebp, %edi
553 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
555 ; X86-NEXT: negl %ebx
556 ; X86-NEXT: movl %ebx, %ebp
557 ; X86-NEXT: orl $1, %ebp
558 ; X86-NEXT: subl %esi, %eax
559 ; X86-NEXT: sbbl %edx, %edi
560 ; X86-NEXT: shrdl $1, %edi, %eax
561 ; X86-NEXT: imull %eax, %ebx
562 ; X86-NEXT: mull %ebp
563 ; X86-NEXT: addl %ebx, %edx
564 ; X86-NEXT: shrl %edi
565 ; X86-NEXT: imull %ebp, %edi
566 ; X86-NEXT: addl %edi, %edx
567 ; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
568 ; X86-NEXT: adcl %ecx, %edx
569 ; X86-NEXT: popl %esi
570 ; X86-NEXT: popl %edi
571 ; X86-NEXT: popl %ebx
572 ; X86-NEXT: popl %ebp
574 %a2 = load i64, ptr %a2_addr
575 %t3 = icmp sgt i64 %a1, %a2 ; signed
576 %t4 = select i1 %t3, i64 -1, i64 1
577 %t5 = select i1 %t3, i64 %a2, i64 %a1
578 %t6 = select i1 %t3, i64 %a1, i64 %a2
579 %t7 = sub i64 %t6, %t5
580 %t8 = lshr i64 %t7, 1
581 %t9 = mul nsw i64 %t8, %t4 ; signed
582 %a10 = add nsw i64 %t9, %a1 ; signed
586 define i64 @scalar_i64_signed_mem_mem(ptr %a1_addr, ptr %a2_addr) nounwind {
587 ; X64-LABEL: scalar_i64_signed_mem_mem:
589 ; X64-NEXT: movq (%rdi), %rcx
590 ; X64-NEXT: movq (%rsi), %rax
591 ; X64-NEXT: xorl %edx, %edx
592 ; X64-NEXT: cmpq %rax, %rcx
593 ; X64-NEXT: setle %dl
594 ; X64-NEXT: leaq -1(%rdx,%rdx), %rdx
595 ; X64-NEXT: movq %rcx, %rsi
596 ; X64-NEXT: cmovgq %rax, %rsi
597 ; X64-NEXT: cmovgq %rcx, %rax
598 ; X64-NEXT: subq %rsi, %rax
599 ; X64-NEXT: shrq %rax
600 ; X64-NEXT: imulq %rdx, %rax
601 ; X64-NEXT: addq %rcx, %rax
604 ; X86-LABEL: scalar_i64_signed_mem_mem:
606 ; X86-NEXT: pushl %ebp
607 ; X86-NEXT: pushl %ebx
608 ; X86-NEXT: pushl %edi
609 ; X86-NEXT: pushl %esi
610 ; X86-NEXT: pushl %eax
611 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
612 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
613 ; X86-NEXT: movl (%eax), %esi
614 ; X86-NEXT: movl 4(%eax), %ecx
615 ; X86-NEXT: movl (%edx), %eax
616 ; X86-NEXT: movl 4(%edx), %edi
617 ; X86-NEXT: cmpl %esi, %eax
618 ; X86-NEXT: movl %edi, %edx
619 ; X86-NEXT: sbbl %ecx, %edx
621 ; X86-NEXT: movzbl %dl, %ebx
622 ; X86-NEXT: jl .LBB9_1
624 ; X86-NEXT: movl %ecx, (%esp) # 4-byte Spill
625 ; X86-NEXT: movl %esi, %edx
626 ; X86-NEXT: jmp .LBB9_3
628 ; X86-NEXT: movl %edi, (%esp) # 4-byte Spill
629 ; X86-NEXT: movl %eax, %edx
630 ; X86-NEXT: movl %ecx, %edi
631 ; X86-NEXT: movl %esi, %eax
633 ; X86-NEXT: negl %ebx
634 ; X86-NEXT: movl %ebx, %ebp
635 ; X86-NEXT: orl $1, %ebp
636 ; X86-NEXT: subl %edx, %eax
637 ; X86-NEXT: sbbl (%esp), %edi # 4-byte Folded Reload
638 ; X86-NEXT: shrdl $1, %edi, %eax
639 ; X86-NEXT: imull %eax, %ebx
640 ; X86-NEXT: mull %ebp
641 ; X86-NEXT: addl %ebx, %edx
642 ; X86-NEXT: shrl %edi
643 ; X86-NEXT: imull %ebp, %edi
644 ; X86-NEXT: addl %edi, %edx
645 ; X86-NEXT: addl %esi, %eax
646 ; X86-NEXT: adcl %ecx, %edx
647 ; X86-NEXT: addl $4, %esp
648 ; X86-NEXT: popl %esi
649 ; X86-NEXT: popl %edi
650 ; X86-NEXT: popl %ebx
651 ; X86-NEXT: popl %ebp
653 %a1 = load i64, ptr %a1_addr
654 %a2 = load i64, ptr %a2_addr
655 %t3 = icmp sgt i64 %a1, %a2 ; signed
656 %t4 = select i1 %t3, i64 -1, i64 1
657 %t5 = select i1 %t3, i64 %a2, i64 %a1
658 %t6 = select i1 %t3, i64 %a1, i64 %a2
659 %t7 = sub i64 %t6, %t5
660 %t8 = lshr i64 %t7, 1
661 %t9 = mul nsw i64 %t8, %t4 ; signed
662 %a10 = add nsw i64 %t9, %a1 ; signed
666 ; ---------------------------------------------------------------------------- ;
668 ; ---------------------------------------------------------------------------- ;
670 ; Values come from regs
672 define i16 @scalar_i16_signed_reg_reg(i16 %a1, i16 %a2) nounwind {
673 ; X64-LABEL: scalar_i16_signed_reg_reg:
675 ; X64-NEXT: xorl %eax, %eax
676 ; X64-NEXT: cmpw %si, %di
677 ; X64-NEXT: setle %al
678 ; X64-NEXT: leal -1(%rax,%rax), %ecx
679 ; X64-NEXT: movl %edi, %eax
680 ; X64-NEXT: cmovgl %esi, %eax
681 ; X64-NEXT: cmovgl %edi, %esi
682 ; X64-NEXT: subl %eax, %esi
683 ; X64-NEXT: movzwl %si, %eax
684 ; X64-NEXT: shrl %eax
685 ; X64-NEXT: imull %ecx, %eax
686 ; X64-NEXT: addl %edi, %eax
687 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
690 ; X86-LABEL: scalar_i16_signed_reg_reg:
692 ; X86-NEXT: pushl %esi
693 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
694 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
695 ; X86-NEXT: xorl %edx, %edx
696 ; X86-NEXT: cmpw %ax, %cx
697 ; X86-NEXT: setle %dl
698 ; X86-NEXT: leal -1(%edx,%edx), %edx
699 ; X86-NEXT: jg .LBB10_1
701 ; X86-NEXT: movl %ecx, %esi
702 ; X86-NEXT: jmp .LBB10_3
703 ; X86-NEXT: .LBB10_1:
704 ; X86-NEXT: movl %eax, %esi
705 ; X86-NEXT: movl %ecx, %eax
706 ; X86-NEXT: .LBB10_3:
707 ; X86-NEXT: subl %esi, %eax
708 ; X86-NEXT: movzwl %ax, %eax
709 ; X86-NEXT: shrl %eax
710 ; X86-NEXT: imull %edx, %eax
711 ; X86-NEXT: addl %ecx, %eax
712 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
713 ; X86-NEXT: popl %esi
715 %t3 = icmp sgt i16 %a1, %a2 ; signed
716 %t4 = select i1 %t3, i16 -1, i16 1
717 %t5 = select i1 %t3, i16 %a2, i16 %a1
718 %t6 = select i1 %t3, i16 %a1, i16 %a2
719 %t7 = sub i16 %t6, %t5
720 %t8 = lshr i16 %t7, 1
721 %t9 = mul nsw i16 %t8, %t4 ; signed
722 %a10 = add nsw i16 %t9, %a1 ; signed
726 define i16 @scalar_i16_unsigned_reg_reg(i16 %a1, i16 %a2) nounwind {
727 ; X64-LABEL: scalar_i16_unsigned_reg_reg:
729 ; X64-NEXT: xorl %eax, %eax
730 ; X64-NEXT: cmpw %si, %di
731 ; X64-NEXT: setbe %al
732 ; X64-NEXT: leal -1(%rax,%rax), %ecx
733 ; X64-NEXT: movl %edi, %eax
734 ; X64-NEXT: cmoval %esi, %eax
735 ; X64-NEXT: cmoval %edi, %esi
736 ; X64-NEXT: subl %eax, %esi
737 ; X64-NEXT: movzwl %si, %eax
738 ; X64-NEXT: shrl %eax
739 ; X64-NEXT: imull %ecx, %eax
740 ; X64-NEXT: addl %edi, %eax
741 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
744 ; X86-LABEL: scalar_i16_unsigned_reg_reg:
746 ; X86-NEXT: pushl %esi
747 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
748 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
749 ; X86-NEXT: xorl %edx, %edx
750 ; X86-NEXT: cmpw %ax, %cx
751 ; X86-NEXT: setbe %dl
752 ; X86-NEXT: leal -1(%edx,%edx), %edx
753 ; X86-NEXT: ja .LBB11_1
755 ; X86-NEXT: movl %ecx, %esi
756 ; X86-NEXT: jmp .LBB11_3
757 ; X86-NEXT: .LBB11_1:
758 ; X86-NEXT: movl %eax, %esi
759 ; X86-NEXT: movl %ecx, %eax
760 ; X86-NEXT: .LBB11_3:
761 ; X86-NEXT: subl %esi, %eax
762 ; X86-NEXT: movzwl %ax, %eax
763 ; X86-NEXT: shrl %eax
764 ; X86-NEXT: imull %edx, %eax
765 ; X86-NEXT: addl %ecx, %eax
766 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
767 ; X86-NEXT: popl %esi
769 %t3 = icmp ugt i16 %a1, %a2
770 %t4 = select i1 %t3, i16 -1, i16 1
771 %t5 = select i1 %t3, i16 %a2, i16 %a1
772 %t6 = select i1 %t3, i16 %a1, i16 %a2
773 %t7 = sub i16 %t6, %t5
774 %t8 = lshr i16 %t7, 1
775 %t9 = mul i16 %t8, %t4
776 %a10 = add i16 %t9, %a1
780 ; Values are loaded. Only check signed case.
782 define i16 @scalar_i16_signed_mem_reg(ptr %a1_addr, i16 %a2) nounwind {
783 ; X64-LABEL: scalar_i16_signed_mem_reg:
785 ; X64-NEXT: movzwl (%rdi), %ecx
786 ; X64-NEXT: xorl %eax, %eax
787 ; X64-NEXT: cmpw %si, %cx
788 ; X64-NEXT: setle %al
789 ; X64-NEXT: leal -1(%rax,%rax), %edx
790 ; X64-NEXT: movl %ecx, %eax
791 ; X64-NEXT: cmovgl %esi, %eax
792 ; X64-NEXT: cmovgl %ecx, %esi
793 ; X64-NEXT: subl %eax, %esi
794 ; X64-NEXT: movzwl %si, %eax
795 ; X64-NEXT: shrl %eax
796 ; X64-NEXT: imull %edx, %eax
797 ; X64-NEXT: addl %ecx, %eax
798 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
801 ; X86-LABEL: scalar_i16_signed_mem_reg:
803 ; X86-NEXT: pushl %esi
804 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
805 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
806 ; X86-NEXT: movzwl (%ecx), %ecx
807 ; X86-NEXT: xorl %edx, %edx
808 ; X86-NEXT: cmpw %ax, %cx
809 ; X86-NEXT: setle %dl
810 ; X86-NEXT: leal -1(%edx,%edx), %edx
811 ; X86-NEXT: jg .LBB12_1
813 ; X86-NEXT: movl %ecx, %esi
814 ; X86-NEXT: jmp .LBB12_3
815 ; X86-NEXT: .LBB12_1:
816 ; X86-NEXT: movl %eax, %esi
817 ; X86-NEXT: movl %ecx, %eax
818 ; X86-NEXT: .LBB12_3:
819 ; X86-NEXT: subl %esi, %eax
820 ; X86-NEXT: movzwl %ax, %eax
821 ; X86-NEXT: shrl %eax
822 ; X86-NEXT: imull %edx, %eax
823 ; X86-NEXT: addl %ecx, %eax
824 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
825 ; X86-NEXT: popl %esi
827 %a1 = load i16, ptr %a1_addr
828 %t3 = icmp sgt i16 %a1, %a2 ; signed
829 %t4 = select i1 %t3, i16 -1, i16 1
830 %t5 = select i1 %t3, i16 %a2, i16 %a1
831 %t6 = select i1 %t3, i16 %a1, i16 %a2
832 %t7 = sub i16 %t6, %t5
833 %t8 = lshr i16 %t7, 1
834 %t9 = mul nsw i16 %t8, %t4 ; signed
835 %a10 = add nsw i16 %t9, %a1 ; signed
839 define i16 @scalar_i16_signed_reg_mem(i16 %a1, ptr %a2_addr) nounwind {
840 ; X64-LABEL: scalar_i16_signed_reg_mem:
842 ; X64-NEXT: movzwl (%rsi), %eax
843 ; X64-NEXT: xorl %ecx, %ecx
844 ; X64-NEXT: cmpw %ax, %di
845 ; X64-NEXT: setle %cl
846 ; X64-NEXT: leal -1(%rcx,%rcx), %ecx
847 ; X64-NEXT: movl %edi, %edx
848 ; X64-NEXT: cmovgl %eax, %edx
849 ; X64-NEXT: cmovgl %edi, %eax
850 ; X64-NEXT: subl %edx, %eax
851 ; X64-NEXT: movzwl %ax, %eax
852 ; X64-NEXT: shrl %eax
853 ; X64-NEXT: imull %ecx, %eax
854 ; X64-NEXT: addl %edi, %eax
855 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
858 ; X86-LABEL: scalar_i16_signed_reg_mem:
860 ; X86-NEXT: pushl %esi
861 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
862 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
863 ; X86-NEXT: movzwl (%eax), %eax
864 ; X86-NEXT: xorl %edx, %edx
865 ; X86-NEXT: cmpw %ax, %cx
866 ; X86-NEXT: setle %dl
867 ; X86-NEXT: leal -1(%edx,%edx), %edx
868 ; X86-NEXT: jg .LBB13_1
870 ; X86-NEXT: movl %ecx, %esi
871 ; X86-NEXT: jmp .LBB13_3
872 ; X86-NEXT: .LBB13_1:
873 ; X86-NEXT: movl %eax, %esi
874 ; X86-NEXT: movl %ecx, %eax
875 ; X86-NEXT: .LBB13_3:
876 ; X86-NEXT: subl %esi, %eax
877 ; X86-NEXT: movzwl %ax, %eax
878 ; X86-NEXT: shrl %eax
879 ; X86-NEXT: imull %edx, %eax
880 ; X86-NEXT: addl %ecx, %eax
881 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
882 ; X86-NEXT: popl %esi
884 %a2 = load i16, ptr %a2_addr
885 %t3 = icmp sgt i16 %a1, %a2 ; signed
886 %t4 = select i1 %t3, i16 -1, i16 1
887 %t5 = select i1 %t3, i16 %a2, i16 %a1
888 %t6 = select i1 %t3, i16 %a1, i16 %a2
889 %t7 = sub i16 %t6, %t5
890 %t8 = lshr i16 %t7, 1
891 %t9 = mul nsw i16 %t8, %t4 ; signed
892 %a10 = add nsw i16 %t9, %a1 ; signed
896 define i16 @scalar_i16_signed_mem_mem(ptr %a1_addr, ptr %a2_addr) nounwind {
897 ; X64-LABEL: scalar_i16_signed_mem_mem:
899 ; X64-NEXT: movzwl (%rdi), %ecx
900 ; X64-NEXT: movzwl (%rsi), %eax
901 ; X64-NEXT: xorl %edx, %edx
902 ; X64-NEXT: cmpw %ax, %cx
903 ; X64-NEXT: setle %dl
904 ; X64-NEXT: leal -1(%rdx,%rdx), %edx
905 ; X64-NEXT: movl %ecx, %esi
906 ; X64-NEXT: cmovgl %eax, %esi
907 ; X64-NEXT: cmovgl %ecx, %eax
908 ; X64-NEXT: subl %esi, %eax
909 ; X64-NEXT: movzwl %ax, %eax
910 ; X64-NEXT: shrl %eax
911 ; X64-NEXT: imull %edx, %eax
912 ; X64-NEXT: addl %ecx, %eax
913 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
916 ; X86-LABEL: scalar_i16_signed_mem_mem:
918 ; X86-NEXT: pushl %esi
919 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
920 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
921 ; X86-NEXT: movzwl (%ecx), %ecx
922 ; X86-NEXT: movzwl (%eax), %eax
923 ; X86-NEXT: xorl %edx, %edx
924 ; X86-NEXT: cmpw %ax, %cx
925 ; X86-NEXT: setle %dl
926 ; X86-NEXT: leal -1(%edx,%edx), %edx
927 ; X86-NEXT: jg .LBB14_1
929 ; X86-NEXT: movl %ecx, %esi
930 ; X86-NEXT: jmp .LBB14_3
931 ; X86-NEXT: .LBB14_1:
932 ; X86-NEXT: movl %eax, %esi
933 ; X86-NEXT: movl %ecx, %eax
934 ; X86-NEXT: .LBB14_3:
935 ; X86-NEXT: subl %esi, %eax
936 ; X86-NEXT: movzwl %ax, %eax
937 ; X86-NEXT: shrl %eax
938 ; X86-NEXT: imull %edx, %eax
939 ; X86-NEXT: addl %ecx, %eax
940 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
941 ; X86-NEXT: popl %esi
943 %a1 = load i16, ptr %a1_addr
944 %a2 = load i16, ptr %a2_addr
945 %t3 = icmp sgt i16 %a1, %a2 ; signed
946 %t4 = select i1 %t3, i16 -1, i16 1
947 %t5 = select i1 %t3, i16 %a2, i16 %a1
948 %t6 = select i1 %t3, i16 %a1, i16 %a2
949 %t7 = sub i16 %t6, %t5
950 %t8 = lshr i16 %t7, 1
951 %t9 = mul nsw i16 %t8, %t4 ; signed
952 %a10 = add nsw i16 %t9, %a1 ; signed
956 ; ---------------------------------------------------------------------------- ;
958 ; ---------------------------------------------------------------------------- ;
960 ; Values come from regs
962 define i8 @scalar_i8_signed_reg_reg(i8 %a1, i8 %a2) nounwind {
963 ; X64-LABEL: scalar_i8_signed_reg_reg:
965 ; X64-NEXT: movl %esi, %eax
966 ; X64-NEXT: cmpb %al, %dil
968 ; X64-NEXT: movl %edi, %edx
969 ; X64-NEXT: cmovgl %esi, %edx
970 ; X64-NEXT: cmovgl %edi, %eax
972 ; X64-NEXT: orb $1, %cl
973 ; X64-NEXT: subb %dl, %al
975 ; X64-NEXT: # kill: def $al killed $al killed $eax
977 ; X64-NEXT: addb %dil, %al
980 ; X86-LABEL: scalar_i8_signed_reg_reg:
982 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
983 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
984 ; X86-NEXT: cmpb %al, %cl
986 ; X86-NEXT: jg .LBB15_1
988 ; X86-NEXT: movb %cl, %ah
989 ; X86-NEXT: jmp .LBB15_3
990 ; X86-NEXT: .LBB15_1:
991 ; X86-NEXT: movb %al, %ah
992 ; X86-NEXT: movb %cl, %al
993 ; X86-NEXT: .LBB15_3:
994 ; X86-NEXT: subb %ah, %al
996 ; X86-NEXT: orb $1, %dl
999 ; X86-NEXT: addb %cl, %al
1001 %t3 = icmp sgt i8 %a1, %a2 ; signed
1002 %t4 = select i1 %t3, i8 -1, i8 1
1003 %t5 = select i1 %t3, i8 %a2, i8 %a1
1004 %t6 = select i1 %t3, i8 %a1, i8 %a2
1005 %t7 = sub i8 %t6, %t5
1006 %t8 = lshr i8 %t7, 1
1007 %t9 = mul nsw i8 %t8, %t4 ; signed
1008 %a10 = add nsw i8 %t9, %a1 ; signed
1012 define i8 @scalar_i8_unsigned_reg_reg(i8 %a1, i8 %a2) nounwind {
1013 ; X64-LABEL: scalar_i8_unsigned_reg_reg:
1015 ; X64-NEXT: movl %esi, %eax
1016 ; X64-NEXT: cmpb %al, %dil
1017 ; X64-NEXT: seta %cl
1018 ; X64-NEXT: movl %edi, %edx
1019 ; X64-NEXT: cmoval %esi, %edx
1020 ; X64-NEXT: cmoval %edi, %eax
1021 ; X64-NEXT: negb %cl
1022 ; X64-NEXT: orb $1, %cl
1023 ; X64-NEXT: subb %dl, %al
1024 ; X64-NEXT: shrb %al
1025 ; X64-NEXT: # kill: def $al killed $al killed $eax
1026 ; X64-NEXT: mulb %cl
1027 ; X64-NEXT: addb %dil, %al
1030 ; X86-LABEL: scalar_i8_unsigned_reg_reg:
1032 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
1033 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
1034 ; X86-NEXT: cmpb %al, %cl
1035 ; X86-NEXT: seta %dl
1036 ; X86-NEXT: ja .LBB16_1
1037 ; X86-NEXT: # %bb.2:
1038 ; X86-NEXT: movb %cl, %ah
1039 ; X86-NEXT: jmp .LBB16_3
1040 ; X86-NEXT: .LBB16_1:
1041 ; X86-NEXT: movb %al, %ah
1042 ; X86-NEXT: movb %cl, %al
1043 ; X86-NEXT: .LBB16_3:
1044 ; X86-NEXT: subb %ah, %al
1045 ; X86-NEXT: negb %dl
1046 ; X86-NEXT: orb $1, %dl
1047 ; X86-NEXT: shrb %al
1048 ; X86-NEXT: mulb %dl
1049 ; X86-NEXT: addb %cl, %al
1051 %t3 = icmp ugt i8 %a1, %a2
1052 %t4 = select i1 %t3, i8 -1, i8 1
1053 %t5 = select i1 %t3, i8 %a2, i8 %a1
1054 %t6 = select i1 %t3, i8 %a1, i8 %a2
1055 %t7 = sub i8 %t6, %t5
1056 %t8 = lshr i8 %t7, 1
1057 %t9 = mul i8 %t8, %t4
1058 %a10 = add i8 %t9, %a1
1062 ; Values are loaded. Only check signed case.
1064 define i8 @scalar_i8_signed_mem_reg(ptr %a1_addr, i8 %a2) nounwind {
1065 ; X64-LABEL: scalar_i8_signed_mem_reg:
1067 ; X64-NEXT: movzbl (%rdi), %ecx
1068 ; X64-NEXT: cmpb %sil, %cl
1069 ; X64-NEXT: setg %dl
1070 ; X64-NEXT: movl %ecx, %edi
1071 ; X64-NEXT: cmovgl %esi, %edi
1072 ; X64-NEXT: movl %ecx, %eax
1073 ; X64-NEXT: cmovlel %esi, %eax
1074 ; X64-NEXT: negb %dl
1075 ; X64-NEXT: orb $1, %dl
1076 ; X64-NEXT: subb %dil, %al
1077 ; X64-NEXT: shrb %al
1078 ; X64-NEXT: # kill: def $al killed $al killed $eax
1079 ; X64-NEXT: mulb %dl
1080 ; X64-NEXT: addb %cl, %al
1083 ; X86-LABEL: scalar_i8_signed_mem_reg:
1085 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
1086 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
1087 ; X86-NEXT: movzbl (%ecx), %ecx
1088 ; X86-NEXT: cmpb %al, %cl
1089 ; X86-NEXT: setg %dl
1090 ; X86-NEXT: jg .LBB17_1
1091 ; X86-NEXT: # %bb.2:
1092 ; X86-NEXT: movb %cl, %ah
1093 ; X86-NEXT: jmp .LBB17_3
1094 ; X86-NEXT: .LBB17_1:
1095 ; X86-NEXT: movb %al, %ah
1096 ; X86-NEXT: movb %cl, %al
1097 ; X86-NEXT: .LBB17_3:
1098 ; X86-NEXT: subb %ah, %al
1099 ; X86-NEXT: negb %dl
1100 ; X86-NEXT: orb $1, %dl
1101 ; X86-NEXT: shrb %al
1102 ; X86-NEXT: mulb %dl
1103 ; X86-NEXT: addb %cl, %al
1105 %a1 = load i8, ptr %a1_addr
1106 %t3 = icmp sgt i8 %a1, %a2 ; signed
1107 %t4 = select i1 %t3, i8 -1, i8 1
1108 %t5 = select i1 %t3, i8 %a2, i8 %a1
1109 %t6 = select i1 %t3, i8 %a1, i8 %a2
1110 %t7 = sub i8 %t6, %t5
1111 %t8 = lshr i8 %t7, 1
1112 %t9 = mul nsw i8 %t8, %t4 ; signed
1113 %a10 = add nsw i8 %t9, %a1 ; signed
1117 define i8 @scalar_i8_signed_reg_mem(i8 %a1, ptr %a2_addr) nounwind {
1118 ; X64-LABEL: scalar_i8_signed_reg_mem:
1120 ; X64-NEXT: movzbl (%rsi), %eax
1121 ; X64-NEXT: cmpb %al, %dil
1122 ; X64-NEXT: setg %cl
1123 ; X64-NEXT: movl %edi, %edx
1124 ; X64-NEXT: cmovgl %eax, %edx
1125 ; X64-NEXT: cmovgl %edi, %eax
1126 ; X64-NEXT: negb %cl
1127 ; X64-NEXT: orb $1, %cl
1128 ; X64-NEXT: subb %dl, %al
1129 ; X64-NEXT: shrb %al
1130 ; X64-NEXT: # kill: def $al killed $al killed $eax
1131 ; X64-NEXT: mulb %cl
1132 ; X64-NEXT: addb %dil, %al
1135 ; X86-LABEL: scalar_i8_signed_reg_mem:
1137 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
1138 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1139 ; X86-NEXT: movzbl (%eax), %eax
1140 ; X86-NEXT: cmpb %al, %cl
1141 ; X86-NEXT: setg %dl
1142 ; X86-NEXT: jg .LBB18_1
1143 ; X86-NEXT: # %bb.2:
1144 ; X86-NEXT: movb %cl, %ah
1145 ; X86-NEXT: jmp .LBB18_3
1146 ; X86-NEXT: .LBB18_1:
1147 ; X86-NEXT: movb %al, %ah
1148 ; X86-NEXT: movb %cl, %al
1149 ; X86-NEXT: .LBB18_3:
1150 ; X86-NEXT: subb %ah, %al
1151 ; X86-NEXT: negb %dl
1152 ; X86-NEXT: orb $1, %dl
1153 ; X86-NEXT: shrb %al
1154 ; X86-NEXT: mulb %dl
1155 ; X86-NEXT: addb %cl, %al
1157 %a2 = load i8, ptr %a2_addr
1158 %t3 = icmp sgt i8 %a1, %a2 ; signed
1159 %t4 = select i1 %t3, i8 -1, i8 1
1160 %t5 = select i1 %t3, i8 %a2, i8 %a1
1161 %t6 = select i1 %t3, i8 %a1, i8 %a2
1162 %t7 = sub i8 %t6, %t5
1163 %t8 = lshr i8 %t7, 1
1164 %t9 = mul nsw i8 %t8, %t4 ; signed
1165 %a10 = add nsw i8 %t9, %a1 ; signed
1169 define i8 @scalar_i8_signed_mem_mem(ptr %a1_addr, ptr %a2_addr) nounwind {
1170 ; X64-LABEL: scalar_i8_signed_mem_mem:
1172 ; X64-NEXT: movzbl (%rdi), %ecx
1173 ; X64-NEXT: movzbl (%rsi), %eax
1174 ; X64-NEXT: cmpb %al, %cl
1175 ; X64-NEXT: setg %dl
1176 ; X64-NEXT: movl %ecx, %esi
1177 ; X64-NEXT: cmovgl %eax, %esi
1178 ; X64-NEXT: cmovgl %ecx, %eax
1179 ; X64-NEXT: negb %dl
1180 ; X64-NEXT: orb $1, %dl
1181 ; X64-NEXT: subb %sil, %al
1182 ; X64-NEXT: shrb %al
1183 ; X64-NEXT: # kill: def $al killed $al killed $eax
1184 ; X64-NEXT: mulb %dl
1185 ; X64-NEXT: addb %cl, %al
1188 ; X86-LABEL: scalar_i8_signed_mem_mem:
1190 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1191 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
1192 ; X86-NEXT: movzbl (%ecx), %ecx
1193 ; X86-NEXT: movzbl (%eax), %eax
1194 ; X86-NEXT: cmpb %al, %cl
1195 ; X86-NEXT: setg %dl
1196 ; X86-NEXT: jg .LBB19_1
1197 ; X86-NEXT: # %bb.2:
1198 ; X86-NEXT: movb %cl, %ah
1199 ; X86-NEXT: jmp .LBB19_3
1200 ; X86-NEXT: .LBB19_1:
1201 ; X86-NEXT: movb %al, %ah
1202 ; X86-NEXT: movb %cl, %al
1203 ; X86-NEXT: .LBB19_3:
1204 ; X86-NEXT: subb %ah, %al
1205 ; X86-NEXT: negb %dl
1206 ; X86-NEXT: orb $1, %dl
1207 ; X86-NEXT: shrb %al
1208 ; X86-NEXT: mulb %dl
1209 ; X86-NEXT: addb %cl, %al
1211 %a1 = load i8, ptr %a1_addr
1212 %a2 = load i8, ptr %a2_addr
1213 %t3 = icmp sgt i8 %a1, %a2 ; signed
1214 %t4 = select i1 %t3, i8 -1, i8 1
1215 %t5 = select i1 %t3, i8 %a2, i8 %a1
1216 %t6 = select i1 %t3, i8 %a1, i8 %a2
1217 %t7 = sub i8 %t6, %t5
1218 %t8 = lshr i8 %t7, 1
1219 %t9 = mul nsw i8 %t8, %t4 ; signed
1220 %a10 = add nsw i8 %t9, %a1 ; signed