[MIPS GlobalISel] Set operand order for G_MERGE and G_UNMERGE
[llvm-complete.git] / test / CodeGen / ARM / smul.ll
blob2b7be41ddb24e6df0ce7ebd3e40258fc456f731d
1 ; RUN: llc -mtriple=arm-eabi -mcpu=generic %s -o /dev/null
2 ; RUN: llc -mtriple=arm-eabi -mcpu=cortex-a8 %s -o - | FileCheck %s
3 ; RUN: llc -mtriple=thumb--none-eabi -mcpu=cortex-a8 %s -o - | FileCheck %s
4 ; RUN: llc -mtriple=thumbv6t2-none-eabi %s -o - | FileCheck %s
5 ; RUN: llc -mtriple=thumbv6-none-eabi %s -o - | FileCheck %s -check-prefix=CHECK-THUMBV6
7 define i32 @f1(i16 %x, i32 %y) {
8 ; CHECK-LABEL: f1:
9 ; CHECK-NOT: sxth
10 ; CHECK: {{smulbt r0, r0, r1|smultb r0, r1, r0}}
11 ; CHECK-THUMBV6-NOT: {{smulbt|smultb}}
12         %tmp1 = sext i16 %x to i32
13         %tmp2 = ashr i32 %y, 16
14         %tmp3 = mul i32 %tmp2, %tmp1
15         ret i32 %tmp3
18 define i32 @f2(i32 %x, i32 %y) {
19 ; CHECK-LABEL: f2:
20 ; CHECK: smultt
21 ; CHECK-THUMBV6-NOT: smultt
22         %tmp1 = ashr i32 %x, 16
23         %tmp3 = ashr i32 %y, 16
24         %tmp4 = mul i32 %tmp3, %tmp1
25         ret i32 %tmp4
28 define i32 @f3(i32 %a, i16 %x, i32 %y) {
29 ; CHECK-LABEL: f3:
30 ; CHECK-NOT: sxth
31 ; CHECK: {{smlabt r0, r1, r2, r0|smlatb r0, r2, r1, r0}}
32 ; CHECK-THUMBV6-NOT: {{smlabt|smlatb}}
33         %tmp = sext i16 %x to i32
34         %tmp2 = ashr i32 %y, 16
35         %tmp3 = mul i32 %tmp2, %tmp
36         %tmp5 = add i32 %tmp3, %a
37         ret i32 %tmp5
40 define i32 @f4(i32 %a, i32 %x, i32 %y) {
41 ; CHECK-LABEL: f4:
42 ; CHECK: smlatt
43 ; CHECK-THUMBV6-NOT: smlatt
44         %tmp1 = ashr i32 %x, 16
45         %tmp3 = ashr i32 %y, 16
46         %tmp4 = mul i32 %tmp3, %tmp1
47         %tmp5 = add i32 %tmp4, %a
48         ret i32 %tmp5
51 define i32 @f5(i32 %a, i16 %x, i16 %y) {
52 ; CHECK-LABEL: f5:
53 ; CHECK-NOT: sxth
54 ; CHECK: smlabb
55 ; CHECK-THUMBV6-NOT: smlabb
56         %tmp1 = sext i16 %x to i32
57         %tmp3 = sext i16 %y to i32
58         %tmp4 = mul i32 %tmp3, %tmp1
59         %tmp5 = add i32 %tmp4, %a
60         ret i32 %tmp5
63 define i32 @f6(i32 %a, i32 %x, i16 %y) {
64 ; CHECK-LABEL: f6:
65 ; CHECK-NOT: sxth
66 ; CHECK: {{smlatb r0, r1, r2, r0|smlabt r0, r2, r1, r0}}
67 ; CHECK-THUMBV6-NOT: {{smlatb|smlabt}}
68         %tmp1 = sext i16 %y to i32
69         %tmp2 = ashr i32 %x, 16
70         %tmp3 = mul i32 %tmp2, %tmp1
71         %tmp5 = add i32 %tmp3, %a
72         ret i32 %tmp5
75 define i32 @f7(i32 %a, i32 %b, i32 %c) {
76 ; CHECK-LABEL: f7:
77 ; CHECK: smlawb r0, r0, r1, r2
78 ; CHECK-THUMBV6-NOT: smlawb
79         %shl = shl i32 %b, 16
80         %shr = ashr exact i32 %shl, 16
81         %conv = sext i32 %a to i64
82         %conv2 = sext i32 %shr to i64
83         %mul = mul nsw i64 %conv2, %conv
84         %shr49 = lshr i64 %mul, 16
85         %conv5 = trunc i64 %shr49 to i32
86         %add = add nsw i32 %conv5, %c
87         ret i32 %add
90 define i32 @f8(i32 %a, i16 signext %b, i32 %c) {
91 ; CHECK-LABEL: f8:
92 ; CHECK-NOT: sxth
93 ; CHECK: smlawb r0, r0, r1, r2
94 ; CHECK-THUMBV6-NOT: smlawb
95         %conv = sext i32 %a to i64
96         %conv1 = sext i16 %b to i64
97         %mul = mul nsw i64 %conv1, %conv
98         %shr5 = lshr i64 %mul, 16
99         %conv2 = trunc i64 %shr5 to i32
100         %add = add nsw i32 %conv2, %c
101         ret i32 %add
104 define i32 @f9(i32 %a, i32 %b, i32 %c) {
105 ; CHECK-LABEL: f9:
106 ; CHECK: smlawt r0, r0, r1, r2
107 ; CHECK-THUMBV6-NOT: smlawt
108         %conv = sext i32 %a to i64
109         %shr = ashr i32 %b, 16
110         %conv1 = sext i32 %shr to i64
111         %mul = mul nsw i64 %conv1, %conv
112         %shr26 = lshr i64 %mul, 16
113         %conv3 = trunc i64 %shr26 to i32
114         %add = add nsw i32 %conv3, %c
115         ret i32 %add
118 define i32 @f10(i32 %a, i32 %b) {
119 ; CHECK-LABEL: f10:
120 ; CHECK: smulwb r0, r0, r1
121 ; CHECK-THUMBV6-NOT: smulwb
122         %shl = shl i32 %b, 16
123         %shr = ashr exact i32 %shl, 16
124         %conv = sext i32 %a to i64
125         %conv2 = sext i32 %shr to i64
126         %mul = mul nsw i64 %conv2, %conv
127         %shr37 = lshr i64 %mul, 16
128         %conv4 = trunc i64 %shr37 to i32
129         ret i32 %conv4
132 define i32 @f11(i32 %a, i16 signext %b) {
133 ; CHECK-LABEL: f11:
134 ; CHECK-NOT: sxth
135 ; CHECK: smulwb r0, r0, r1
136 ; CHECK-THUMBV6-NOT: smulwb
137         %conv = sext i32 %a to i64
138         %conv1 = sext i16 %b to i64
139         %mul = mul nsw i64 %conv1, %conv
140         %shr4 = lshr i64 %mul, 16
141         %conv2 = trunc i64 %shr4 to i32
142         ret i32 %conv2
145 define i32 @f12(i32 %a, i32 %b) {
146 ; CHECK-LABEL: f12:
147 ; CHECK: smulwt r0, r0, r1
148 ; CHECK-THUMBV6-NOT: smulwt
149         %conv = sext i32 %a to i64
150         %shr = ashr i32 %b, 16
151         %conv1 = sext i32 %shr to i64
152         %mul = mul nsw i64 %conv1, %conv
153         %shr25 = lshr i64 %mul, 16
154         %conv3 = trunc i64 %shr25 to i32
155         ret i32 %conv3
158 define i32 @f13(i32 %x, i16 %y) {
159 ; CHECK-LABEL: f13:
160 ; CHECK-NOT: sxth
161 ; CHECK: {{smultb r0, r0, r1|smulbt r0, r1, r0}}
162 ; CHECK-THUMBV6-NOT: {{smultb|smulbt}}
163         %tmp1 = sext i16 %y to i32
164         %tmp2 = ashr i32 %x, 16
165         %tmp3 = mul i32 %tmp2, %tmp1
166         ret i32 %tmp3
169 define i32 @f14(i32 %x, i32 %y) {
170 ; CHECK-LABEL: f14:
171 ; CHECK-NOT: sxth
172 ; CHECK: {{smultb r0, r0, r1|smulbt r0, r1, r0}}
173 ; CHECK-THUMBV6-NOT: {{smultb|smulbt}}
174         %tmp1 = shl i32 %y, 16
175         %tmp2 = ashr i32 %tmp1, 16
176         %tmp3 = ashr i32 %x, 16
177         %tmp4 = mul i32 %tmp3, %tmp2
178         ret i32 %tmp4
181 define i32 @f15(i32 %x, i32 %y) {
182 ; CHECK-LABEL: f15:
183 ; CHECK-NOT: sxth
184 ; CHECK: {{smulbt r0, r0, r1|smultb r0, r1, r0}}
185 ; CHECK-THUMBV6-NOT: {{smulbt|smultb}}
186         %tmp1 = shl i32 %x, 16
187         %tmp2 = ashr i32 %tmp1, 16
188         %tmp3 = ashr i32 %y, 16
189         %tmp4 = mul i32 %tmp2, %tmp3
190         ret i32 %tmp4
193 define i32 @f16(i16 %x, i16 %y) {
194 ; CHECK-LABEL: f16:
195 ; CHECK-NOT: sxth
196 ; CHECK: smulbb
197 ; CHECK-THUMBV6-NOT: smulbb
198         %tmp1 = sext i16 %x to i32
199         %tmp2 = sext i16 %x to i32
200         %tmp3 = mul i32 %tmp1, %tmp2
201         ret i32 %tmp3
204 define i32 @f17(i32 %x, i32 %y) {
205 ; CHECK-LABEL: f17:
206 ; CHECK: smulbb
207 ; CHECK-THUMBV6-NOT: smulbb
208         %tmp1 = shl i32 %x, 16
209         %tmp2 = shl i32 %y, 16
210         %tmp3 = ashr i32 %tmp1, 16
211         %tmp4 = ashr i32 %tmp2, 16
212         %tmp5 = mul i32 %tmp3, %tmp4
213         ret i32 %tmp5
216 define i32 @f18(i32 %a, i32 %x, i32 %y) {
217 ; CHECK-LABEL: f18:
218 ; CHECK: {{smlabt r0, r1, r2, r0|smlatb r0, r2, r1, r0}}
219 ; CHECK-THUMBV6-NOT: {{smlabt|smlatb}}
220         %tmp0 = shl i32 %x, 16
221         %tmp1 = ashr i32 %tmp0, 16
222         %tmp2 = ashr i32 %y, 16
223         %tmp3 = mul i32 %tmp2, %tmp1
224         %tmp5 = add i32 %tmp3, %a
225         ret i32 %tmp5
228 define i32 @f19(i32 %a, i32 %x, i32 %y) {
229 ; CHECK-LABEL: f19:
230 ; CHECK: {{smlatb r0, r1, r2, r0|smlabt r0, r2, r1, r0}}
231 ; CHECK-THUMBV6-NOT: {{smlatb|smlabt}}
232         %tmp0 = shl i32 %y, 16
233         %tmp1 = ashr i32 %tmp0, 16
234         %tmp2 = ashr i32 %x, 16
235         %tmp3 = mul i32 %tmp2, %tmp1
236         %tmp5 = add i32 %tmp3, %a
237         ret i32 %tmp5
240 define i32 @f20(i32 %a, i32 %x, i32 %y) {
241 ; CHECK-LABEL: f20:
242 ; CHECK: smlabb
243 ; CHECK-THUMBV6-NOT: smlabb
244         %tmp1 = shl i32 %x, 16
245         %tmp2 = ashr i32 %tmp1, 16
246         %tmp3 = shl i32 %y, 16
247         %tmp4 = ashr i32 %tmp3, 16
248         %tmp5 = mul i32 %tmp2, %tmp4
249         %tmp6 = add i32 %tmp5, %a
250         ret i32 %tmp6
253 define i32 @f21(i32 %a, i32 %x, i16 %y) {
254 ; CHECK-LABEL: f21
255 ; CHECK-NOT: sxth
256 ; CHECK: smlabb
257 ; CHECK-THUMBV6-NOT: smlabb
258         %tmp1 = shl i32 %x, 16
259         %tmp2 = ashr i32 %tmp1, 16
260         %tmp3 = sext i16 %y to i32
261         %tmp4 = mul i32 %tmp2, %tmp3
262         %tmp5 = add i32 %a, %tmp4
263         ret i32 %tmp5
266 @global_b = external global i16, align 2
268 define i32 @f22(i32 %a) {
269 ; CHECK-LABEL: f22:
270 ; CHECK: smulwb r0, r0, r1
271 ; CHECK-THUMBV6-NOT: smulwb
272         %b = load i16, i16* @global_b, align 2
273         %sext = sext i16 %b to i64
274         %conv = sext i32 %a to i64
275         %mul = mul nsw i64 %sext, %conv
276         %shr37 = lshr i64 %mul, 16
277         %conv4 = trunc i64 %shr37 to i32
278         ret i32 %conv4
281 define i32 @f23(i32 %a, i32 %c) {
282 ; CHECK-LABEL: f23:
283 ; CHECK: smlawb r0, r0, r2, r1
284 ; CHECK-THUMBV6-NOT: smlawb
285         %b = load i16, i16* @global_b, align 2
286         %sext = sext i16 %b to i64
287         %conv = sext i32 %a to i64
288         %mul = mul nsw i64 %sext, %conv
289         %shr49 = lshr i64 %mul, 16
290         %conv5 = trunc i64 %shr49 to i32
291         %add = add nsw i32 %conv5, %c
292         ret i32 %add