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 sanity check to ensure statepoints are generating StackMap
5 ; sections correctly. This is not intended to be a rigorous test of the
6 ; 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(i32 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 i32 addrspace(1)*, i32 2, align 8
26 store i32 addrspace(1)* null, i32 addrspace(1)** %metadata1
27 %ptr_derived = getelementptr i32, i32 addrspace(1)* %ptr_base, i32 %arg
28 %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 2, i32 addrspace(1)* %ptr_base, i32 addrspace(1)* null, i32 addrspace(1)* %ptr_base, i32 addrspace(1)* %ptr_derived, i32 addrspace(1)* null)
29 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
30 %a = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 9, i32 9)
31 %b = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 9, i32 10)
32 %c = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 11, i32 11)
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(i32 addrspace(1)* %ptr_base,
41 i32 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 i32 addrspace(1)*, i32 2, align 8
55 store i32 addrspace(1)* null, i32 addrspace(1)** %metadata1
56 %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 2, i32 addrspace(1)* %ptr_base, i32 addrspace(1)* null, i32 addrspace(1)* %ptr_base, i32 addrspace(1)* %ptr_derived, i32 addrspace(1)* null)
57 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
58 %a = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 9, i32 9)
59 %b = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 9, i32 10)
60 %c = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 11, i32 11)
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, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 237, i32 0, 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(i32 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, void (i64, i64, i64, i64, i64, i64, i64, i64)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi64i64i64i64i64i64i64i64f(i64 0, i32 0, 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, i32 addrspace(1)* %p)
94 %p.relocated = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %statepoint_token, i32 15, i32 15) ; (%p, %p)
95 %ld = load i32, i32 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(%struct*)
106 define void @test_fixed_arg(%struct* byval %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, void (%struct*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp0s_structsf(i64 0, i32 0, void (%struct*)* @use, i32 1, i32 0, %struct* %x, i32 0, i32 1, %struct* %x)
123 declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
124 declare token @llvm.experimental.gc.statepoint.p0f_isVoidi64i64i64i64i64i64i64i64f(i64, i32, void (i64, i64, i64, i64, i64, i64, i64, i64)*, i32, i32, ...)
125 declare token @llvm.experimental.gc.statepoint.p0f_isVoidp0s_structsf(i64, i32, void (%struct*)*, i32, i32, ...)
126 declare i1 @llvm.experimental.gc.result.i1(token)
127 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) #3
129 ; CHECK-LABEL: .section .llvm_stackmaps
130 ; CHECK-NEXT: __LLVM_StackMaps:
132 ; CHECK-NEXT: .byte 3
133 ; CHECK-NEXT: .byte 0
134 ; CHECK-NEXT: .short 0
136 ; CHECK-NEXT: .long 5
138 ; CHECK-NEXT: .long 0
140 ; CHECK-NEXT: .long 5
142 ; Functions and stack size
143 ; CHECK-NEXT: .quad test
144 ; CHECK-NEXT: .quad 40
145 ; CHECK-NEXT: .quad 1
146 ; CHECK-NEXT: .quad test_derived_arg
147 ; CHECK-NEXT: .quad 40
148 ; CHECK-NEXT: .quad 1
149 ; CHECK-NEXT: .quad test_id
150 ; CHECK-NEXT: .quad 8
151 ; CHECK-NEXT: .quad 1
152 ; CHECK-NEXT: .quad test_spadj
153 ; CHECK-NEXT: .quad 8
154 ; CHECK-NEXT: .quad 1
155 ; CHECK-NEXT: .quad test_fixed_arg
156 ; CHECK-NEXT: .quad 8
157 ; CHECK-NEXT: .quad 1
164 ; CHECK-NEXT: .quad 0
168 ; CHECK-NEXT: .long .Ltmp0-test
173 ; CHECK-NEXT: .byte 0
176 ; CHECK-NEXT: .short 0
180 ; CHECK-NEXT: .byte 0
183 ; CHECK-NEXT: .short 0
187 ; CHECK-NEXT: .byte 0
190 ; CHECK-NEXT: .short 0
192 ; Indirect Spill Slot [RSP+0]
194 ; CHECK-NEXT: .byte 0
197 ; CHECK-NEXT: .short 0
201 ; CHECK-NEXT: .byte 0
204 ; CHECK-NEXT: .short 0
208 ; CHECK-NEXT: .byte 0
211 ; CHECK-NEXT: .short 0
215 ; CHECK-NEXT: .byte 0
218 ; CHECK-NEXT: .short 0
220 ; Indirect Spill Slot [RSP+16]
222 ; CHECK-NEXT: .byte 0
225 ; CHECK-NEXT: .short 0
227 ; Indirect Spill Slot [RSP+8]
229 ; CHECK-NEXT: .byte 0
232 ; CHECK-NEXT: .short 0
234 ; Indirect Spill Slot [RSP+16]
236 ; CHECK-NEXT: .byte 0
239 ; CHECK-NEXT: .short 0
241 ; Indirect Spill Slot [RSP+16]
243 ; CHECK-NEXT: .byte 0
246 ; CHECK-NEXT: .short 0
249 ; No Padding or LiveOuts
258 ; CHECK-NEXT: .quad 0
262 ; CHECK-NEXT: .long .Ltmp1-test_derived_arg
267 ; CHECK-NEXT: .byte 0
270 ; CHECK-NEXT: .short 0
274 ; CHECK-NEXT: .byte 0
277 ; CHECK-NEXT: .short 0
279 ; Indirect Spill Slot [RSP+0]
281 ; CHECK-NEXT: .byte 0
284 ; CHECK-NEXT: .short 0
288 ; CHECK-NEXT: .byte 0
291 ; CHECK-NEXT: .short 0
295 ; CHECK-NEXT: .byte 0
298 ; CHECK-NEXT: .short 0
302 ; CHECK-NEXT: .byte 0
305 ; CHECK-NEXT: .short 0
307 ; Indirect Spill Slot [RSP+16]
309 ; CHECK-NEXT: .byte 0
312 ; CHECK-NEXT: .short 0
314 ; Indirect Spill Slot [RSP+8]
316 ; CHECK-NEXT: .byte 0
319 ; CHECK-NEXT: .short 0
321 ; Indirect Spill Slot [RSP+16]
323 ; CHECK-NEXT: .byte 0
326 ; CHECK-NEXT: .short 0
328 ; Indirect Spill Slot [RSP+16]
330 ; CHECK-NEXT: .byte 0
333 ; CHECK-NEXT: .short 0
336 ; No Padding or LiveOuts
341 ; Records for the test_id function:
344 ; CHECK-NEXT: .quad 237
347 ; CHECK-NEXT: .long .Ltmp2-test_id
358 ; CHECK-NEXT: .byte 0
361 ; CHECK-NEXT: .short 0
367 ; CHECK-NEXT: .byte 0
370 ; CHECK-NEXT: .short 0
376 ; CHECK-NEXT: .byte 0
379 ; CHECK-NEXT: .short 0
382 ; No padding or LiveOuts
391 ; CHECK-NEXT: .quad 0
394 ; CHECK-NEXT: .long .Ltmp3-test_spadj
405 ; CHECK-NEXT: .byte 0
408 ; CHECK-NEXT: .short 0
414 ; CHECK-NEXT: .byte 0
417 ; CHECK-NEXT: .short 0
423 ; CHECK-NEXT: .byte 0
426 ; CHECK-NEXT: .short 0
430 ; Indirect Spill Slot [RSP+16]
432 ; CHECK-NEXT: .byte 0
435 ; CHECK-NEXT: .short 0
439 ; Indirect Spill Slot [RSP+16]
441 ; CHECK-NEXT: .byte 0
444 ; CHECK-NEXT: .short 0
447 ; No padding or LiveOuts
456 ; CHECK-NEXT: .quad 0
459 ; CHECK-NEXT: .long .Ltmp4-test_fixed_arg
470 ; CHECK-NEXT: .byte 0
473 ; CHECK-NEXT: .short 0
479 ; CHECK-NEXT: .byte 0
482 ; CHECK-NEXT: .short 0
488 ; CHECK-NEXT: .byte 0
491 ; CHECK-NEXT: .short 0
497 ; CHECK-NEXT: .byte 0
500 ; CHECK-NEXT: .short 0
503 ; No padding or LiveOuts