1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-linux-gnu -tailcallopt -code-model=large -enable-misched=false | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Workerdeclare fastcc i32 @callee(i32 %arg) 4*9880d681SAndroid Build Coastguard Workerdefine fastcc i32 @directcall(i32 %arg) { 5*9880d681SAndroid Build Coastguard Workerentry: 6*9880d681SAndroid Build Coastguard Worker; This is the large code model, so &callee may not fit into the jmp 7*9880d681SAndroid Build Coastguard Worker; instruction. Instead, stick it into a register. 8*9880d681SAndroid Build Coastguard Worker; CHECK: movabsq $callee, [[REGISTER:%r[a-z0-9]+]] 9*9880d681SAndroid Build Coastguard Worker; CHECK: jmpq *[[REGISTER]] # TAILCALL 10*9880d681SAndroid Build Coastguard Worker %res = tail call fastcc i32 @callee(i32 %arg) 11*9880d681SAndroid Build Coastguard Worker ret i32 %res 12*9880d681SAndroid Build Coastguard Worker} 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker; Check that the register used for an indirect tail call doesn't 15*9880d681SAndroid Build Coastguard Worker; clobber any of the arguments. 16*9880d681SAndroid Build Coastguard Workerdefine fastcc i32 @indirect_manyargs(i32(i32,i32,i32,i32,i32,i32,i32)* %target) { 17*9880d681SAndroid Build Coastguard Worker; Adjust the stack to enter the function. (The amount of the 18*9880d681SAndroid Build Coastguard Worker; adjustment may change in the future, in which case the location of 19*9880d681SAndroid Build Coastguard Worker; the stack argument and the return adjustment will change too.) 20*9880d681SAndroid Build Coastguard Worker; CHECK: pushq 21*9880d681SAndroid Build Coastguard Worker; Put the call target into R11, which won't be clobbered while restoring 22*9880d681SAndroid Build Coastguard Worker; callee-saved registers and won't be used for passing arguments. 23*9880d681SAndroid Build Coastguard Worker; CHECK: movq %rdi, %rax 24*9880d681SAndroid Build Coastguard Worker; Pass the stack argument. 25*9880d681SAndroid Build Coastguard Worker; CHECK: movl $7, 16(%rsp) 26*9880d681SAndroid Build Coastguard Worker; Pass the register arguments, in the right registers. 27*9880d681SAndroid Build Coastguard Worker; CHECK: movl $1, %edi 28*9880d681SAndroid Build Coastguard Worker; CHECK: movl $2, %esi 29*9880d681SAndroid Build Coastguard Worker; CHECK: movl $3, %edx 30*9880d681SAndroid Build Coastguard Worker; CHECK: movl $4, %ecx 31*9880d681SAndroid Build Coastguard Worker; CHECK: movl $5, %r8d 32*9880d681SAndroid Build Coastguard Worker; CHECK: movl $6, %r9d 33*9880d681SAndroid Build Coastguard Worker; Adjust the stack to "return". 34*9880d681SAndroid Build Coastguard Worker; CHECK: popq 35*9880d681SAndroid Build Coastguard Worker; And tail-call to the target. 36*9880d681SAndroid Build Coastguard Worker; CHECK: jmpq *%rax # TAILCALL 37*9880d681SAndroid Build Coastguard Worker %res = tail call fastcc i32 %target(i32 1, i32 2, i32 3, i32 4, i32 5, 38*9880d681SAndroid Build Coastguard Worker i32 6, i32 7) 39*9880d681SAndroid Build Coastguard Worker ret i32 %res 40*9880d681SAndroid Build Coastguard Worker} 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker; Check that the register used for a direct tail call doesn't clobber 43*9880d681SAndroid Build Coastguard Worker; any of the arguments. 44*9880d681SAndroid Build Coastguard Workerdeclare fastcc i32 @manyargs_callee(i32,i32,i32,i32,i32,i32,i32) 45*9880d681SAndroid Build Coastguard Workerdefine fastcc i32 @direct_manyargs() { 46*9880d681SAndroid Build Coastguard Worker; Adjust the stack to enter the function. (The amount of the 47*9880d681SAndroid Build Coastguard Worker; adjustment may change in the future, in which case the location of 48*9880d681SAndroid Build Coastguard Worker; the stack argument and the return adjustment will change too.) 49*9880d681SAndroid Build Coastguard Worker; CHECK: pushq 50*9880d681SAndroid Build Coastguard Worker; Pass the stack argument. 51*9880d681SAndroid Build Coastguard Worker; CHECK: movl $7, 16(%rsp) 52*9880d681SAndroid Build Coastguard Worker; This is the large code model, so &manyargs_callee may not fit into 53*9880d681SAndroid Build Coastguard Worker; the jmp instruction. Put it into a register which won't be clobbered 54*9880d681SAndroid Build Coastguard Worker; while restoring callee-saved registers and won't be used for passing 55*9880d681SAndroid Build Coastguard Worker; arguments. 56*9880d681SAndroid Build Coastguard Worker; CHECK: movabsq $manyargs_callee, %rax 57*9880d681SAndroid Build Coastguard Worker; Pass the register arguments, in the right registers. 58*9880d681SAndroid Build Coastguard Worker; CHECK: movl $1, %edi 59*9880d681SAndroid Build Coastguard Worker; CHECK: movl $2, %esi 60*9880d681SAndroid Build Coastguard Worker; CHECK: movl $3, %edx 61*9880d681SAndroid Build Coastguard Worker; CHECK: movl $4, %ecx 62*9880d681SAndroid Build Coastguard Worker; CHECK: movl $5, %r8d 63*9880d681SAndroid Build Coastguard Worker; CHECK: movl $6, %r9d 64*9880d681SAndroid Build Coastguard Worker; Adjust the stack to "return". 65*9880d681SAndroid Build Coastguard Worker; CHECK: popq 66*9880d681SAndroid Build Coastguard Worker; And tail-call to the target. 67*9880d681SAndroid Build Coastguard Worker; CHECK: jmpq *%rax # TAILCALL 68*9880d681SAndroid Build Coastguard Worker %res = tail call fastcc i32 @manyargs_callee(i32 1, i32 2, i32 3, i32 4, 69*9880d681SAndroid Build Coastguard Worker i32 5, i32 6, i32 7) 70*9880d681SAndroid Build Coastguard Worker ret i32 %res 71*9880d681SAndroid Build Coastguard Worker} 72