xref: /llvm-project/llvm/test/CodeGen/X86/GlobalISel/sub-scalar.ll (revision 0342aefa32efe91780c9c39c17e8c68c2684d26f)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -mtriple=x86_64-linux-gnu -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=X64
3; RUN: llc -mtriple=i386-linux-gnu   -global-isel -verify-machineinstrs < %s -o - | FileCheck %s --check-prefix=X86
4
5define i128 @test_sub_i128(i128 %arg1, i128 %arg2) nounwind {
6; X64-LABEL: test_sub_i128:
7; X64:       # %bb.0:
8; X64-NEXT:    movq %rdi, %rax
9; X64-NEXT:    subq %rdx, %rax
10; X64-NEXT:    sbbq %rcx, %rsi
11; X64-NEXT:    movq %rsi, %rdx
12; X64-NEXT:    retq
13;
14; X86-LABEL: test_sub_i128:
15; X86:       # %bb.0:
16; X86-NEXT:    pushl %edi
17; X86-NEXT:    pushl %esi
18; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
19; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
20; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
21; X86-NEXT:    movl {{[0-9]+}}(%esp), %esi
22; X86-NEXT:    movl {{[0-9]+}}(%esp), %edi
23; X86-NEXT:    subl {{[0-9]+}}(%esp), %ecx
24; X86-NEXT:    sbbl {{[0-9]+}}(%esp), %edx
25; X86-NEXT:    sbbl {{[0-9]+}}(%esp), %esi
26; X86-NEXT:    sbbl {{[0-9]+}}(%esp), %edi
27; X86-NEXT:    movl %ecx, (%eax)
28; X86-NEXT:    movl %edx, 4(%eax)
29; X86-NEXT:    movl %esi, 8(%eax)
30; X86-NEXT:    movl %edi, 12(%eax)
31; X86-NEXT:    popl %esi
32; X86-NEXT:    popl %edi
33; X86-NEXT:    retl
34  %ret = sub i128 %arg1, %arg2
35  ret i128 %ret
36}
37
38define i64 @test_sub_i64(i64 %arg1, i64 %arg2) {
39; X64-LABEL: test_sub_i64:
40; X64:       # %bb.0:
41; X64-NEXT:    movq %rdi, %rax
42; X64-NEXT:    subq %rsi, %rax
43; X64-NEXT:    retq
44;
45; X86-LABEL: test_sub_i64:
46; X86:       # %bb.0:
47; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
48; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
49; X86-NEXT:    subl {{[0-9]+}}(%esp), %eax
50; X86-NEXT:    sbbl {{[0-9]+}}(%esp), %edx
51; X86-NEXT:    retl
52  %ret = sub i64 %arg1, %arg2
53  ret i64 %ret
54}
55
56define i32 @test_sub_i32(i32 %arg1, i32 %arg2) {
57; X64-LABEL: test_sub_i32:
58; X64:       # %bb.0:
59; X64-NEXT:    movl %edi, %eax
60; X64-NEXT:    subl %esi, %eax
61; X64-NEXT:    retq
62;
63; X86-LABEL: test_sub_i32:
64; X86:       # %bb.0:
65; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
66; X86-NEXT:    subl {{[0-9]+}}(%esp), %eax
67; X86-NEXT:    retl
68  %ret = sub i32 %arg1, %arg2
69  ret i32 %ret
70}
71
72define i16 @test_sub_i16(i16 %arg1, i16 %arg2) {
73; X64-LABEL: test_sub_i16:
74; X64:       # %bb.0:
75; X64-NEXT:    movl %edi, %eax
76; X64-NEXT:    subw %si, %ax
77; X64-NEXT:    # kill: def $ax killed $ax killed $eax
78; X64-NEXT:    retq
79;
80; X86-LABEL: test_sub_i16:
81; X86:       # %bb.0:
82; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
83; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
84; X86-NEXT:    subw %cx, %ax
85; X86-NEXT:    # kill: def $ax killed $ax killed $eax
86; X86-NEXT:    retl
87  %ret = sub i16 %arg1, %arg2
88  ret i16 %ret
89}
90
91define i8 @test_sub_i8(i8 %arg1, i8 %arg2) {
92; X64-LABEL: test_sub_i8:
93; X64:       # %bb.0:
94; X64-NEXT:    movl %edi, %eax
95; X64-NEXT:    subb %sil, %al
96; X64-NEXT:    # kill: def $al killed $al killed $eax
97; X64-NEXT:    retq
98;
99; X86-LABEL: test_sub_i8:
100; X86:       # %bb.0:
101; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
102; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
103; X86-NEXT:    subb %cl, %al
104; X86-NEXT:    # kill: def $al killed $al killed $eax
105; X86-NEXT:    retl
106  %ret = sub i8 %arg1, %arg2
107  ret i8 %ret
108}
109
110define i32 @test_sub_i1(i32 %arg1, i32 %arg2) {
111; X64-LABEL: test_sub_i1:
112; X64:       # %bb.0:
113; X64-NEXT:    cmpl %esi, %edi
114; X64-NEXT:    sete %al
115; X64-NEXT:    subb %al, %al
116; X64-NEXT:    movzbl %al, %eax
117; X64-NEXT:    andl $1, %eax
118; X64-NEXT:    retq
119;
120; X86-LABEL: test_sub_i1:
121; X86:       # %bb.0:
122; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
123; X86-NEXT:    cmpl %eax, {{[0-9]+}}(%esp)
124; X86-NEXT:    sete %al
125; X86-NEXT:    subb %al, %al
126; X86-NEXT:    movzbl %al, %eax
127; X86-NEXT:    andl $1, %eax
128; X86-NEXT:    retl
129  %c = icmp eq i32 %arg1, %arg2
130  %x = sub i1 %c , %c
131  %ret = zext i1 %x to i32
132  ret i32 %ret
133}
134