1; RUN: llc -mtriple armv7-none-eabi %s -o - | FileCheck %s --check-prefix=EABI
2; RUN: llc -mtriple armv7-none-eabihf %s -o - | FileCheck %s --check-prefix=EABI
3; RUN: llc -mtriple armv7-linux-gnueabi %s -o - | FileCheck %s --check-prefix=GNU
4; RUN: llc -mtriple armv7-apple-darwin %s -o - | FileCheck %s --check-prefix=DARWIN
5; FIXME: long-term, we will use "-apple-macho" and won't need this exception:
6; RUN: llc -mtriple armv7-apple-darwin-eabi %s -o - | FileCheck %s --check-prefix=DARWIN
7
8define signext i16 @f16(i16 signext %a, i16 signext %b) {
9; EABI-LABEL: f16:
10; GNU-LABEL: f16:
11; DARWIN-LABEL: f16:
12entry:
13  %conv = sext i16 %a to i32
14  %conv1 = sext i16 %b to i32
15  %div = sdiv i32 %conv, %conv1
16  %rem = srem i32 %conv, %conv1
17; EABI: __aeabi_idivmod
18; EABI: mov [[div:r[0-9]+]], r0
19; EABI: mov [[rem:r[0-9]+]], r1
20; GNU: __aeabi_idiv
21; GNU: mov [[sum:r[0-9]+]], r0
22; GNU: __modsi3
23; GNU: add [[sum]]{{.*}}r0
24; DARWIN: ___divsi3
25; DARWIN: mov [[sum:r[0-9]+]], r0
26; DARWIN: __modsi3
27; DARWIN: add [[sum]]{{.*}}r0
28  %rem8 = srem i32 %conv1, %conv
29; EABI: __aeabi_idivmod
30; GNU: __modsi3
31; DARWIN: __modsi3
32  %add = add nsw i32 %rem, %div
33  %add13 = add nsw i32 %add, %rem8
34  %conv14 = trunc i32 %add13 to i16
35; EABI: add r0{{.*}}r1
36; EABI: sxth r0, r0
37; GNU: add r0{{.*}}[[sum]]
38; GNU: sxth r0, r0
39; DARWIN: add r0{{.*}}[[sum]]
40; DARWIN: sxth r0, r0
41  ret i16 %conv14
42}
43
44define i32 @f32(i32 %a, i32 %b) {
45; EABI-LABEL: f32:
46; GNU-LABEL: f32:
47; DARWIN-LABEL: f32:
48entry:
49  %div = sdiv i32 %a, %b
50  %rem = srem i32 %a, %b
51; EABI: __aeabi_idivmod
52; EABI: mov [[div:r[0-9]+]], r0
53; EABI: mov [[rem:r[0-9]+]], r1
54; GNU: __aeabi_idiv
55; GNU: mov [[sum:r[0-9]+]], r0
56; GNU: __modsi3
57; GNU: add [[sum]]{{.*}}r0
58; DARWIN: ___divsi3
59; DARWIN: mov [[sum:r[0-9]+]], r0
60; DARWIN: __modsi3
61; DARWIN: add [[sum]]{{.*}}r0
62  %rem1 = srem i32 %b, %a
63; EABI: __aeabi_idivmod
64; GNU: __modsi3
65; DARWIN: __modsi3
66  %add = add nsw i32 %rem, %div
67  %add2 = add nsw i32 %add, %rem1
68; EABI: add r0{{.*}}r1
69; GNU: add r0{{.*}}[[sum]]
70; DARWIN: add r0{{.*}}[[sum]]
71  ret i32 %add2
72}
73
74define i32 @uf(i32 %a, i32 %b) {
75; EABI-LABEL: uf:
76; GNU-LABEL: uf:
77; DARWIN-LABEL: uf:
78entry:
79  %div = udiv i32 %a, %b
80  %rem = urem i32 %a, %b
81; EABI: __aeabi_uidivmod
82; GNU: __aeabi_uidiv
83; GNU: mov [[sum:r[0-9]+]], r0
84; GNU: __umodsi3
85; GNU: add [[sum]]{{.*}}r0
86; DARWIN: ___udivsi3
87; DARWIN: mov [[sum:r[0-9]+]], r0
88; DARWIN: __umodsi3
89; DARWIN: add [[sum]]{{.*}}r0
90  %rem1 = urem i32 %b, %a
91; EABI: __aeabi_uidivmod
92; GNU: __umodsi3
93; DARWIN: __umodsi3
94  %add = add nuw i32 %rem, %div
95  %add2 = add nuw i32 %add, %rem1
96; EABI: add r0{{.*}}r1
97; GNU: add r0{{.*}}[[sum]]
98; DARWIN: add r0{{.*}}[[sum]]
99  ret i32 %add2
100}
101
102; FIXME: AEABI is not lowering long u/srem into u/ldivmod
103define i64 @longf(i64 %a, i64 %b) {
104; EABI-LABEL: longf:
105; GNU-LABEL: longf:
106; DARWIN-LABEL: longf:
107entry:
108  %div = sdiv i64 %a, %b
109  %rem = srem i64 %a, %b
110; EABI: __aeabi_ldivmod
111; GNU: __aeabi_ldivmod
112; GNU: mov [[div1:r[0-9]+]], r0
113; GNU: mov [[div2:r[0-9]+]], r1
114; DARWIN: ___divdi3
115; DARWIN: mov [[div1:r[0-9]+]], r0
116; DARWIN: mov [[div2:r[0-9]+]], r1
117; DARWIN: __moddi3
118  %add = add nsw i64 %rem, %div
119; GNU: adds r0{{.*}}[[div1]]
120; GNU: adc r1{{.*}}[[div2]]
121; DARWIN: adds r0{{.*}}[[div1]]
122; DARWIN: adc r1{{.*}}[[div2]]
123  ret i64 %add
124}
125
126define i32 @g1(i32 %a, i32 %b) {
127; EABI-LABEL: g1:
128; GNU-LABEL: g1:
129; DARWIN-LABEL: g1:
130entry:
131  %div = sdiv i32 %a, %b
132  %rem = srem i32 %a, %b
133; EABI: __aeabi_idivmod
134; GNU: __aeabi_idiv
135; GNU: mov [[sum:r[0-9]+]], r0
136; GNU: __modsi3
137; DARWIN: ___divsi3
138; DARWIN: mov [[sum:r[0-9]+]], r0
139; DARWIN: __modsi3
140  %add = add nsw i32 %rem, %div
141; EABI:	add	r0{{.*}}r1
142; GNU: add r0{{.*}}[[sum]]
143; DARWIN: add r0{{.*}}[[sum]]
144  ret i32 %add
145}
146
147; On both Darwin and Gnu, this is just a call to __modsi3
148define i32 @g2(i32 %a, i32 %b) {
149; EABI-LABEL: g2:
150; GNU-LABEL: g2:
151; DARWIN-LABEL: g2:
152entry:
153  %rem = srem i32 %a, %b
154; EABI: __aeabi_idivmod
155; GNU: __modsi3
156; DARWIN: __modsi3
157  ret i32 %rem
158; EABI:	mov	r0, r1
159}
160
161define i32 @g3(i32 %a, i32 %b) {
162; EABI-LABEL: g3:
163; GNU-LABEL: g3:
164; DARWIN-LABEL: g3:
165entry:
166  %rem = srem i32 %a, %b
167; EABI: __aeabi_idivmod
168; EABI: mov [[mod:r[0-9]+]], r1
169; GNU: __modsi3
170; GNU: mov [[sum:r[0-9]+]], r0
171; DARWIN: __modsi3
172; DARWIN: mov [[sum:r[0-9]+]], r0
173  %rem1 = srem i32 %b, %rem
174; EABI: __aeabi_idivmod
175; GNU: __modsi3
176; DARWIN: __modsi3
177  %add = add nsw i32 %rem1, %rem
178; EABI: add r0, r1, [[mod]]
179; GNU: add r0{{.*}}[[sum]]
180; DARWIN: add r0{{.*}}[[sum]]
181  ret i32 %add
182}
183
184define i32 @g4(i32 %a, i32 %b) {
185; EABI-LABEL: g4:
186; GNU-LABEL: g4:
187; DARWIN-LABEL: g4:
188entry:
189  %div = sdiv i32 %a, %b
190; EABI: __aeabi_idivmod
191; EABI: mov [[div:r[0-9]+]], r0
192; GNU: __aeabi_idiv
193; GNU: mov [[sum:r[0-9]+]], r0
194; DARWIN: ___divsi3
195; DARWIN: mov [[sum:r[0-9]+]], r0
196  %rem = srem i32 %b, %div
197; EABI: __aeabi_idivmod
198; GNU: __modsi3
199; DARWIN: __modsi3
200  %add = add nsw i32 %rem, %div
201; EABI: add r0, r1, [[div]]
202; GNU: add r0{{.*}}[[sum]]
203; DARWIN: add r0{{.*}}[[sum]]
204  ret i32 %add
205}
206