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(ptr addrspace(1) %a, ptr addrspace(1) %b, ptr 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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %a, ptr addrspace(1) %b, ptr addrspace(1) %c), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
20 %a1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
21 %b1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 1)
22 %c1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %c1, ptr addrspace(1) %b1, ptr addrspace(1) %a1), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
27 %a2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 2)
28 %b2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 1)
29 %c2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(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(ptr addrspace(1) %a, ptr addrspace(1) %b, ptr 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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %a, ptr addrspace(1) %b, ptr addrspace(1) %c), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
43 %a1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
44 %b1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 1)
45 %c1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %c1, ptr addrspace(1) %b1, ptr addrspace(1) %a1), "deopt" (ptr addrspace(1) %a1, i32 0, ptr addrspace(1) %c1, i32 0, i32 0)]
50 %a2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 2)
51 %b2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 1)
52 %c2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(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 %r14d, 12(%rsp)
69 ; CHECK-DAG: movl %ebp, 8(%rsp)
70 ; CHECK-DAG: movl %ebx, 4(%rsp)
72 ; CHECK-DAG: movl %r14d, 12(%rsp)
73 ; CHECK-DAG: movl %ebp, 8(%rsp)
74 ; CHECK-DAG: movl %ebx, 4(%rsp)
76 ; CHECK-DAG: movl %r14d, 12(%rsp)
77 ; CHECK-DAG: movl %ebp, 8(%rsp)
78 ; CHECK-DAG: movl %ebx, 4(%rsp)
80 call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
81 call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
82 call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["deopt" (i32 %a, i32 %b, i32 %c)]
83 call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(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(ptr addrspace(1) %a, ptr addrspace(1) %b, ptr addrspace(1) %c) #1 gc "statepoint-example" personality ptr @"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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %a, ptr addrspace(1) %b, ptr 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 ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
101 %b1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 1)
102 %c1 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 2)
103 ; Should work even through bitcasts
104 ; This is the key check. There should NOT be any memory moves here
107 %safepoint_token2 = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %c1, ptr addrspace(1) %b1, ptr addrspace(1) %a1), "deopt" (i32 0, i32 -1, i32 0, i32 0, i32 0)]
108 to label %normal_return2 unwind label %exceptional_return2
111 %a2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 2)
112 %b2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 1)
113 %c2 = tail call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 0)
117 %landing_pad = landingpad { ptr, i32 }
122 %landing_pad2 = landingpad { ptr, i32 }
127 ; Function Attrs: nounwind
128 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32) #3
130 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
132 declare i32 @"personality_function"()
134 attributes #1 = { uwtable }