1 ; RUN: llc -verify-machineinstrs -stack-symbol-ordering=0 < %s | FileCheck %s
3 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-pc-linux-gnu"
6 ; This test is checking to make sure that we reuse the same stack slots
7 ; for GC values spilled over two different call sites. Since the order
8 ; of GC arguments differ, niave lowering code would insert loads and
9 ; stores to rearrange items on the stack. We need to make sure (for
10 ; performance) that this doesn't happen.
11 define i32 @back_to_back_calls(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" {
12 ; CHECK-LABEL: back_to_back_calls
13 ; The exact stores don't matter, but there need to be three stack slots created
14 ; CHECK-DAG: movq %rdi, {{[0-9]*}}(%rsp)
15 ; CHECK-DAG: movq %rdx, {{[0-9]*}}(%rsp)
16 ; CHECK-DAG: movq %rsi, {{[0-9]*}}(%rsp)
17 ; There should be no more than three moves
19 %safepoint_token = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
20 %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 0)
21 %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 1)
22 %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 2)
24 ; This is the key check. There should NOT be any memory moves here
26 %safepoint_token2 = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (i32 addrspace(1)* %c1, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
27 %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 2)
28 %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 1)
29 %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 0)
34 ; This test simply checks that minor changes in vm state don't prevent slots
35 ; being reused for gc values.
36 define i32 @reserve_first(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" {
37 ; CHECK-LABEL: reserve_first
38 ; The exact stores don't matter, but there need to be three stack slots created
39 ; CHECK-DAG: movq %rdi, {{[0-9]*}}(%rsp)
40 ; CHECK-DAG: movq %rdx, {{[0-9]*}}(%rsp)
41 ; CHECK-DAG: movq %rsi, {{[0-9]*}}(%rsp)
42 %safepoint_token = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
43 %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 0)
44 %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 1)
45 %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 2)
47 ; This is the key check. There should NOT be any memory moves here
49 %safepoint_token2 = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (i32 addrspace(1)* %c1, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1), "deopt" (i32 addrspace(1)* %a1, i32 0, i32 addrspace(1)* %c1, i32 0, i32 0)]
50 %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 2)
51 %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 1)
52 %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 0)
57 ; Check that we reuse the same stack slot across multiple calls. The use of
58 ; more than two calls here is critical. We've had a bug which allowed reuse
59 ; exactly once which went undetected for a long time.
60 define i32 @back_to_back_deopt(i32 %a, i32 %b, i32 %c) #1
61 gc "statepoint-example" {
62 ; CHECK-LABEL: back_to_back_deopt
63 ; The exact stores don't matter, but there need to be three stack slots created
64 ; CHECK-DAG: movl %edi, 12(%rsp)
65 ; CHECK-DAG: movl %esi, 8(%rsp)
66 ; CHECK-DAG: movl %edx, 4(%rsp)
68 ; CHECK-DAG: movl %ebx, 12(%rsp)
69 ; CHECK-DAG: movl %ebp, 8(%rsp)
70 ; CHECK-DAG: movl %r14d, 4(%rsp)
72 ; CHECK-DAG: movl %ebx, 12(%rsp)
73 ; CHECK-DAG: movl %ebp, 8(%rsp)
74 ; CHECK-DAG: movl %r14d, 4(%rsp)
76 ; CHECK-DAG: movl %ebx, 12(%rsp)
77 ; CHECK-DAG: movl %ebp, 8(%rsp)
78 ; CHECK-DAG: movl %r14d, 4(%rsp)
80 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
81 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
82 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
83 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
87 ; Test that stack slots are reused for invokes
88 define i32 @back_to_back_invokes(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" personality i32 ()* @"personality_function" {
89 ; CHECK-LABEL: back_to_back_invokes
91 ; The exact stores don't matter, but there need to be three stack slots created
92 ; CHECK-DAG: movq %rdi, {{[0-9]*}}(%rsp)
93 ; CHECK-DAG: movq %rdx, {{[0-9]*}}(%rsp)
94 ; CHECK-DAG: movq %rsi, {{[0-9]*}}(%rsp)
96 %safepoint_token = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
97 to label %normal_return unwind label %exceptional_return
100 %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 0)
101 %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 1)
102 %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 0, i32 2)
103 ; Should work even through bitcasts
104 %c1.casted = bitcast i32 addrspace(1)* %c1 to i8 addrspace(1)*
105 ; This is the key check. There should NOT be any memory moves here
108 %safepoint_token2 = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (i8 addrspace(1)* %c1.casted, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
109 to label %normal_return2 unwind label %exceptional_return2
112 %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 2)
113 %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 0, i32 1)
114 %c2 = tail call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token2, i32 0, i32 0)
118 %landing_pad = landingpad { i8*, i32 }
123 %landing_pad2 = landingpad { i8*, i32 }
128 ; Function Attrs: nounwind
129 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) #3
130 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32) #3
132 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
134 declare i32 @"personality_function"()
136 attributes #1 = { uwtable }