xref: /llvm-project/llvm/test/CodeGen/X86/GlobalISel/add-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_add_i128(i128 %arg1, i128 %arg2) nounwind {
6; X64-LABEL: test_add_i128:
7; X64:       # %bb.0:
8; X64-NEXT:    movq %rdx, %rax
9; X64-NEXT:    addq %rdi, %rax
10; X64-NEXT:    adcq %rsi, %rcx
11; X64-NEXT:    movq %rcx, %rdx
12; X64-NEXT:    retq
13;
14; X86-LABEL: test_add_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:    addl {{[0-9]+}}(%esp), %ecx
24; X86-NEXT:    adcl {{[0-9]+}}(%esp), %edx
25; X86-NEXT:    adcl {{[0-9]+}}(%esp), %esi
26; X86-NEXT:    adcl {{[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 = add i128 %arg1, %arg2
35  ret i128 %ret
36}
37
38define i64 @test_add_i64(i64 %arg1, i64 %arg2) {
39; X64-LABEL: test_add_i64:
40; X64:       # %bb.0:
41; X64-NEXT:    leaq (%rsi,%rdi), %rax
42; X64-NEXT:    retq
43;
44; X86-LABEL: test_add_i64:
45; X86:       # %bb.0:
46; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
47; X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
48; X86-NEXT:    addl {{[0-9]+}}(%esp), %eax
49; X86-NEXT:    adcl {{[0-9]+}}(%esp), %edx
50; X86-NEXT:    retl
51  %ret = add i64 %arg1, %arg2
52  ret i64 %ret
53}
54
55define i32 @test_add_i32(i32 %arg1, i32 %arg2) {
56; X64-LABEL: test_add_i32:
57; X64:       # %bb.0:
58; X64-NEXT:    # kill: def $edi killed $edi def $rdi
59; X64-NEXT:    # kill: def $esi killed $esi def $rsi
60; X64-NEXT:    leal (%rsi,%rdi), %eax
61; X64-NEXT:    retq
62;
63; X86-LABEL: test_add_i32:
64; X86:       # %bb.0:
65; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
66; X86-NEXT:    addl {{[0-9]+}}(%esp), %eax
67; X86-NEXT:    retl
68  %ret = add i32 %arg1, %arg2
69  ret i32 %ret
70}
71
72define i16 @test_add_i16(i16 %arg1, i16 %arg2) {
73; X64-LABEL: test_add_i16:
74; X64:       # %bb.0:
75; X64-NEXT:    # kill: def $edi killed $edi def $rdi
76; X64-NEXT:    # kill: def $esi killed $esi def $rsi
77; X64-NEXT:    leal (%rsi,%rdi), %eax
78; X64-NEXT:    # kill: def $ax killed $ax killed $eax
79; X64-NEXT:    retq
80;
81; X86-LABEL: test_add_i16:
82; X86:       # %bb.0:
83; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
84; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
85; X86-NEXT:    addw %cx, %ax
86; X86-NEXT:    # kill: def $ax killed $ax killed $eax
87; X86-NEXT:    retl
88  %ret = add i16 %arg1, %arg2
89  ret i16 %ret
90}
91
92define i8 @test_add_i8(i8 %arg1, i8 %arg2) {
93; X64-LABEL: test_add_i8:
94; X64:       # %bb.0:
95; X64-NEXT:    # kill: def $edi killed $edi def $rdi
96; X64-NEXT:    # kill: def $esi killed $esi def $rsi
97; X64-NEXT:    leal (%rsi,%rdi), %eax
98; X64-NEXT:    # kill: def $al killed $al killed $eax
99; X64-NEXT:    retq
100;
101; X86-LABEL: test_add_i8:
102; X86:       # %bb.0:
103; X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
104; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
105; X86-NEXT:    addb %cl, %al
106; X86-NEXT:    # kill: def $al killed $al killed $eax
107; X86-NEXT:    retl
108  %ret = add i8 %arg1, %arg2
109  ret i8 %ret
110}
111
112define i32 @test_add_i1(i32 %arg1, i32 %arg2) {
113; X64-LABEL: test_add_i1:
114; X64:       # %bb.0:
115; X64-NEXT:    cmpl %esi, %edi
116; X64-NEXT:    sete %al
117; X64-NEXT:    addb %al, %al
118; X64-NEXT:    movzbl %al, %eax
119; X64-NEXT:    andl $1, %eax
120; X64-NEXT:    retq
121;
122; X86-LABEL: test_add_i1:
123; X86:       # %bb.0:
124; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
125; X86-NEXT:    cmpl %eax, {{[0-9]+}}(%esp)
126; X86-NEXT:    sete %al
127; X86-NEXT:    addb %al, %al
128; X86-NEXT:    movzbl %al, %eax
129; X86-NEXT:    andl $1, %eax
130; X86-NEXT:    retl
131  %c = icmp eq i32 %arg1, %arg2
132  %x = add i1 %c , %c
133  %ret = zext i1 %x to i32
134  ret i32 %ret
135}
136