1 ; RUN: llc -verify-machineinstrs < %s | FileCheck %s 2 ; This file contains a collection of basic tests to ensure we didn't 3 ; screw up normal call lowering when a statepoint is a GC transition. 4 5 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128" 6 target triple = "x86_64-pc-linux-gnu" 7 8 declare zeroext i1 @return_i1() 9 declare zeroext i32 @return_i32() 10 declare zeroext i32 @return_i32_with_args(i32, i8*) 11 declare i32* @return_i32ptr() 12 declare float @return_float() 13 declare void @varargf(i32, ...) 14 15 define i1 @test_i1_return() gc "statepoint-example" { 16 ; CHECK-LABEL: test_i1_return 17 ; This is just checking that a i1 gets lowered normally when there's no extra 18 ; state arguments to the statepoint 19 ; CHECK: pushq %rax 20 ; CHECK: callq return_i1 21 ; CHECK: popq %rcx 22 ; CHECK: retq 23 entry: 24 %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 1, i32 0, i32 0) 25 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token) 26 ret i1 %call1 27 } 28 29 define i32 @test_i32_return() gc "statepoint-example" { 30 ; CHECK-LABEL: test_i32_return 31 ; CHECK: pushq %rax 32 ; CHECK: callq return_i32 33 ; CHECK: popq %rcx 34 ; CHECK: retq 35 entry: 36 %safepoint_token = tail call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 0, i32 0, i32 ()* @return_i32, i32 0, i32 1, i32 0, i32 0) 37 %call1 = call zeroext i32 @llvm.experimental.gc.result.i32(token %safepoint_token) 38 ret i32 %call1 39 } 40 41 define i32* @test_i32ptr_return() gc "statepoint-example" { 42 ; CHECK-LABEL: test_i32ptr_return 43 ; CHECK: pushq %rax 44 ; CHECK: callq return_i32ptr 45 ; CHECK: popq %rcx 46 ; CHECK: retq 47 entry: 48 %safepoint_token = tail call token (i64, i32, i32* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p0i32f(i64 0, i32 0, i32* ()* @return_i32ptr, i32 0, i32 1, i32 0, i32 0) 49 %call1 = call i32* @llvm.experimental.gc.result.p0i32(token %safepoint_token) 50 ret i32* %call1 51 } 52 53 define float @test_float_return() gc "statepoint-example" { 54 ; CHECK-LABEL: test_float_return 55 ; CHECK: pushq %rax 56 ; CHECK: callq return_float 57 ; CHECK: popq %rax 58 ; CHECK: retq 59 entry: 60 %safepoint_token = tail call token (i64, i32, float ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_f32f(i64 0, i32 0, float ()* @return_float, i32 0, i32 1, i32 0, i32 0) 61 %call1 = call float @llvm.experimental.gc.result.f32(token %safepoint_token) 62 ret float %call1 63 } 64 65 define i1 @test_relocate(i32 addrspace(1)* %a) gc "statepoint-example" { 66 ; CHECK-LABEL: test_relocate 67 ; Check that an ununsed relocate has no code-generation impact 68 ; CHECK: pushq %rax 69 ; CHECK: callq return_i1 70 ; CHECK-NEXT: .Ltmp4: 71 ; CHECK-NEXT: popq %rcx 72 ; CHECK-NEXT: .cfi_def_cfa_offset 8 73 ; CHECK-NEXT: retq 74 entry: 75 %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 1, i32 0, i32 0, i32 addrspace(1)* %a) 76 %call1 = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 7) 77 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token) 78 ret i1 %call2 79 } 80 81 define void @test_void_vararg() gc "statepoint-example" { 82 ; CHECK-LABEL: test_void_vararg 83 ; Check a statepoint wrapping a *void* returning vararg function works 84 ; CHECK: callq varargf 85 entry: 86 %safepoint_token = tail call token (i64, i32, void (i32, ...)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi32varargf(i64 0, i32 0, void (i32, ...)* @varargf, i32 2, i32 1, i32 42, i32 43, i32 0, i32 0) 87 ;; if we try to use the result from a statepoint wrapping a 88 ;; non-void-returning varargf, we will experience a crash. 89 ret void 90 } 91 92 define i32 @test_transition_args() gc "statepoint-example" { 93 ; CHECK-LABEL: test_transition_args 94 ; CHECK: pushq %rax 95 ; CHECK: callq return_i32 96 ; CHECK: popq %rcx 97 ; CHECK: retq 98 entry: 99 %val = alloca i32 100 %safepoint_token = call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 0, i32 0, i32 ()* @return_i32, i32 0, i32 1, i32 2, i32* %val, i64 42, i32 0) 101 %call1 = call i32 @llvm.experimental.gc.result.i32(token %safepoint_token) 102 ret i32 %call1 103 } 104 105 define i32 @test_transition_args_2() gc "statepoint-example" { 106 ; CHECK-LABEL: test_transition_args_2 107 ; CHECK: pushq %rax 108 ; CHECK: callq return_i32 109 ; CHECK: popq %rcx 110 ; CHECK: retq 111 entry: 112 %val = alloca i32 113 %arg = alloca i8 114 %safepoint_token = call token (i64, i32, i32 (i32, i8*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32i32p0i8f(i64 0, i32 0, i32 (i32, i8*)* @return_i32_with_args, i32 2, i32 1, i32 0, i8* %arg, i32 2, i32* %val, i64 42, i32 0) 115 %call1 = call i32 @llvm.experimental.gc.result.i32(token %safepoint_token) 116 ret i32 %call1 117 } 118 119 declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...) 120 declare i1 @llvm.experimental.gc.result.i1(token) 121 122 declare token @llvm.experimental.gc.statepoint.p0f_i32f(i64, i32, i32 ()*, i32, i32, ...) 123 declare token @llvm.experimental.gc.statepoint.p0f_i32i32p0i8f(i64, i32, i32 (i32, i8*)*, i32, i32, ...) 124 declare i32 @llvm.experimental.gc.result.i32(token) 125 126 declare token @llvm.experimental.gc.statepoint.p0f_p0i32f(i64, i32, i32* ()*, i32, i32, ...) 127 declare i32* @llvm.experimental.gc.result.p0i32(token) 128 129 declare token @llvm.experimental.gc.statepoint.p0f_f32f(i64, i32, float ()*, i32, i32, ...) 130 declare float @llvm.experimental.gc.result.f32(token) 131 132 declare token @llvm.experimental.gc.statepoint.p0f_isVoidi32varargf(i64, i32, void (i32, ...)*, i32, i32, ...) 133 134 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) 135