1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs -mtriple=arm64-apple-ios7.0 -o - %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker@var = global void()* zeroinitializer 3*9880d681SAndroid Build Coastguard Worker 4*9880d681SAndroid Build Coastguard Workerdeclare void @bar() 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Workerdefine void @foo() { 7*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo: 8*9880d681SAndroid Build Coastguard Worker %func = load void()*, void()** @var 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker ; Calling a function encourages @foo to use a callee-saved register, 11*9880d681SAndroid Build Coastguard Worker ; which makes it a natural choice for the tail call itself. But we don't 12*9880d681SAndroid Build Coastguard Worker ; want that: the final "br xN" has to use a temporary or argument 13*9880d681SAndroid Build Coastguard Worker ; register. 14*9880d681SAndroid Build Coastguard Worker call void @bar() 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Worker tail call void %func() 17*9880d681SAndroid Build Coastguard Worker; CHECK: br {{x([0-79]|1[0-8])}} 18*9880d681SAndroid Build Coastguard Worker ret void 19*9880d681SAndroid Build Coastguard Worker} 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker; No matter how tempting it is, LLVM should not use x30 since that'll be 22*9880d681SAndroid Build Coastguard Worker; restored to its incoming value before the "br". 23*9880d681SAndroid Build Coastguard Workerdefine void @test_x30_tail() { 24*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_x30_tail: 25*9880d681SAndroid Build Coastguard Worker; CHECK: mov [[DEST:x[0-9]+]], x30 26*9880d681SAndroid Build Coastguard Worker; CHECK: br [[DEST]] 27*9880d681SAndroid Build Coastguard Worker %addr = call i8* @llvm.returnaddress(i32 0) 28*9880d681SAndroid Build Coastguard Worker %faddr = bitcast i8* %addr to void()* 29*9880d681SAndroid Build Coastguard Worker tail call void %faddr() 30*9880d681SAndroid Build Coastguard Worker ret void 31*9880d681SAndroid Build Coastguard Worker} 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Workerdeclare i8* @llvm.returnaddress(i32) 34