1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=i686 -mattr=cmov | FileCheck %s --check-prefix=X86
3; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s --check-prefix=X64
4
5declare i4 @llvm.ssub.sat.i4(i4, i4)
6declare i8 @llvm.ssub.sat.i8(i8, i8)
7declare i16 @llvm.ssub.sat.i16(i16, i16)
8declare i32 @llvm.ssub.sat.i32(i32, i32)
9declare i64 @llvm.ssub.sat.i64(i64, i64)
10
11define i32 @func32(i32 %x, i32 %y, i32 %z) nounwind {
12; X86-LABEL: func32:
13; X86:       # %bb.0:
14; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
15; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
16; X86-NEXT:    imull {{[0-9]+}}(%esp), %edx
17; X86-NEXT:    xorl %ecx, %ecx
18; X86-NEXT:    cmpl %edx, %eax
19; X86-NEXT:    setns %cl
20; X86-NEXT:    addl $2147483647, %ecx # imm = 0x7FFFFFFF
21; X86-NEXT:    subl %edx, %eax
22; X86-NEXT:    cmovol %ecx, %eax
23; X86-NEXT:    retl
24;
25; X64-LABEL: func32:
26; X64:       # %bb.0:
27; X64-NEXT:    imull %edx, %esi
28; X64-NEXT:    xorl %eax, %eax
29; X64-NEXT:    cmpl %esi, %edi
30; X64-NEXT:    setns %al
31; X64-NEXT:    addl $2147483647, %eax # imm = 0x7FFFFFFF
32; X64-NEXT:    subl %esi, %edi
33; X64-NEXT:    cmovnol %edi, %eax
34; X64-NEXT:    retq
35  %a = mul i32 %y, %z
36  %tmp = call i32 @llvm.ssub.sat.i32(i32 %x, i32 %a)
37  ret i32 %tmp
38}
39
40define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
41; X86-LABEL: func64:
42; X86:       # %bb.0:
43; X86-NEXT:    pushl %ebx
44; X86-NEXT:    pushl %esi
45; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
46; X86-NEXT:    movl {{[0-9]+}}(%esp), %esi
47; X86-NEXT:    subl {{[0-9]+}}(%esp), %ecx
48; X86-NEXT:    sbbl {{[0-9]+}}(%esp), %esi
49; X86-NEXT:    seto %bl
50; X86-NEXT:    movl %esi, %eax
51; X86-NEXT:    sarl $31, %eax
52; X86-NEXT:    testb %bl, %bl
53; X86-NEXT:    cmovel %ecx, %eax
54; X86-NEXT:    xorl %edx, %edx
55; X86-NEXT:    testl %esi, %esi
56; X86-NEXT:    setns %dl
57; X86-NEXT:    addl $2147483647, %edx # imm = 0x7FFFFFFF
58; X86-NEXT:    testb %bl, %bl
59; X86-NEXT:    cmovel %esi, %edx
60; X86-NEXT:    popl %esi
61; X86-NEXT:    popl %ebx
62; X86-NEXT:    retl
63;
64; X64-LABEL: func64:
65; X64:       # %bb.0:
66; X64-NEXT:    xorl %ecx, %ecx
67; X64-NEXT:    cmpq %rdx, %rdi
68; X64-NEXT:    setns %cl
69; X64-NEXT:    movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
70; X64-NEXT:    addq %rcx, %rax
71; X64-NEXT:    subq %rdx, %rdi
72; X64-NEXT:    cmovnoq %rdi, %rax
73; X64-NEXT:    retq
74  %a = mul i64 %y, %z
75  %tmp = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %z)
76  ret i64 %tmp
77}
78
79define signext i16 @func16(i16 signext %x, i16 signext %y, i16 signext %z) nounwind {
80; X86-LABEL: func16:
81; X86:       # %bb.0:
82; X86-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
83; X86-NEXT:    movzwl {{[0-9]+}}(%esp), %edx
84; X86-NEXT:    imulw {{[0-9]+}}(%esp), %dx
85; X86-NEXT:    xorl %ecx, %ecx
86; X86-NEXT:    cmpw %dx, %ax
87; X86-NEXT:    setns %cl
88; X86-NEXT:    addl $32767, %ecx # imm = 0x7FFF
89; X86-NEXT:    subw %dx, %ax
90; X86-NEXT:    cmovol %ecx, %eax
91; X86-NEXT:    # kill: def $ax killed $ax killed $eax
92; X86-NEXT:    retl
93;
94; X64-LABEL: func16:
95; X64:       # %bb.0:
96; X64-NEXT:    imull %edx, %esi
97; X64-NEXT:    xorl %eax, %eax
98; X64-NEXT:    cmpw %si, %di
99; X64-NEXT:    setns %al
100; X64-NEXT:    addl $32767, %eax # imm = 0x7FFF
101; X64-NEXT:    subw %si, %di
102; X64-NEXT:    cmovnol %edi, %eax
103; X64-NEXT:    # kill: def $ax killed $ax killed $eax
104; X64-NEXT:    retq
105  %a = mul i16 %y, %z
106  %tmp = call i16 @llvm.ssub.sat.i16(i16 %x, i16 %a)
107  ret i16 %tmp
108}
109
110define signext i8 @func8(i8 signext %x, i8 signext %y, i8 signext %z) nounwind {
111; X86-LABEL: func8:
112; X86:       # %bb.0:
113; X86-NEXT:    movb {{[0-9]+}}(%esp), %dl
114; X86-NEXT:    movb {{[0-9]+}}(%esp), %al
115; X86-NEXT:    mulb {{[0-9]+}}(%esp)
116; X86-NEXT:    xorl %ecx, %ecx
117; X86-NEXT:    cmpb %al, %dl
118; X86-NEXT:    setns %cl
119; X86-NEXT:    addl $127, %ecx
120; X86-NEXT:    subb %al, %dl
121; X86-NEXT:    movzbl %dl, %eax
122; X86-NEXT:    cmovol %ecx, %eax
123; X86-NEXT:    # kill: def $al killed $al killed $eax
124; X86-NEXT:    retl
125;
126; X64-LABEL: func8:
127; X64:       # %bb.0:
128; X64-NEXT:    movl %esi, %eax
129; X64-NEXT:    # kill: def $al killed $al killed $eax
130; X64-NEXT:    mulb %dl
131; X64-NEXT:    xorl %ecx, %ecx
132; X64-NEXT:    cmpb %al, %dil
133; X64-NEXT:    setns %cl
134; X64-NEXT:    addl $127, %ecx
135; X64-NEXT:    subb %al, %dil
136; X64-NEXT:    movzbl %dil, %eax
137; X64-NEXT:    cmovol %ecx, %eax
138; X64-NEXT:    # kill: def $al killed $al killed $eax
139; X64-NEXT:    retq
140  %a = mul i8 %y, %z
141  %tmp = call i8 @llvm.ssub.sat.i8(i8 %x, i8 %a)
142  ret i8 %tmp
143}
144
145define signext i4 @func4(i4 signext %x, i4 signext %y, i4 signext %z) nounwind {
146; X86-LABEL: func4:
147; X86:       # %bb.0:
148; X86-NEXT:    movb {{[0-9]+}}(%esp), %cl
149; X86-NEXT:    movb {{[0-9]+}}(%esp), %al
150; X86-NEXT:    mulb {{[0-9]+}}(%esp)
151; X86-NEXT:    shlb $4, %al
152; X86-NEXT:    sarb $4, %al
153; X86-NEXT:    subb %al, %cl
154; X86-NEXT:    movzbl %cl, %eax
155; X86-NEXT:    cmpb $7, %cl
156; X86-NEXT:    movl $7, %ecx
157; X86-NEXT:    cmovll %eax, %ecx
158; X86-NEXT:    cmpb $-8, %cl
159; X86-NEXT:    movl $248, %eax
160; X86-NEXT:    cmovgl %ecx, %eax
161; X86-NEXT:    movsbl %al, %eax
162; X86-NEXT:    retl
163;
164; X64-LABEL: func4:
165; X64:       # %bb.0:
166; X64-NEXT:    movl %esi, %eax
167; X64-NEXT:    # kill: def $al killed $al killed $eax
168; X64-NEXT:    mulb %dl
169; X64-NEXT:    shlb $4, %al
170; X64-NEXT:    sarb $4, %al
171; X64-NEXT:    subb %al, %dil
172; X64-NEXT:    movzbl %dil, %eax
173; X64-NEXT:    cmpb $7, %al
174; X64-NEXT:    movl $7, %ecx
175; X64-NEXT:    cmovll %eax, %ecx
176; X64-NEXT:    cmpb $-8, %cl
177; X64-NEXT:    movl $248, %eax
178; X64-NEXT:    cmovgl %ecx, %eax
179; X64-NEXT:    movsbl %al, %eax
180; X64-NEXT:    retq
181  %a = mul i4 %y, %z
182  %tmp = call i4 @llvm.ssub.sat.i4(i4 %x, i4 %a)
183  ret i4 %tmp
184}
185