[StatepointLowering] Reuse stack slots across basic blocks
[oota-llvm.git] / test / CodeGen / X86 / statepoint-stack-usage.ll
1 ; RUN: llc < %s | FileCheck %s
2
3 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-pc-linux-gnu"
5
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: movq   %rdi, 16(%rsp)
15 ; CHECK: movq   %rdx, 8(%rsp)
16 ; CHECK: movq   %rsi, (%rsp)
17   %safepoint_token = tail call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c)
18   %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 12)
19   %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 13)
20   %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 14)
21 ; CHECK: callq
22 ; This is the key check.  There should NOT be any memory moves here
23 ; CHECK-NOT: movq
24   %safepoint_token2 = tail call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %c1, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1)
25   %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 14)
26   %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 13)
27   %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 12)
28 ; CHECK: callq
29   ret i32 1
30 }
31
32 ; This test simply checks that minor changes in vm state don't prevent slots
33 ; being reused for gc values.  
34 define i32 @reserve_first(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" {
35 ; CHECK-LABEL: reserve_first
36 ; The exact stores don't matter, but there need to be three stack slots created
37 ; CHECK: movq   %rdi, 16(%rsp)
38 ; CHECK: movq   %rdx, 8(%rsp)
39 ; CHECK: movq   %rsi, (%rsp)
40   %safepoint_token = tail call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c)
41   %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 12)
42   %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 13)
43   %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 14)
44 ; CHECK: callq
45 ; This is the key check.  There should NOT be any memory moves here
46 ; CHECK-NOT: movq
47   %safepoint_token2 = tail call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 addrspace(1)* %a1, i32 0, i32 addrspace(1)* %c1, i32 0, i32 0, i32 addrspace(1)* %c1, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1)
48   %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 14)
49   %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 13)
50   %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 12)
51 ; CHECK: callq
52   ret i32 1
53 }
54
55 ; Test that stack slots are reused for invokes
56 define i32 @back_to_back_invokes(i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c) #1 gc "statepoint-example" {
57 ; CHECK-LABEL: back_to_back_invokes
58 entry:
59   ; The exact stores don't matter, but there need to be three stack slots created
60   ; CHECK: movq %rdi, 16(%rsp)
61   ; CHECK: movq %rdx, 8(%rsp)
62   ; CHECK: movq %rsi, (%rsp)
63   ; CHECK: callq
64   %safepoint_token = invoke i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i32 addrspace(1)* %a, i32 addrspace(1)* %b, i32 addrspace(1)* %c)
65                    to label %normal_return unwind label %exceptional_return
66
67 normal_return:
68   %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 12)
69   %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 13)
70   %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 14)
71   ; Should work even through bitcasts
72   %c1.casted = bitcast i32 addrspace(1)* %c1 to i8 addrspace(1)*
73   ; This is the key check.  There should NOT be any memory moves here
74   ; CHECK-NOT: movq
75   ; CHECK: callq
76   %safepoint_token2 = invoke i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* undef, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0, i8 addrspace(1)* %c1.casted, i32 addrspace(1)* %b1, i32 addrspace(1)* %a1)
77                     to label %normal_return2 unwind label %exceptional_return2
78
79 normal_return2:
80   %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 14)
81   %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 13)
82   %c2 = tail call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %safepoint_token2, i32 12, i32 12)
83   ret i32 1
84
85 exceptional_return:
86   %landing_pad = landingpad { i8*, i32 } personality i32 ()* @"personality_function"
87           cleanup
88   ret i32 0
89
90 exceptional_return2:
91   %landing_pad2 = landingpad { i8*, i32 } personality i32 ()* @"personality_function"
92           cleanup
93   ret i32 0
94 }
95
96 ; Function Attrs: nounwind
97 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32) #3
98 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32, i32, i32) #3
99
100 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
101
102 declare i32 @"personality_function"()
103
104 attributes #1 = { uwtable }