1 ; RUN: llc -mtriple=arm-eabi %s -o - | FileCheck %s --check-prefix=ARM
3 ; RUN: llc -mtriple=arm-eabi -mcpu=arm1156t2-s -mattr=+thumb2 %s -o - \
4 ; RUN: | FileCheck %s --check-prefix=ARMT2
6 ; RUN: llc -mtriple=thumb-eabi -mcpu=cortex-m0 %s -o - \
7 ; RUN: | FileCheck %s --check-prefix=THUMB1
9 ; RUN: llc -mtriple=thumb-eabi -mcpu=arm1156t2-s -mattr=+thumb2 %s -o - \
10 ; RUN: | FileCheck %s --check-prefix=THUMB2
12 ; RUN: llc -mtriple=thumbv8m.base-eabi %s -o - \
13 ; RUN: | FileCheck %s --check-prefix=V8MBASE
15 define i32 @t1(i32 %c) nounwind readnone {
18 ; ARM: mov [[R1:r[0-9]+]], #101
19 ; ARM: orr [[R1b:r[0-9]+]], [[R1]], #256
20 ; ARM: movgt {{r[0-1]}}, #123
23 ; ARMT2: movw [[R:r[0-1]]], #357
24 ; ARMT2: movwgt [[R]], #123
31 ; THUMB2: movw [[R:r[0-1]]], #357
32 ; THUMB2: movgt [[R]], #123
34 %0 = icmp sgt i32 %c, 1
35 %1 = select i1 %0, i32 123, i32 357
39 define i32 @t2(i32 %c) nounwind readnone {
42 ; ARM: mov [[R:r[0-9]+]], #101
43 ; ARM: orr [[R]], [[R]], #256
44 ; ARM: movle [[R]], #123
47 ; ARMT2: mov [[R:r[0-1]]], #123
48 ; ARMT2: movwgt [[R]], #357
51 ; THUMB1: cmp r{{[0-9]+}}, #1
55 ; THUMB2: mov{{(s|\.w)}} [[R:r[0-1]]], #123
56 ; THUMB2: movwgt [[R]], #357
58 %0 = icmp sgt i32 %c, 1
59 %1 = select i1 %0, i32 357, i32 123
63 define i32 @t3(i32 %a) nounwind readnone {
66 ; ARM: rsbs r1, r0, #0
71 ; ARMT2: lsr r0, r0, #5
74 ; THUMB1: rsbs r1, r0, #0
79 ; THUMB2: lsrs r0, r0, #5
80 %0 = icmp eq i32 %a, 160
81 %1 = zext i1 %0 to i32
85 define i32 @t4(i32 %a, i32 %b, i32 %x) nounwind {
92 ; ARMT2: movwlt [[R0:r[0-9]+]], #65365
93 ; ARMT2: movtlt [[R0]], #65365
96 ; THUMB1: cmp r{{[0-9]+}}, r{{[0-9]+}}
100 ; THUMB2: mvnlt [[R0:r[0-9]+]], #11141290
101 %0 = icmp slt i32 %a, %b
102 %1 = select i1 %0, i32 4283826005, i32 %x
107 define i32 @t5(i32 %a) nounwind {
111 ; ARM: sub r0, r0, #1
113 ; ARM: rsbs r1, r0, #0
114 ; ARM: adc r0, r0, r1
118 ; THUMB1: rsbs r0, r1, #0
119 ; THUMB1: adcs r0, r1
123 ; THUMB2: subs r0, #1
125 ; THUMB2: lsrs r0, r0, #5
127 %cmp = icmp eq i32 %a, 1
128 %conv = zext i1 %cmp to i32
132 define i32 @t6(i32 %a) nounwind {
140 ; THUMB1: subs r1, r0, #1
141 ; THUMB1: sbcs r0, r1
147 ; THUMB2: movne r0, #1
148 %tobool = icmp ne i32 %a, 0
149 %lnot.ext = zext i1 %tobool to i32
153 define i32 @t7(i32 %a, i32 %b) nounwind readnone {
156 ; ARM: subs r0, r0, r1
158 ; ARM: lsl r0, r0, #2
161 ; ARMT2: subs r0, r0, r1
162 ; ARMT2: movwne r0, #1
163 ; ARMT2: lsl r0, r0, #2
166 ; THUMB1: subs r0, r0, r1
167 ; THUMB1: subs r1, r0, #1
168 ; THUMB1: sbcs r0, r1
169 ; THUMB1: lsls r0, r0, #2
172 ; THUMB2: subs r0, r0, r1
174 ; THUMB2: movne r0, #1
175 ; THUMB2: lsls r0, r0, #2
176 %0 = icmp ne i32 %a, %b
177 %1 = select i1 %0, i32 4, i32 0
181 define void @t8(i32 %a) {
184 ; ARM scheduler emits icmp/zext before both calls, so isn't relevant
189 ; ARMT2: sub r0, r4, #5
191 ; ARMT2: lsr r0, r0, #5
196 ; THUMB1: subs r2, r4, #5
197 ; THUMB1: rsbs r0, r2, #0
198 ; THUMB1: adcs r0, r2
203 ; THUMB2: subs r0, r4, #5
205 ; THUMB2: lsrs r0, r0, #5
207 %cmp = icmp eq i32 %a, 5
208 %conv = zext i1 %cmp to i32
209 %call = tail call i32 @t7(i32 9, i32 %a)
210 tail call i32 @t7(i32 %conv, i32 %call)
214 define void @t9(i8* %a, i8 %b) {
217 ; ARM scheduler emits icmp/zext before both calls, so isn't relevant
223 ; ARMT2: add r1, r4, #1
225 ; ARMT2: add r2, r2, #1
226 ; ARMT2: add r1, r1, #1
232 ; THUMB1: sxtb r1, r4
233 ; THUMB1: uxtb r0, r1
235 ; THUMB1: adds r1, r1, #1
237 ; THUMB1: adds r1, r1, #1
238 ; THUMB1: adds r2, r2, #1
239 ; THUMB1: uxtb r3, r2
244 ; THUMB2: uxtb r0, r4
246 ; THUMB2: adds r1, r4, #1
248 ; THUMB2: adds r2, #1
249 ; THUMB2: adds r1, #1
250 ; THUMB2: uxtb r3, r2
254 %conv = sext i8 %0 to i32
255 %conv119 = zext i8 %0 to i32
256 %conv522 = and i32 %conv, 255
257 %cmp723 = icmp eq i32 %conv522, %conv119
258 tail call void @f(i1 zeroext %cmp723)
259 br i1 %cmp723, label %while.body, label %while.end
261 while.body: ; preds = %entry, %while.body
262 %ref.025 = phi i8 [ %inc9, %while.body ], [ %0, %entry ]
263 %in.024 = phi i32 [ %inc, %while.body ], [ %conv, %entry ]
264 %inc = add i32 %in.024, 1
265 %inc9 = add i8 %ref.025, 1
266 %conv1 = zext i8 %inc9 to i32
267 %cmp = icmp slt i32 %conv1, %conv119
268 %conv5 = and i32 %inc, 255
269 br i1 %cmp, label %while.body, label %while.end
275 declare void @f(i1 zeroext)
282 store i32 -3, i32* %q
283 store i32 -8, i32* %p
284 %0 = load i32, i32* %q
285 %1 = load i32, i32* %p
286 %div = sdiv i32 %0, %1
287 %mul = mul nsw i32 %div, %1
288 %rem = srem i32 %0, %1
289 %add = add nsw i32 %mul, %rem
290 %cmp = icmp eq i32 %add, %0
294 ; ARM: rsbs r1, r0, #0
295 ; ARM: adc r0, r0, r1
299 ; ARMT2: lsr r0, r0, #5
302 ; THUMB1: rsbs r0, r1, #0
303 ; THUMB1: adcs r0, r1
307 ; THUMB2: lsrs r0, r0, #5
309 ; V8MBASE-LABEL: t10:
310 ; V8MBASE-NOT: movs r0, #0
311 ; V8MBASE: movs r0, #7
317 %load = load i32, i32* %bit
318 %clear = and i32 %load, -4096
319 %set = or i32 %clear, 33
320 store i32 %set, i32* %bit
321 %load1 = load i32, i32* %bit
322 %clear2 = and i32 %load1, -33550337
323 %set3 = or i32 %clear2, 40960
324 %clear5 = and i32 %set3, 4095
325 %rem = srem i32 %clear5, 10
326 %clear9 = and i32 %set3, -4096
327 %set10 = or i32 %clear9, %rem
328 store i32 %set10, i32* %bit
329 %clear12 = and i32 %set10, 4095
330 %cmp = icmp eq i32 %clear12, 3
334 ; ARM: rsbs r1, r0, #0
335 ; ARM: adc r0, r0, r1
339 ; ARMT2: lsr r0, r0, #5
342 ; THUMB1-NOT: movs r0, #0
343 ; THUMB1: movs r0, #5
347 ; THUMB2: lsrs r0, r0, #5
349 ; V8MBASE-LABEL: t11:
350 ; V8MBASE-NOT: movs r0, #0
351 ; V8MBASE: movw r0, #40960
354 define i32 @t12(i32 %a) nounwind {
362 ; THUMB1: subs r1, r0, #1
363 ; THUMB1: sbcs r0, r1
364 ; THUMB1: lsls r0, r0, #1
370 ; THUMB2: movne r0, #1
371 %tobool = icmp ne i32 %a, 0
372 %lnot.ext = select i1 %tobool, i32 2, i32 0
376 define i32 @t13(i32 %a) nounwind {
386 ; THUMB1: movs r0, #3
392 ; THUMB2: movne r0, #3
393 %tobool = icmp ne i32 %a, 0
394 %lnot.ext = select i1 %tobool, i32 3, i32 0