[PowerPC] Recommit r314244 with refactoring and off by default
[llvm-core.git] / test / CodeGen / X86 / iabs.ll
blob952c31c7814bbd3e563e93d35f9579f6f841146a
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:
7 ;;       movl   %edi, %eax
8 ;;       negl   %eax
9 ;;       cmovll %edi, %eax
10 ;;       ret
11 ; rdar://10695237
12 define i8 @test_i8(i8 %a) nounwind {
13 ; X86-LABEL: test_i8:
14 ; X86:       # BB#0:
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
20 ; X86-NEXT:    retl
22 ; X64-LABEL: test_i8:
23 ; X64:       # BB#0:
24 ; X64-NEXT:    movl %edi, %eax
25 ; X64-NEXT:    sarb $7, %al
26 ; X64-NEXT:    addb %al, %dil
27 ; X64-NEXT:    xorb %al, %dil
28 ; X64-NEXT:    movl %edi, %eax
29 ; X64-NEXT:    retq
30   %tmp1neg = sub i8 0, %a
31   %b = icmp sgt i8 %a, -1
32   %abs = select i1 %b, i8 %a, i8 %tmp1neg
33   ret i8 %abs
36 define i16 @test_i16(i16 %a) nounwind {
37 ; X86-NO-CMOV-LABEL: test_i16:
38 ; X86-NO-CMOV:       # BB#0:
39 ; X86-NO-CMOV-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
40 ; X86-NO-CMOV-NEXT:    movl %eax, %ecx
41 ; X86-NO-CMOV-NEXT:    sarw $15, %cx
42 ; X86-NO-CMOV-NEXT:    addl %ecx, %eax
43 ; X86-NO-CMOV-NEXT:    xorl %ecx, %eax
44 ; X86-NO-CMOV-NEXT:    # kill: %ax<def> %ax<kill> %eax<kill>
45 ; X86-NO-CMOV-NEXT:    retl
47 ; X86-CMOV-LABEL: test_i16:
48 ; X86-CMOV:       # BB#0:
49 ; X86-CMOV-NEXT:    movzwl {{[0-9]+}}(%esp), %ecx
50 ; X86-CMOV-NEXT:    movl %ecx, %eax
51 ; X86-CMOV-NEXT:    negw %ax
52 ; X86-CMOV-NEXT:    cmovlw %cx, %ax
53 ; X86-CMOV-NEXT:    retl
55 ; X64-LABEL: test_i16:
56 ; X64:       # BB#0:
57 ; X64-NEXT:    movl %edi, %eax
58 ; X64-NEXT:    negw %ax
59 ; X64-NEXT:    cmovlw %di, %ax
60 ; X64-NEXT:    retq
61   %tmp1neg = sub i16 0, %a
62   %b = icmp sgt i16 %a, -1
63   %abs = select i1 %b, i16 %a, i16 %tmp1neg
64   ret i16 %abs
67 define i32 @test_i32(i32 %a) nounwind {
68 ; X86-NO-CMOV-LABEL: test_i32:
69 ; X86-NO-CMOV:       # BB#0:
70 ; X86-NO-CMOV-NEXT:    movl {{[0-9]+}}(%esp), %eax
71 ; X86-NO-CMOV-NEXT:    movl %eax, %ecx
72 ; X86-NO-CMOV-NEXT:    sarl $31, %ecx
73 ; X86-NO-CMOV-NEXT:    addl %ecx, %eax
74 ; X86-NO-CMOV-NEXT:    xorl %ecx, %eax
75 ; X86-NO-CMOV-NEXT:    retl
77 ; X86-CMOV-LABEL: test_i32:
78 ; X86-CMOV:       # BB#0:
79 ; X86-CMOV-NEXT:    movl {{[0-9]+}}(%esp), %ecx
80 ; X86-CMOV-NEXT:    movl %ecx, %eax
81 ; X86-CMOV-NEXT:    negl %eax
82 ; X86-CMOV-NEXT:    cmovll %ecx, %eax
83 ; X86-CMOV-NEXT:    retl
85 ; X64-LABEL: test_i32:
86 ; X64:       # BB#0:
87 ; X64-NEXT:    movl %edi, %eax
88 ; X64-NEXT:    negl %eax
89 ; X64-NEXT:    cmovll %edi, %eax
90 ; X64-NEXT:    retq
91   %tmp1neg = sub i32 0, %a
92   %b = icmp sgt i32 %a, -1
93   %abs = select i1 %b, i32 %a, i32 %tmp1neg
94   ret i32 %abs
97 define i64 @test_i64(i64 %a) nounwind {
98 ; X86-LABEL: test_i64:
99 ; X86:       # BB#0:
100 ; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
101 ; X86-NEXT:    movl %edx, %ecx
102 ; X86-NEXT:    sarl $31, %ecx
103 ; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
104 ; X86-NEXT:    addl %ecx, %eax
105 ; X86-NEXT:    adcl %ecx, %edx
106 ; X86-NEXT:    xorl %ecx, %edx
107 ; X86-NEXT:    xorl %ecx, %eax
108 ; X86-NEXT:    retl
110 ; X64-LABEL: test_i64:
111 ; X64:       # BB#0:
112 ; X64-NEXT:    movq %rdi, %rax
113 ; X64-NEXT:    negq %rax
114 ; X64-NEXT:    cmovlq %rdi, %rax
115 ; X64-NEXT:    retq
116   %tmp1neg = sub i64 0, %a
117   %b = icmp sgt i64 %a, -1
118   %abs = select i1 %b, i64 %a, i64 %tmp1neg
119   ret i64 %abs