1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=arm-eabi %s -o - | FileCheck %s
3 ; RUN: llc -mtriple=armv6m-eabi %s -o - | FileCheck %s --check-prefix=EXPAND
5 define i64 @test_shl(i64 %val, i64 %amt) {
6 ; CHECK-LABEL: test_shl:
8 ; CHECK-NEXT: rsb r3, r2, #32
9 ; CHECK-NEXT: lsr r3, r0, r3
10 ; CHECK-NEXT: orr r1, r3, r1, lsl r2
11 ; CHECK-NEXT: sub r3, r2, #32
12 ; CHECK-NEXT: cmp r3, #0
13 ; CHECK-NEXT: lslge r1, r0, r3
14 ; CHECK-NEXT: lsl r0, r0, r2
15 ; CHECK-NEXT: movge r0, #0
16 ; CHECK-NEXT: mov pc, lr
18 ; EXPAND-LABEL: test_shl:
20 ; EXPAND-NEXT: .save {r7, lr}
21 ; EXPAND-NEXT: push {r7, lr}
22 ; EXPAND-NEXT: bl __aeabi_llsl
23 ; EXPAND-NEXT: pop {r7, pc}
24 %res = shl i64 %val, %amt
28 ; Explanation for lshr is pretty much the reverse of shl.
29 define i64 @test_lshr(i64 %val, i64 %amt) {
30 ; CHECK-LABEL: test_lshr:
32 ; CHECK-NEXT: rsb r3, r2, #32
33 ; CHECK-NEXT: lsr r0, r0, r2
34 ; CHECK-NEXT: orr r0, r0, r1, lsl r3
35 ; CHECK-NEXT: sub r3, r2, #32
36 ; CHECK-NEXT: cmp r3, #0
37 ; CHECK-NEXT: lsrge r0, r1, r3
38 ; CHECK-NEXT: lsr r1, r1, r2
39 ; CHECK-NEXT: movge r1, #0
40 ; CHECK-NEXT: mov pc, lr
42 ; EXPAND-LABEL: test_lshr:
44 ; EXPAND-NEXT: .save {r7, lr}
45 ; EXPAND-NEXT: push {r7, lr}
46 ; EXPAND-NEXT: bl __aeabi_llsr
47 ; EXPAND-NEXT: pop {r7, pc}
48 %res = lshr i64 %val, %amt
52 ; One minor difference for ashr: the high bits must be "hi >> 31" if the shift
53 ; amount is large to get the right sign bit.
54 define i64 @test_ashr(i64 %val, i64 %amt) {
55 ; CHECK-LABEL: test_ashr:
57 ; CHECK-NEXT: sub r12, r2, #32
58 ; CHECK-NEXT: asr r3, r1, r2
59 ; CHECK-NEXT: lsr r0, r0, r2
60 ; CHECK-NEXT: rsb r2, r2, #32
61 ; CHECK-NEXT: cmp r12, #0
62 ; CHECK-NEXT: orr r0, r0, r1, lsl r2
63 ; CHECK-NEXT: asrge r3, r1, #31
64 ; CHECK-NEXT: asrge r0, r1, r12
65 ; CHECK-NEXT: mov r1, r3
66 ; CHECK-NEXT: mov pc, lr
68 ; EXPAND-LABEL: test_ashr:
70 ; EXPAND-NEXT: .save {r7, lr}
71 ; EXPAND-NEXT: push {r7, lr}
72 ; EXPAND-NEXT: bl __aeabi_lasr
73 ; EXPAND-NEXT: pop {r7, pc}
74 %res = ashr i64 %val, %amt