1 ; RUN: llc < %s -verify-machineinstrs -stack-symbol-ordering=0 -mtriple="x86_64-pc-linux-gnu" | FileCheck %s
2 ; RUN: llc < %s -verify-machineinstrs -stack-symbol-ordering=0 -mtriple="x86_64-pc-unknown-elf" | FileCheck %s
4 ; This test is a basic correctness check to ensure statepoints are generating
5 ; StackMap sections correctly. This is not intended to be a rigorous test of
6 ; the StackMap format (see the stackmap tests for that).
8 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
10 declare zeroext i1 @return_i1()
12 define i1 @test(ptr addrspace(1) %ptr_base, i32 %arg)
13 gc "statepoint-example" {
15 ; Do we see two spills for the local values and the store to the
17 ; CHECK: subq $40, %rsp
18 ; CHECK: movq $0, 24(%rsp)
19 ; CHECK: movq %rdi, 16(%rsp)
20 ; CHECK: movq %rax, 8(%rsp)
21 ; CHECK: callq return_i1
22 ; CHECK: addq $40, %rsp
25 %metadata1 = alloca ptr addrspace(1), i32 2, align 8
26 store ptr addrspace(1) null, ptr %metadata1
27 %ptr_derived = getelementptr i32, ptr addrspace(1) %ptr_base, i32 %arg
28 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %ptr_base, ptr addrspace(1) %ptr_derived, ptr addrspace(1) null), "deopt" (ptr addrspace(1) %ptr_base, ptr addrspace(1) null)]
29 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
30 %a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
31 %b = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 1)
32 %c = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 2, i32 2)
37 ; This is similar to the previous test except that we have derived pointer as
38 ; argument to the function. Despite that this can not happen after the
39 ; RewriteSafepointForGC pass, lowering should be able to handle it anyway.
40 define i1 @test_derived_arg(ptr addrspace(1) %ptr_base,
41 ptr addrspace(1) %ptr_derived)
42 gc "statepoint-example" {
43 ; CHECK-LABEL: test_derived_arg
44 ; Do we see two spills for the local values and the store to the
46 ; CHECK: subq $40, %rsp
47 ; CHECK: movq $0, 24(%rsp)
48 ; CHECK: movq %rdi, 16(%rsp)
49 ; CHECK: movq %rsi, 8(%rsp)
50 ; CHECK: callq return_i1
51 ; CHECK: addq $40, %rsp
54 %metadata1 = alloca ptr addrspace(1), i32 2, align 8
55 store ptr addrspace(1) null, ptr %metadata1
56 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %ptr_base, ptr addrspace(1) %ptr_derived, ptr addrspace(1) null), "deopt" (ptr addrspace(1) %ptr_base, ptr addrspace(1) null)]
57 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
58 %a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
59 %b = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 1)
60 %c = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 2, i32 2)
65 ; Simple test case to check that we emit the ID field correctly
66 define i1 @test_id() gc "statepoint-example" {
67 ; CHECK-LABEL: test_id
69 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 237, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0)
70 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
74 ; This test checks that when SP is changed in the function
75 ; (e.g. passing arguments on stack), the stack map entry
76 ; takes this adjustment into account.
77 declare void @many_arg(i64, i64, i64, i64, i64, i64, i64, i64)
79 define i32 @test_spadj(ptr addrspace(1) %p) gc "statepoint-example" {
80 ; CHECK-LABEL: test_spadj
81 ; CHECK: movq %rdi, (%rsp)
82 ; CHECK: xorl %edi, %edi
83 ; CHECK: xorl %esi, %esi
84 ; CHECK: xorl %edx, %edx
85 ; CHECK: xorl %ecx, %ecx
86 ; CHECK: xorl %r8d, %r8d
87 ; CHECK: xorl %r9d, %r9d
90 ; CHECK: callq many_arg
91 ; CHECK: addq $16, %rsp
93 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (i64, i64, i64, i64, i64, i64, i64, i64)) @many_arg, i32 8, i32 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %p)]
94 %p.relocated = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%p, %p)
95 %ld = load i32, ptr addrspace(1) %p.relocated
99 ; Test that function arguments at fixed stack offset
100 ; can be directly encoded in the stack map, without
102 %struct = type { i64, i64, i64 }
104 declare void @use(ptr)
106 define void @test_fixed_arg(ptr byval(%struct) %x) gc "statepoint-example" {
107 ; CHECK-LABEL: test_fixed_arg
109 ; CHECK: leaq 16(%rsp), %rdi
110 ; Should not spill fixed stack address.
111 ; CHECK-NOT: movq %rdi, (%rsp)
119 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (ptr)) @use, i32 1, i32 0, ptr %x, i32 0, i32 0) ["deopt" (ptr %x)]
123 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
124 declare i1 @llvm.experimental.gc.result.i1(token)
125 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32) #3
127 ; CHECK-LABEL: .section .llvm_stackmaps
128 ; CHECK-NEXT: __LLVM_StackMaps:
130 ; CHECK-NEXT: .byte 3
131 ; CHECK-NEXT: .byte 0
132 ; CHECK-NEXT: .short 0
134 ; CHECK-NEXT: .long 5
136 ; CHECK-NEXT: .long 0
138 ; CHECK-NEXT: .long 5
140 ; Functions and stack size
141 ; CHECK-NEXT: .quad test
142 ; CHECK-NEXT: .quad 40
143 ; CHECK-NEXT: .quad 1
144 ; CHECK-NEXT: .quad test_derived_arg
145 ; CHECK-NEXT: .quad 40
146 ; CHECK-NEXT: .quad 1
147 ; CHECK-NEXT: .quad test_id
148 ; CHECK-NEXT: .quad 8
149 ; CHECK-NEXT: .quad 1
150 ; CHECK-NEXT: .quad test_spadj
151 ; CHECK-NEXT: .quad 8
152 ; CHECK-NEXT: .quad 1
153 ; CHECK-NEXT: .quad test_fixed_arg
154 ; CHECK-NEXT: .quad 8
155 ; CHECK-NEXT: .quad 1
162 ; CHECK-NEXT: .quad 0
166 ; CHECK-NEXT: .long .Ltmp0-test
171 ; CHECK-NEXT: .byte 0
174 ; CHECK-NEXT: .short 0
178 ; CHECK-NEXT: .byte 0
181 ; CHECK-NEXT: .short 0
185 ; CHECK-NEXT: .byte 0
188 ; CHECK-NEXT: .short 0
190 ; Indirect Spill Slot [RSP+0]
192 ; CHECK-NEXT: .byte 0
195 ; CHECK-NEXT: .short 0
199 ; CHECK-NEXT: .byte 0
202 ; CHECK-NEXT: .short 0
206 ; CHECK-NEXT: .byte 0
209 ; CHECK-NEXT: .short 0
213 ; CHECK-NEXT: .byte 0
216 ; CHECK-NEXT: .short 0
218 ; Indirect Spill Slot [RSP+16]
220 ; CHECK-NEXT: .byte 0
223 ; CHECK-NEXT: .short 0
225 ; Indirect Spill Slot [RSP+8]
227 ; CHECK-NEXT: .byte 0
230 ; CHECK-NEXT: .short 0
232 ; Indirect Spill Slot [RSP+16]
234 ; CHECK-NEXT: .byte 0
237 ; CHECK-NEXT: .short 0
239 ; Indirect Spill Slot [RSP+16]
241 ; CHECK-NEXT: .byte 0
244 ; CHECK-NEXT: .short 0
247 ; No Padding or LiveOuts
256 ; CHECK-NEXT: .quad 0
260 ; CHECK-NEXT: .long .Ltmp1-test_derived_arg
265 ; CHECK-NEXT: .byte 0
268 ; CHECK-NEXT: .short 0
272 ; CHECK-NEXT: .byte 0
275 ; CHECK-NEXT: .short 0
277 ; Indirect Spill Slot [RSP+0]
279 ; CHECK-NEXT: .byte 0
282 ; CHECK-NEXT: .short 0
286 ; CHECK-NEXT: .byte 0
289 ; CHECK-NEXT: .short 0
293 ; CHECK-NEXT: .byte 0
296 ; CHECK-NEXT: .short 0
300 ; CHECK-NEXT: .byte 0
303 ; CHECK-NEXT: .short 0
305 ; Indirect Spill Slot [RSP+16]
307 ; CHECK-NEXT: .byte 0
310 ; CHECK-NEXT: .short 0
312 ; Indirect Spill Slot [RSP+8]
314 ; CHECK-NEXT: .byte 0
317 ; CHECK-NEXT: .short 0
319 ; Indirect Spill Slot [RSP+16]
321 ; CHECK-NEXT: .byte 0
324 ; CHECK-NEXT: .short 0
326 ; Indirect Spill Slot [RSP+16]
328 ; CHECK-NEXT: .byte 0
331 ; CHECK-NEXT: .short 0
334 ; No Padding or LiveOuts
339 ; Records for the test_id function:
342 ; CHECK-NEXT: .quad 237
345 ; CHECK-NEXT: .long .Ltmp2-test_id
356 ; CHECK-NEXT: .byte 0
359 ; CHECK-NEXT: .short 0
365 ; CHECK-NEXT: .byte 0
368 ; CHECK-NEXT: .short 0
374 ; CHECK-NEXT: .byte 0
377 ; CHECK-NEXT: .short 0
380 ; No padding or LiveOuts
389 ; CHECK-NEXT: .quad 0
392 ; CHECK-NEXT: .long .Ltmp3-test_spadj
403 ; CHECK-NEXT: .byte 0
406 ; CHECK-NEXT: .short 0
412 ; CHECK-NEXT: .byte 0
415 ; CHECK-NEXT: .short 0
421 ; CHECK-NEXT: .byte 0
424 ; CHECK-NEXT: .short 0
428 ; Indirect Spill Slot [RSP+16]
430 ; CHECK-NEXT: .byte 0
433 ; CHECK-NEXT: .short 0
437 ; Indirect Spill Slot [RSP+16]
439 ; CHECK-NEXT: .byte 0
442 ; CHECK-NEXT: .short 0
445 ; No padding or LiveOuts
454 ; CHECK-NEXT: .quad 0
457 ; CHECK-NEXT: .long .Ltmp4-test_fixed_arg
468 ; CHECK-NEXT: .byte 0
471 ; CHECK-NEXT: .short 0
477 ; CHECK-NEXT: .byte 0
480 ; CHECK-NEXT: .short 0
486 ; CHECK-NEXT: .byte 0
489 ; CHECK-NEXT: .short 0
495 ; CHECK-NEXT: .byte 0
498 ; CHECK-NEXT: .short 0
501 ; No padding or LiveOuts