xref: /llvm-project/llvm/test/CodeGen/X86/isel-sdiv.ll (revision 10edabbcf331fdd53d27c5195de1b692a0063721)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -global-isel=0                    -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefixes=X64
3; RUN: llc < %s -fast-isel -fast-isel-abort=1     -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefixes=X64
4; RUN: llc < %s -global-isel -global-isel-abort=1 -mtriple=x86_64-linux-gnu | FileCheck %s --check-prefixes=X64
5; RUN: llc < %s -global-isel=0                    -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86,DAG-X86
6; RUN: llc < %s -fast-isel -fast-isel-abort=1     -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86,DAG-X86
7; RUN: llc < %s -global-isel -global-isel-abort=1 -mtriple=i686-linux-gnu | FileCheck %s --check-prefixes=X86,GISEL-X86
8
9define i8 @test_sdiv_i8(i8 %arg1, i8 %arg2) nounwind {
10; X64-LABEL: test_sdiv_i8:
11; X64:       # %bb.0:
12; X64-NEXT:    movsbl %dil, %eax
13; X64-NEXT:    idivb %sil
14; X64-NEXT:    retq
15;
16; DAG-X86-LABEL: test_sdiv_i8:
17; DAG-X86:       # %bb.0:
18; DAG-X86-NEXT:    movsbl {{[0-9]+}}(%esp), %eax
19; DAG-X86-NEXT:    idivb {{[0-9]+}}(%esp)
20; DAG-X86-NEXT:    retl
21;
22; GISEL-X86-LABEL: test_sdiv_i8:
23; GISEL-X86:       # %bb.0:
24; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
25; GISEL-X86-NEXT:    cbtw
26; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
27; GISEL-X86-NEXT:    idivb %cl
28; GISEL-X86-NEXT:    retl
29  %ret = sdiv i8 %arg1, %arg2
30  ret i8 %ret
31}
32
33define i16 @test_sdiv_i16(i16 %arg1, i16 %arg2) nounwind {
34; X64-LABEL: test_sdiv_i16:
35; X64:       # %bb.0:
36; X64-NEXT:    movl %edi, %eax
37; X64-NEXT:    # kill: def $ax killed $ax killed $eax
38; X64-NEXT:    cwtd
39; X64-NEXT:    idivw %si
40; X64-NEXT:    retq
41;
42; DAG-X86-LABEL: test_sdiv_i16:
43; DAG-X86:       # %bb.0:
44; DAG-X86-NEXT:    movzwl {{[0-9]+}}(%esp), %eax
45; DAG-X86-NEXT:    cwtd
46; DAG-X86-NEXT:    idivw {{[0-9]+}}(%esp)
47; DAG-X86-NEXT:    retl
48;
49; GISEL-X86-LABEL: test_sdiv_i16:
50; GISEL-X86:       # %bb.0:
51; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
52; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
53; GISEL-X86-NEXT:    # kill: def $ax killed $ax killed $eax
54; GISEL-X86-NEXT:    cwtd
55; GISEL-X86-NEXT:    idivw %cx
56; GISEL-X86-NEXT:    retl
57  %ret = sdiv i16 %arg1, %arg2
58  ret i16 %ret
59}
60
61define i32 @test_sdiv_i32(i32 %arg1, i32 %arg2) nounwind {
62; X64-LABEL: test_sdiv_i32:
63; X64:       # %bb.0:
64; X64-NEXT:    movl %edi, %eax
65; X64-NEXT:    cltd
66; X64-NEXT:    idivl %esi
67; X64-NEXT:    retq
68;
69; X86-LABEL: test_sdiv_i32:
70; X86:       # %bb.0:
71; X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
72; X86-NEXT:    cltd
73; X86-NEXT:    idivl {{[0-9]+}}(%esp)
74; X86-NEXT:    retl
75  %ret = sdiv i32 %arg1, %arg2
76  ret i32 %ret
77}
78
79define i64 @test_sdiv_i64(i64 %arg1, i64 %arg2) nounwind {
80; X64-LABEL: test_sdiv_i64:
81; X64:       # %bb.0:
82; X64-NEXT:    movq %rdi, %rax
83; X64-NEXT:    cqto
84; X64-NEXT:    idivq %rsi
85; X64-NEXT:    retq
86;
87; DAG-X86-LABEL: test_sdiv_i64:
88; DAG-X86:       # %bb.0:
89; DAG-X86-NEXT:    subl $12, %esp
90; DAG-X86-NEXT:    pushl {{[0-9]+}}(%esp)
91; DAG-X86-NEXT:    pushl {{[0-9]+}}(%esp)
92; DAG-X86-NEXT:    pushl {{[0-9]+}}(%esp)
93; DAG-X86-NEXT:    pushl {{[0-9]+}}(%esp)
94; DAG-X86-NEXT:    calll __divdi3
95; DAG-X86-NEXT:    addl $28, %esp
96; DAG-X86-NEXT:    retl
97;
98; GISEL-X86-LABEL: test_sdiv_i64:
99; GISEL-X86:       # %bb.0:
100; GISEL-X86-NEXT:    pushl %esi
101; GISEL-X86-NEXT:    subl $24, %esp
102; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %eax
103; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %ecx
104; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %edx
105; GISEL-X86-NEXT:    movl {{[0-9]+}}(%esp), %esi
106; GISEL-X86-NEXT:    movl %eax, (%esp)
107; GISEL-X86-NEXT:    movl %ecx, {{[0-9]+}}(%esp)
108; GISEL-X86-NEXT:    movl %edx, {{[0-9]+}}(%esp)
109; GISEL-X86-NEXT:    movl %esi, {{[0-9]+}}(%esp)
110; GISEL-X86-NEXT:    calll __divdi3
111; GISEL-X86-NEXT:    addl $24, %esp
112; GISEL-X86-NEXT:    popl %esi
113; GISEL-X86-NEXT:    retl
114  %ret = sdiv i64 %arg1, %arg2
115  ret i64 %ret
116}
117