1 ; RUN: llc -mtriple=thumbv7m-none-eabi -o - %s | FileCheck %s
5 ; Leaf function, no frame so no need for a frame pointer.
15 ; Leaf function, frame pointer is requested but we don't need any stack frame,
16 ; so don't create a frame pointer.
17 define void @leaf_nofpelim() "frame-pointer"="all" {
18 ; CHECK-LABEL: leaf_nofpelim:
26 ; Leaf function, frame pointer is requested and we need a stack frame, so we
27 ; need to use a frame pointer.
28 define void @leaf_lowreg_nofpelim() "frame-pointer"="all" {
29 ; CHECK-LABEL: leaf_lowreg_nofpelim:
30 ; CHECK: push {r4, r6, r7, lr}
31 ; CHECK: add r7, sp, #8
32 ; CHECK: pop {r4, r6, r7, pc}
33 call void asm sideeffect "", "~{r4}" ()
37 ; Leaf function, frame pointer is requested and we need a stack frame, so we
38 ; need to use a frame pointer. A high register is pushed to the stack, so we
39 ; must use two push/pop instructions to ensure that fp and sp are adjacent on
41 define void @leaf_highreg_nofpelim() "frame-pointer"="all" {
42 ; CHECK-LABEL: leaf_highreg_nofpelim:
43 ; CHECK: push {r6, r7, lr}
44 ; CHECK: add r7, sp, #4
45 ; CHECK: str r8, [sp, #-4]!
46 ; CHECK: ldr r8, [sp], #4
47 ; CHECK: pop {r6, r7, pc}
48 call void asm sideeffect "", "~{r8}" ()
52 ; Leaf function, frame pointer requested for non-leaf functions only, so no
53 ; need for a stack frame.
54 define void @leaf_nononleaffpelim() "frame-pointer"="non-leaf" {
55 ; CHECK-LABEL: leaf_nononleaffpelim:
63 ; Has a call, but still no need for a frame pointer.
66 ; CHECK: push {[[DUMMYREG:r[0-9]+]], lr}
69 ; CHECK: pop {[[DUMMYREG]], pc}
74 ; Has a call, and frame pointer requested.
75 define void @call_nofpelim() "frame-pointer"="all" {
76 ; CHECK-LABEL: call_nofpelim:
77 ; CHECK: push {r7, lr}
85 ; Has a call, and frame pointer requested for non-leaf function.
86 define void @call_nononleaffpelim() "frame-pointer"="non-leaf" {
87 ; CHECK-LABEL: call_nononleaffpelim:
88 ; CHECK: push {r7, lr}
96 ; Has a high register clobbered, no need for a frame pointer.
97 define void @highreg() {
98 ; CHECK-LABEL: highreg:
99 ; CHECK: push.w {r8, lr}
102 ; CHECK: pop.w {r8, pc}
103 call void asm sideeffect "", "~{r8}" ()
108 ; Has a high register clobbered, frame pointer requested. We need to split the
109 ; push into two, to ensure that r7 and sp are adjacent on the stack.
110 define void @highreg_nofpelim() "frame-pointer"="all" {
111 ; CHECK-LABEL: highreg_nofpelim:
112 ; CHECK: push {[[DUMMYREG:r[0-9]+]], r7, lr}
113 ; CHECK: add r7, sp, #4
114 ; CHECK: str r8, [sp, #-4]!
116 ; CHECK: ldr r8, [sp], #4
117 ; CHECK: pop {[[DUMMYREG]], r7, pc}
118 call void asm sideeffect "", "~{r8}" ()
123 ; Has a high register clobbered, frame required due to variable-sized alloca.
124 ; We need a frame pointer to correctly restore the stack, but don't need to
125 ; split the push/pop here, because the frame pointer not required by the ABI.
126 define void @highreg_alloca(i32 %a) {
127 ; CHECK-LABEL: highreg_alloca:
128 ; CHECK: push.w {[[SOMEREGS:.*]], r7, r8, lr}
129 ; CHECK: add r7, sp, #{{[0-9]+}}
131 ; CHECK: pop.w {[[SOMEREGS]], r7, r8, pc}
132 %alloca = alloca i32, i32 %a, align 4
134 call void asm sideeffect "", "~{r8}" ()
138 ; Has a high register clobbered, frame required due to both variable-sized
139 ; alloca and ABI. We do need to split the push/pop here.
140 define void @highreg_alloca_nofpelim(i32 %a) "frame-pointer"="all" {
141 ; CHECK-LABEL: highreg_alloca_nofpelim:
142 ; CHECK: push {[[SOMEREGS:.*]], r7, lr}
143 ; CHECK: add r7, sp, #{{[0-9]+}}
144 ; CHECK: str r8, [sp, #-4]!
146 ; CHECK: ldr r8, [sp], #4
147 ; CHECK: pop {[[SOMEREGS]], r7, pc}
148 %alloca = alloca i32, i32 %a, align 4
150 call void asm sideeffect "", "~{r8}" ()