1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86 --check-prefix=X86-NO-CMOV
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+cmov | FileCheck %s --check-prefix=X86 --check-prefix=X86-CMOV
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64
6 ;; Integer absolute value, should produce something at least as good as:
12 define i8 @test_i8(i8 %a) nounwind {
15 ; X86-NEXT: movb {{[0-9]+}}(%esp), %al
16 ; X86-NEXT: movl %eax, %ecx
17 ; X86-NEXT: sarb $7, %cl
18 ; X86-NEXT: addb %cl, %al
19 ; X86-NEXT: xorb %cl, %al
24 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
25 ; X64-NEXT: movl %edi, %ecx
26 ; X64-NEXT: sarb $7, %cl
27 ; X64-NEXT: leal (%rdi,%rcx), %eax
28 ; X64-NEXT: xorb %cl, %al
29 ; X64-NEXT: # kill: def $al killed $al killed $eax
31 %tmp1neg = sub i8 0, %a
32 %b = icmp sgt i8 %a, -1
33 %abs = select i1 %b, i8 %a, i8 %tmp1neg
37 define i16 @test_i16(i16 %a) nounwind {
38 ; X86-NO-CMOV-LABEL: test_i16:
39 ; X86-NO-CMOV: # %bb.0:
40 ; X86-NO-CMOV-NEXT: movswl {{[0-9]+}}(%esp), %eax
41 ; X86-NO-CMOV-NEXT: movl %eax, %ecx
42 ; X86-NO-CMOV-NEXT: sarl $15, %ecx
43 ; X86-NO-CMOV-NEXT: addl %ecx, %eax
44 ; X86-NO-CMOV-NEXT: xorl %ecx, %eax
45 ; X86-NO-CMOV-NEXT: # kill: def $ax killed $ax killed $eax
46 ; X86-NO-CMOV-NEXT: retl
48 ; X86-CMOV-LABEL: test_i16:
50 ; X86-CMOV-NEXT: movzwl {{[0-9]+}}(%esp), %ecx
51 ; X86-CMOV-NEXT: movl %ecx, %eax
52 ; X86-CMOV-NEXT: negw %ax
53 ; X86-CMOV-NEXT: cmovlw %cx, %ax
56 ; X64-LABEL: test_i16:
58 ; X64-NEXT: movl %edi, %eax
60 ; X64-NEXT: cmovlw %di, %ax
62 %tmp1neg = sub i16 0, %a
63 %b = icmp sgt i16 %a, -1
64 %abs = select i1 %b, i16 %a, i16 %tmp1neg
68 define i32 @test_i32(i32 %a) nounwind {
69 ; X86-NO-CMOV-LABEL: test_i32:
70 ; X86-NO-CMOV: # %bb.0:
71 ; X86-NO-CMOV-NEXT: movl {{[0-9]+}}(%esp), %eax
72 ; X86-NO-CMOV-NEXT: movl %eax, %ecx
73 ; X86-NO-CMOV-NEXT: sarl $31, %ecx
74 ; X86-NO-CMOV-NEXT: addl %ecx, %eax
75 ; X86-NO-CMOV-NEXT: xorl %ecx, %eax
76 ; X86-NO-CMOV-NEXT: retl
78 ; X86-CMOV-LABEL: test_i32:
80 ; X86-CMOV-NEXT: movl {{[0-9]+}}(%esp), %ecx
81 ; X86-CMOV-NEXT: movl %ecx, %eax
82 ; X86-CMOV-NEXT: negl %eax
83 ; X86-CMOV-NEXT: cmovll %ecx, %eax
86 ; X64-LABEL: test_i32:
88 ; X64-NEXT: movl %edi, %eax
90 ; X64-NEXT: cmovll %edi, %eax
92 %tmp1neg = sub i32 0, %a
93 %b = icmp sgt i32 %a, -1
94 %abs = select i1 %b, i32 %a, i32 %tmp1neg
98 define i64 @test_i64(i64 %a) nounwind {
99 ; X86-LABEL: test_i64:
101 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
102 ; X86-NEXT: movl %edx, %ecx
103 ; X86-NEXT: sarl $31, %ecx
104 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
105 ; X86-NEXT: addl %ecx, %eax
106 ; X86-NEXT: adcl %ecx, %edx
107 ; X86-NEXT: xorl %ecx, %edx
108 ; X86-NEXT: xorl %ecx, %eax
111 ; X64-LABEL: test_i64:
113 ; X64-NEXT: movq %rdi, %rax
114 ; X64-NEXT: negq %rax
115 ; X64-NEXT: cmovlq %rdi, %rax
117 %tmp1neg = sub i64 0, %a
118 %b = icmp sgt i64 %a, -1
119 %abs = select i1 %b, i64 %a, i64 %tmp1neg