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 ; There should be no more than three moves 18 ; CHECK-NOT: movq 19 %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) 20 %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 12) 21 %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 13) 22 %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 14) 23 ; CHECK: callq 24 ; This is the key check. There should NOT be any memory moves here 25 ; CHECK-NOT: movq 26 %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) 27 %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 14) 28 %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 13) 29 %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 12) 30 ; CHECK: callq 31 ret i32 1 32 } 33 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: movq %rdi, 16(%rsp) 40 ; CHECK: movq %rdx, 8(%rsp) 41 ; CHECK: movq %rsi, (%rsp) 42 %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) 43 %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 12) 44 %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 13) 45 %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 14) 46 ; CHECK: callq 47 ; This is the key check. There should NOT be any memory moves here 48 ; CHECK-NOT: movq 49 %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) 50 %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 14) 51 %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 13) 52 %c2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 12) 53 ; CHECK: callq 54 ret i32 1 55 } 56 57 ; Test that stack slots are reused for invokes 58 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" { 59 ; CHECK-LABEL: back_to_back_invokes 60 entry: 61 ; The exact stores don't matter, but there need to be three stack slots created 62 ; CHECK: movq %rdi, 16(%rsp) 63 ; CHECK: movq %rdx, 8(%rsp) 64 ; CHECK: movq %rsi, (%rsp) 65 ; CHECK: callq 66 %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) 67 to label %normal_return unwind label %exceptional_return 68 69 normal_return: 70 %a1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 12) 71 %b1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 13) 72 %c1 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token, i32 12, i32 14) 73 ; Should work even through bitcasts 74 %c1.casted = bitcast i32 addrspace(1)* %c1 to i8 addrspace(1)* 75 ; This is the key check. There should NOT be any memory moves here 76 ; CHECK-NOT: movq 77 ; CHECK: callq 78 %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) 79 to label %normal_return2 unwind label %exceptional_return2 80 81 normal_return2: 82 %a2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 14) 83 %b2 = tail call coldcc i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %safepoint_token2, i32 12, i32 13) 84 %c2 = tail call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32 %safepoint_token2, i32 12, i32 12) 85 ret i32 1 86 87 exceptional_return: 88 %landing_pad = landingpad { i8*, i32 } 89 cleanup 90 ret i32 0 91 92 exceptional_return2: 93 %landing_pad2 = landingpad { i8*, i32 } 94 cleanup 95 ret i32 0 96 } 97 98 ; Function Attrs: nounwind 99 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32) #3 100 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(i32, i32, i32) #3 101 102 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) 103 104 declare i32 @"personality_function"() 105 106 attributes #1 = { uwtable } 107