llvm-intrinsics.ll
8.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
; RUN: llc < %s -march=xcore | FileCheck %s
; RUN: llc < %s -march=xcore -frame-pointer=all | FileCheck %s -check-prefix=CHECKFP
declare i8* @llvm.frameaddress(i32) nounwind readnone
declare i8* @llvm.returnaddress(i32) nounwind
declare i8* @llvm.eh.dwarf.cfa(i32) nounwind
declare void @llvm.eh.return.i32(i32, i8*) nounwind
declare void @llvm.eh.unwind.init() nounwind
define i8* @FA0() nounwind {
entry:
; CHECK-LABEL: FA0
; CHECK: ldaw r0, sp[0]
; CHECK-NEXT: retsp 0
%0 = call i8* @llvm.frameaddress(i32 0)
ret i8* %0
}
define i8* @FA1() nounwind {
entry:
; CHECK-LABEL: FA1
; CHECK: entsp 100
; CHECK-NEXT: ldaw r0, sp[0]
; CHECK-NEXT: retsp 100
%0 = alloca [100 x i32]
%1 = call i8* @llvm.frameaddress(i32 0)
ret i8* %1
}
define i8* @RA0() nounwind {
entry:
; CHECK-LABEL: RA0
; CHECK: stw lr, sp[0]
; CHECK-NEXT: ldw r0, sp[0]
; CHECK-NEXT: ldw lr, sp[0]
; CHECK-NEXT: retsp 0
%0 = call i8* @llvm.returnaddress(i32 0)
ret i8* %0
}
define i8* @RA1() nounwind {
entry:
; CHECK-LABEL: RA1
; CHECK: entsp 100
; CHECK-NEXT: ldw r0, sp[100]
; CHECK-NEXT: retsp 100
%0 = alloca [100 x i32]
%1 = call i8* @llvm.returnaddress(i32 0)
ret i8* %1
}
; test FRAME_TO_ARGS_OFFSET lowering
define i8* @FTAO0() nounwind {
entry:
; CHECK-LABEL: FTAO0
; CHECK: ldc r0, 0
; CHECK-NEXT: ldaw r1, sp[0]
; CHECK-NEXT: add r0, r1, r0
; CHECK-NEXT: retsp 0
%0 = call i8* @llvm.eh.dwarf.cfa(i32 0)
ret i8* %0
}
define i8* @FTAO1() nounwind {
entry:
; CHECK-LABEL: FTAO1
; CHECK: entsp 100
; CHECK-NEXT: ldc r0, 400
; CHECK-NEXT: ldaw r1, sp[0]
; CHECK-NEXT: add r0, r1, r0
; CHECK-NEXT: retsp 100
%0 = alloca [100 x i32]
%1 = call i8* @llvm.eh.dwarf.cfa(i32 0)
ret i8* %1
}
define i8* @EH0(i32 %offset, i8* %handler) {
entry:
; CHECK-LABEL: EH0
; CHECK: entsp 2
; CHECK: .cfi_def_cfa_offset 8
; CHECK: .cfi_offset 15, 0
; CHECK: .cfi_offset 1, -8
; CHECK: .cfi_offset 0, -4
; CHECK: ldc r2, 8
; CHECK-NEXT: ldaw r3, sp[0]
; CHECK-NEXT: add r2, r3, r2
; CHECK-NEXT: add r2, r2, r0
; CHECK-NEXT: mov r3, r1
; CHECK-NEXT: ldw r1, sp[0]
; CHECK-NEXT: ldw r0, sp[1]
; CHECK-NEXT: set sp, r2
; CHECK-NEXT: bau r3
call void @llvm.eh.return.i32(i32 %offset, i8* %handler)
unreachable
}
declare void @foo(...)
define i8* @EH1(i32 %offset, i8* %handler) {
entry:
; CHECK-LABEL: EH1
; CHECK: entsp 5
; CHECK: .cfi_def_cfa_offset 20
; CHECK: .cfi_offset 15, 0
; CHECK: .cfi_offset 1, -16
; CHECK: .cfi_offset 0, -12
; CHECK: stw r4, sp[4]
; CHECK: .cfi_offset 4, -4
; CHECK: stw r5, sp[3]
; CHECK: .cfi_offset 5, -8
; CHECK: mov r4, r1
; CHECK-NEXT: mov r5, r0
; CHECK-NEXT: bl foo
; CHECK-NEXT: ldc r0, 20
; CHECK-NEXT: ldaw r1, sp[0]
; CHECK-NEXT: add r0, r1, r0
; CHECK-NEXT: add r2, r0, r5
; CHECK-NEXT: mov r3, r4
; CHECK-NEXT: ldw r5, sp[3]
; CHECK-NEXT: ldw r4, sp[4]
; CHECK-NEXT: ldw r1, sp[1]
; CHECK-NEXT: ldw r0, sp[2]
; CHECK-NEXT: set sp, r2
; CHECK-NEXT: bau r3
call void (...) @foo()
call void @llvm.eh.return.i32(i32 %offset, i8* %handler)
unreachable
}
@offset = external constant i32
@handler = external constant i8
define i8* @EH2(i32 %r0, i32 %r1, i32 %r2, i32 %r3) {
entry:
; CHECK-LABEL: EH2
; CHECK: entsp 3
; CHECK: bl foo
; CHECK-NEXT: ldw r0, dp[offset]
; CHECK-NEXT: ldc r1, 12
; CHECK-NEXT: ldaw r2, sp[0]
; CHECK-NEXT: add r1, r2, r1
; CHECK-NEXT: add r2, r1, r0
; CHECK-NEXT: ldaw r3, dp[handler]
; CHECK-NEXT: ldw r1, sp[1]
; CHECK-NEXT: ldw r0, sp[2]
; CHECK-NEXT: set sp, r2
; CHECK-NEXT: bau r3
call void (...) @foo()
%0 = load i32, i32* @offset
call void @llvm.eh.return.i32(i32 %0, i8* @handler)
unreachable
}
; FP: spill FP+SR+R0:1+R4:9 = entsp 2+2+6
; But we dont actually spill or restore R0:1
; CHECKFP-LABEL: Unwind0:
; CHECKFP: entsp 10
; CHECKFP: stw r10, sp[1]
; CHECKFP: ldaw r10, sp[0]
; CHECKFP: stw r4, r10[9]
; CHECKFP: stw r5, r10[8]
; CHECKFP: stw r6, r10[7]
; CHECKFP: stw r7, r10[6]
; CHECKFP: stw r8, r10[5]
; CHECKFP: stw r9, r10[4]
; CHECKFP: ldw r9, r10[4]
; CHECKFP: ldw r8, r10[5]
; CHECKFP: ldw r7, r10[6]
; CHECKFP: ldw r6, r10[7]
; CHECKFP: ldw r5, r10[8]
; CHECKFP: ldw r4, r10[9]
; CHECKFP: set sp, r10
; CHECKFP: ldw r10, sp[1]
; CHECKFP: retsp 10
;
; !FP: spill R0:1+R4:10 = entsp 2+7
; But we dont actually spill or restore R0:1
; CHECK-LABEL: Unwind0:
; CHECK: entsp 9
; CHECK: stw r4, sp[8]
; CHECK: stw r5, sp[7]
; CHECK: stw r6, sp[6]
; CHECK: stw r7, sp[5]
; CHECK: stw r8, sp[4]
; CHECK: stw r9, sp[3]
; CHECK: stw r10, sp[2]
; CHECK: ldw r10, sp[2]
; CHECK: ldw r9, sp[3]
; CHECK: ldw r8, sp[4]
; CHECK: ldw r7, sp[5]
; CHECK: ldw r6, sp[6]
; CHECK: ldw r5, sp[7]
; CHECK: ldw r4, sp[8]
; CHECK: retsp 9
define void @Unwind0() {
call void @llvm.eh.unwind.init()
ret void
}
; FP: spill FP+SR+R0:1+R4:9+LR = entsp 2+2+6 + extsp 1
; But we dont actually spill or restore R0:1
; CHECKFP-LABEL: Unwind1:
; CHECKFP: entsp 10
; CHECKFP: stw r10, sp[1]
; CHECKFP: ldaw r10, sp[0]
; CHECKFP: stw r4, r10[9]
; CHECKFP: stw r5, r10[8]
; CHECKFP: stw r6, r10[7]
; CHECKFP: stw r7, r10[6]
; CHECKFP: stw r8, r10[5]
; CHECKFP: stw r9, r10[4]
; CHECKFP: extsp 1
; CHECKFP: bl foo
; CHECKFP: ldaw sp, sp[1]
; CHECKFP: ldw r9, r10[4]
; CHECKFP: ldw r8, r10[5]
; CHECKFP: ldw r7, r10[6]
; CHECKFP: ldw r6, r10[7]
; CHECKFP: ldw r5, r10[8]
; CHECKFP: ldw r4, r10[9]
; CHECKFP: set sp, r10
; CHECKFP: ldw r10, sp[1]
; CHECKFP: retsp 10
;
; !FP: spill R0:1+R4:10+LR = entsp 2+7+1
; But we dont actually spill or restore R0:1
; CHECK-LABEL: Unwind1:
; CHECK: entsp 10
; CHECK: stw r4, sp[9]
; CHECK: stw r5, sp[8]
; CHECK: stw r6, sp[7]
; CHECK: stw r7, sp[6]
; CHECK: stw r8, sp[5]
; CHECK: stw r9, sp[4]
; CHECK: stw r10, sp[3]
; CHECK: bl foo
; CHECK: ldw r10, sp[3]
; CHECK: ldw r9, sp[4]
; CHECK: ldw r8, sp[5]
; CHECK: ldw r7, sp[6]
; CHECK: ldw r6, sp[7]
; CHECK: ldw r5, sp[8]
; CHECK: ldw r4, sp[9]
; CHECK: retsp 10
define void @Unwind1() {
call void (...) @foo()
call void @llvm.eh.unwind.init()
ret void
}
; FP: spill FP+SR+R0:1+R4:9 = entsp 2+2+6
; We dont spill R0:1
; We only restore R0:1 during eh.return
; CHECKFP-LABEL: UnwindEH:
; CHECKFP: entsp 10
; CHECKFP: .cfi_def_cfa_offset 40
; CHECKFP: .cfi_offset 15, 0
; CHECKFP: stw r10, sp[1]
; CHECKFP: .cfi_offset 10, -36
; CHECKFP: ldaw r10, sp[0]
; CHECKFP: .cfi_def_cfa_register 10
; CHECKFP: .cfi_offset 1, -32
; CHECKFP: .cfi_offset 0, -28
; CHECKFP: stw r4, r10[9]
; CHECKFP: .cfi_offset 4, -4
; CHECKFP: stw r5, r10[8]
; CHECKFP: .cfi_offset 5, -8
; CHECKFP: stw r6, r10[7]
; CHECKFP: .cfi_offset 6, -12
; CHECKFP: stw r7, r10[6]
; CHECKFP: .cfi_offset 7, -16
; CHECKFP: stw r8, r10[5]
; CHECKFP: .cfi_offset 8, -20
; CHECKFP: stw r9, r10[4]
; CHECKFP: .cfi_offset 9, -24
; CHECKFP: bt r0, .LBB{{[0-9_]+}}
; CHECKFP: ldw r9, r10[4]
; CHECKFP-NEXT: ldw r8, r10[5]
; CHECKFP-NEXT: ldw r7, r10[6]
; CHECKFP-NEXT: ldw r6, r10[7]
; CHECKFP-NEXT: ldw r5, r10[8]
; CHECKFP-NEXT: ldw r4, r10[9]
; CHECKFP-NEXT: set sp, r10
; CHECKFP-NEXT: ldw r10, sp[1]
; CHECKFP-NEXT: retsp 10
; CHECKFP: .LBB{{[0-9_]+}}
; CHECKFP-NEXT: ldc r2, 40
; CHECKFP-NEXT: add r2, r10, r2
; CHECKFP-NEXT: add r2, r2, r0
; CHECKFP-NEXT: mov r3, r1
; CHECKFP-NEXT: ldw r9, r10[4]
; CHECKFP-NEXT: ldw r8, r10[5]
; CHECKFP-NEXT: ldw r7, r10[6]
; CHECKFP-NEXT: ldw r6, r10[7]
; CHECKFP-NEXT: ldw r5, r10[8]
; CHECKFP-NEXT: ldw r4, r10[9]
; CHECKFP-NEXT: ldw r1, sp[2]
; CHECKFP-NEXT: ldw r0, sp[3]
; CHECKFP-NEXT: set sp, r2
; CHECKFP-NEXT: bau r3
;
; !FP: spill R0:1+R4:10 = entsp 2+7
; We dont spill R0:1
; We only restore R0:1 during eh.return
; CHECK-LABEL: UnwindEH:
; CHECK: entsp 9
; CHECK: .cfi_def_cfa_offset 36
; CHECK: .cfi_offset 15, 0
; CHECK: .cfi_offset 1, -36
; CHECK: .cfi_offset 0, -32
; CHECK: stw r4, sp[8]
; CHECK: .cfi_offset 4, -4
; CHECK: stw r5, sp[7]
; CHECK: .cfi_offset 5, -8
; CHECK: stw r6, sp[6]
; CHECK: .cfi_offset 6, -12
; CHECK: stw r7, sp[5]
; CHECK: .cfi_offset 7, -16
; CHECK: stw r8, sp[4]
; CHECK: .cfi_offset 8, -20
; CHECK: stw r9, sp[3]
; CHECK: .cfi_offset 9, -24
; CHECK: stw r10, sp[2]
; CHECK: .cfi_offset 10, -28
; CHECK: bt r0, .LBB{{[0-9_]+}}
; CHECK: ldw r10, sp[2]
; CHECK-NEXT: ldw r9, sp[3]
; CHECK-NEXT: ldw r8, sp[4]
; CHECK-NEXT: ldw r7, sp[5]
; CHECK-NEXT: ldw r6, sp[6]
; CHECK-NEXT: ldw r5, sp[7]
; CHECK-NEXT: ldw r4, sp[8]
; CHECK-NEXT: retsp 9
; CHECK: .LBB{{[0-9_]+}}
; CHECK-NEXT: ldc r2, 36
; CHECK-NEXT: ldaw r3, sp[0]
; CHECK-NEXT: add r2, r3, r2
; CHECK-NEXT: add r2, r2, r0
; CHECK-NEXT: mov r3, r1
; CHECK-NEXT: ldw r10, sp[2]
; CHECK-NEXT: ldw r9, sp[3]
; CHECK-NEXT: ldw r8, sp[4]
; CHECK-NEXT: ldw r7, sp[5]
; CHECK-NEXT: ldw r6, sp[6]
; CHECK-NEXT: ldw r5, sp[7]
; CHECK-NEXT: ldw r4, sp[8]
; CHECK-NEXT: ldw r1, sp[0]
; CHECK-NEXT: ldw r0, sp[1]
; CHECK-NEXT: set sp, r2
; CHECK-NEXT: bau r3
define void @UnwindEH(i32 %offset, i8* %handler) {
call void @llvm.eh.unwind.init()
%cmp = icmp eq i32 %offset, 0
br i1 %cmp, label %normal, label %eh
eh:
call void @llvm.eh.return.i32(i32 %offset, i8* %handler)
unreachable
normal:
ret void
}