1 ; RUN: llc < %s -mtriple=i686-pc-linux | FileCheck %s -check-prefix=LINUX -check-prefix=CHECK
2 ; RUN: llc < %s -mtriple=i686-apple-darwin | FileCheck %s -check-prefix=DARWIN -check-prefix=CHECK
3 ; RUN: llc < %s -mtriple=i686-pc-linux -stop-after=prologepilog | FileCheck %s --check-prefix=PEI
5 declare i32 @__gxx_personality_v0(...)
6 declare void @good(i32 %a, i32 %b, i32 %c, i32 %d)
7 declare void @large(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f)
10 ; When we use an invoke, we expect a .cfi_escape GNU_ARGS_SIZE
11 ; with size 16 before the invocation. Without FP, we also expect
12 ; .cfi_adjust_cfa_offset after each push.
13 ; Darwin should not generate pushes in either circumstance.
14 ; CHECK-LABEL: test1_nofp:
15 ; LINUX: .cfi_escape 0x2e, 0x10
16 ; LINUX-NEXT: pushl $4
17 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
18 ; LINUX-NEXT: pushl $3
19 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
20 ; LINUX-NEXT: pushl $2
21 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
22 ; LINUX-NEXT: pushl $1
23 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
25 ; LINUX-NEXT: addl $16, %esp
26 ; LINUX: .cfi_adjust_cfa_offset -16
27 ; DARWIN-NOT: .cfi_escape
30 ; PEI-LABEL: name: test1_nofp
31 ; PEI: $esp = frame-setup SUB32ri $esp, 12, implicit-def dead $eflags
32 ; PEI-NEXT: frame-setup CFI_INSTRUCTION def_cfa_offset 16
33 ; PEI-NOT: frame-setup CFI_INSTRUCTION
35 define void @test1_nofp() #0 personality ptr @__gxx_personality_v0 {
37 invoke void @good(i32 1, i32 2, i32 3, i32 4)
38 to label %continue unwind label %cleanup
42 landingpad { ptr, i32 }
47 ; CHECK-LABEL: test1_fp:
48 ; LINUX: .cfi_escape 0x2e, 0x10
49 ; LINUX-NEXT: pushl $4
50 ; LINUX-NEXT: pushl $3
51 ; LINUX-NEXT: pushl $2
52 ; LINUX-NEXT: pushl $1
54 ; LINUX-NEXT: addl $16, %esp
56 ; DARWIN-NOT: .cfi_escape
58 define void @test1_fp() #1 personality ptr @__gxx_personality_v0 {
60 invoke void @good(i32 1, i32 2, i32 3, i32 4)
61 to label %continue unwind label %cleanup
65 landingpad { ptr, i32 }
70 ; If the function has no handlers, we don't need to generate GNU_ARGS_SIZE,
71 ; even if it has an unwind table. Without FP, we still need cfi_adjust_cfa_offset,
72 ; so darwin should not generate pushes.
73 ; CHECK-LABEL: test2_nofp:
74 ; LINUX-NOT: .cfi_escape
76 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
77 ; LINUX-NEXT: pushl $3
78 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
79 ; LINUX-NEXT: pushl $2
80 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
81 ; LINUX-NEXT: pushl $1
82 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
84 ; LINUX-NEXT: addl $28, %esp
85 ; LINUX: .cfi_adjust_cfa_offset -28
86 ; DARWIN-NOT: .cfi_escape
88 define void @test2_nofp() #0 personality ptr @__gxx_personality_v0 {
90 call void @good(i32 1, i32 2, i32 3, i32 4)
94 ; CHECK-LABEL: test2_fp:
95 ; CHECK-NOT: .cfi_escape
96 ; CHECK-NOT: .cfi_adjust_cfa_offset
98 ; CHECK-NEXT: pushl $3
99 ; CHECK-NEXT: pushl $2
100 ; CHECK-NEXT: pushl $1
102 ; CHECK-NEXT: addl $24, %esp
103 define void @test2_fp() #1 personality ptr @__gxx_personality_v0 {
105 call void @good(i32 1, i32 2, i32 3, i32 4)
109 ; If we did not end up using any pushes, no need for GNU_ARGS_SIZE or
110 ; cfi_adjust_cfa_offset.
111 ; CHECK-LABEL: test3_nofp:
112 ; LINUX-NOT: .cfi_escape
113 ; LINUX-NOT: .cfi_adjust_cfa_offset
116 define void @test3_nofp() #0 personality ptr @__gxx_personality_v0 {
119 to label %continue unwind label %cleanup
123 landingpad { ptr, i32 }
128 ; If we did not end up using any pushes, no need for GNU_ARGS_SIZE or
129 ; cfi_adjust_cfa_offset.
130 ; CHECK-LABEL: test3_fp:
132 ; LINUX-NOT: .cfi_escape
133 ; LINUX-NOT: .cfi_adjust_cfa_offset
136 define void @test3_fp() #1 personality ptr @__gxx_personality_v0 {
139 to label %continue unwind label %cleanup
143 landingpad { ptr, i32 }
148 ; Different sized stacks need different GNU_ARGS_SIZEs
149 ; CHECK-LABEL: test4:
150 ; LINUX: .cfi_escape 0x2e, 0x10
151 ; LINUX-NEXT: pushl $4
152 ; LINUX-NEXT: pushl $3
153 ; LINUX-NEXT: pushl $2
154 ; LINUX-NEXT: pushl $1
156 ; LINUX-NEXT: addl $16, %esp
157 ; LINUX: .cfi_escape 0x2e, 0x20
158 ; LINUX: subl $8, %esp
159 ; LINUX-NEXT: pushl $11
160 ; LINUX-NEXT: pushl $10
161 ; LINUX-NEXT: pushl $9
162 ; LINUX-NEXT: pushl $8
163 ; LINUX-NEXT: pushl $7
164 ; LINUX-NEXT: pushl $6
165 ; LINUX-NEXT: calll large
166 ; LINUX-NEXT: addl $32, %esp
167 define void @test4() #1 personality ptr @__gxx_personality_v0 {
169 invoke void @good(i32 1, i32 2, i32 3, i32 4)
170 to label %continue1 unwind label %cleanup
172 invoke void @large(i32 6, i32 7, i32 8, i32 9, i32 10, i32 11)
173 to label %continue2 unwind label %cleanup
177 landingpad { ptr, i32 }
182 ; If we did use pushes, we need to reset GNU_ARGS_SIZE before a call
183 ; without parameters, but don't need to adjust the cfa offset
184 ; CHECK-LABEL: test5_nofp:
185 ; LINUX: .cfi_escape 0x2e, 0x10
186 ; LINUX-NEXT: pushl $4
187 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
188 ; LINUX-NEXT: pushl $3
189 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
190 ; LINUX-NEXT: pushl $2
191 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
192 ; LINUX-NEXT: pushl $1
193 ; LINUX-NEXT: .cfi_adjust_cfa_offset 4
195 ; LINUX-NEXT: addl $16, %esp
196 ; LINUX: .cfi_adjust_cfa_offset -16
197 ; LINUX-NOT: .cfi_adjust_cfa_offset
198 ; LINUX: .cfi_escape 0x2e, 0x00
199 ; LINUX-NOT: .cfi_adjust_cfa_offset
201 define void @test5_nofp() #0 personality ptr @__gxx_personality_v0 {
203 invoke void @good(i32 1, i32 2, i32 3, i32 4)
204 to label %continue1 unwind label %cleanup
207 to label %continue2 unwind label %cleanup
211 landingpad { ptr, i32 }
216 ; CHECK-LABEL: test5_fp:
217 ; LINUX: .cfi_escape 0x2e, 0x10
218 ; LINUX-NEXT: pushl $4
219 ; LINUX-NEXT: pushl $3
220 ; LINUX-NEXT: pushl $2
221 ; LINUX-NEXT: pushl $1
223 ; LINUX-NEXT: addl $16, %esp
224 ; LINUX: .cfi_escape 0x2e, 0x00
225 ; LINUX-NOT: .cfi_adjust_cfa_offset
227 define void @test5_fp() #1 personality ptr @__gxx_personality_v0 {
229 invoke void @good(i32 1, i32 2, i32 3, i32 4)
230 to label %continue1 unwind label %cleanup
233 to label %continue2 unwind label %cleanup
237 landingpad { ptr, i32 }
242 ; FIXME: This is actually inefficient - we don't need to repeat the .cfi_escape twice.
243 ; CHECK-LABEL: test6:
244 ; LINUX: .cfi_escape 0x2e, 0x10
246 ; LINUX: .cfi_escape 0x2e, 0x10
248 define void @test6() #1 personality ptr @__gxx_personality_v0 {
250 invoke void @good(i32 1, i32 2, i32 3, i32 4)
251 to label %continue1 unwind label %cleanup
253 invoke void @good(i32 5, i32 6, i32 7, i32 8)
254 to label %continue2 unwind label %cleanup
258 landingpad { ptr, i32 }
263 ; Darwin should generate pushes in the presense of FP and an unwind table,
264 ; but not FP and invoke.
265 ; CHECK-LABEL: test7:
267 ; DARWIN: movl %esp, %ebp
268 ; DARWIN: .cfi_def_cfa_register %ebp
269 ; DARWIN-NOT: .cfi_adjust_cfa_offset
271 ; DARWIN-NEXT: pushl $3
272 ; DARWIN-NEXT: pushl $2
273 ; DARWIN-NEXT: pushl $1
275 define void @test7() #1 personality ptr @__gxx_personality_v0 {
277 call void @good(i32 1, i32 2, i32 3, i32 4)
281 ; CHECK-LABEL: test8:
283 ; DARWIN: movl %esp, %ebp
284 ; DARWIN-NOT: .cfi_adjust_cfa_offset
286 define void @test8() #1 personality ptr @__gxx_personality_v0 {
288 invoke void @good(i32 1, i32 2, i32 3, i32 4)
289 to label %continue unwind label %cleanup
293 landingpad { ptr, i32 }
298 attributes #0 = { optsize }
299 attributes #1 = { optsize "frame-pointer"="all" }