1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu -aarch64-load-store-opt=0 | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Workerdeclare void @callee_stack0() 4*9880d681SAndroid Build Coastguard Workerdeclare void @callee_stack8([8 x i32], i64) 5*9880d681SAndroid Build Coastguard Workerdeclare void @callee_stack16([8 x i32], i64, i64) 6*9880d681SAndroid Build Coastguard Worker 7*9880d681SAndroid Build Coastguard Workerdefine void @caller_to0_from0() nounwind { 8*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to0_from0: 9*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB 10*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack0() 11*9880d681SAndroid Build Coastguard Worker ret void 12*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: b callee_stack0 13*9880d681SAndroid Build Coastguard Worker} 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard Workerdefine void @caller_to0_from8([8 x i32], i64) nounwind{ 16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to0_from8: 17*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: // BB 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack0() 20*9880d681SAndroid Build Coastguard Worker ret void 21*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: b callee_stack0 22*9880d681SAndroid Build Coastguard Worker} 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Workerdefine void @caller_to8_from0() { 25*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to8_from0: 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker; Caller isn't going to clean up any extra stack we allocate, so it 28*9880d681SAndroid Build Coastguard Worker; can't be a tail call. 29*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack8([8 x i32] undef, i64 42) 30*9880d681SAndroid Build Coastguard Worker ret void 31*9880d681SAndroid Build Coastguard Worker; CHECK: bl callee_stack8 32*9880d681SAndroid Build Coastguard Worker} 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Workerdefine void @caller_to8_from8([8 x i32], i64 %a) { 35*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to8_from8: 36*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: sub sp, sp, 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker; This should reuse our stack area for the 42 39*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack8([8 x i32] undef, i64 42) 40*9880d681SAndroid Build Coastguard Worker ret void 41*9880d681SAndroid Build Coastguard Worker; CHECK: str {{x[0-9]+}}, [sp] 42*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: b callee_stack8 43*9880d681SAndroid Build Coastguard Worker} 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Workerdefine void @caller_to16_from8([8 x i32], i64 %a) { 46*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to16_from8: 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker; Shouldn't be a tail call: we can't use SP+8 because our caller might 49*9880d681SAndroid Build Coastguard Worker; have something there. This may sound obvious but implementation does 50*9880d681SAndroid Build Coastguard Worker; some funky aligning. 51*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack16([8 x i32] undef, i64 undef, i64 undef) 52*9880d681SAndroid Build Coastguard Worker; CHECK: bl callee_stack16 53*9880d681SAndroid Build Coastguard Worker ret void 54*9880d681SAndroid Build Coastguard Worker} 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Workerdefine void @caller_to8_from24([8 x i32], i64 %a, i64 %b, i64 %c) { 57*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to8_from24: 58*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: sub sp, sp 59*9880d681SAndroid Build Coastguard Worker 60*9880d681SAndroid Build Coastguard Worker; Reuse our area, putting "42" at incoming sp 61*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack8([8 x i32] undef, i64 42) 62*9880d681SAndroid Build Coastguard Worker ret void 63*9880d681SAndroid Build Coastguard Worker; CHECK: str {{x[0-9]+}}, [sp] 64*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: b callee_stack8 65*9880d681SAndroid Build Coastguard Worker} 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard Workerdefine void @caller_to16_from16([8 x i32], i64 %a, i64 %b) { 68*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: caller_to16_from16: 69*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: sub sp, sp, 70*9880d681SAndroid Build Coastguard Worker 71*9880d681SAndroid Build Coastguard Worker; Here we want to make sure that both loads happen before the stores: 72*9880d681SAndroid Build Coastguard Worker; otherwise either %a or %b will be wrongly clobbered. 73*9880d681SAndroid Build Coastguard Worker tail call void @callee_stack16([8 x i32] undef, i64 %b, i64 %a) 74*9880d681SAndroid Build Coastguard Worker ret void 75*9880d681SAndroid Build Coastguard Worker 76*9880d681SAndroid Build Coastguard Worker; CHECK: ldr [[VAL0:x[0-9]+]], 77*9880d681SAndroid Build Coastguard Worker; CHECK: ldr [[VAL1:x[0-9]+]], 78*9880d681SAndroid Build Coastguard Worker; CHECK: str [[VAL0]], 79*9880d681SAndroid Build Coastguard Worker; CHECK: str [[VAL1]], 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: add sp, sp, 82*9880d681SAndroid Build Coastguard Worker; CHECK: b callee_stack16 83*9880d681SAndroid Build Coastguard Worker} 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker@func = global void(i32)* null 86*9880d681SAndroid Build Coastguard Worker 87*9880d681SAndroid Build Coastguard Workerdefine void @indirect_tail() { 88*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: indirect_tail: 89*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: sub sp, sp 90*9880d681SAndroid Build Coastguard Worker 91*9880d681SAndroid Build Coastguard Worker %fptr = load void(i32)*, void(i32)** @func 92*9880d681SAndroid Build Coastguard Worker tail call void %fptr(i32 42) 93*9880d681SAndroid Build Coastguard Worker ret void 94*9880d681SAndroid Build Coastguard Worker; CHECK: ldr [[FPTR:x[1-9]+]], [{{x[0-9]+}}, {{#?}}:lo12:func] 95*9880d681SAndroid Build Coastguard Worker; CHECK: mov w0, #{{42|0x2a}} 96*9880d681SAndroid Build Coastguard Worker; CHECK: br [[FPTR]] 97*9880d681SAndroid Build Coastguard Worker} 98