xref: /aosp_15_r20/external/llvm/test/CodeGen/AArch64/tailcall-explicit-sret.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple arm64-apple-darwin -aarch64-load-store-opt=false -asm-verbose=false -disable-post-ra | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; Disable the load/store optimizer to avoid having LDP/STPs and simplify checks.
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker; Check that we don't try to tail-call with a non-forwarded sret parameter.
7*9880d681SAndroid Build Coastguard Workerdeclare void @test_explicit_sret(i1024* sret) #0
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker; This is the only OK case, where we forward the explicit sret pointer.
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_tailcall_explicit_sret:
12*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: b _test_explicit_sret
13*9880d681SAndroid Build Coastguard Workerdefine void @test_tailcall_explicit_sret(i1024* sret %arg) #0 {
14*9880d681SAndroid Build Coastguard Worker  tail call void @test_explicit_sret(i1024* %arg)
15*9880d681SAndroid Build Coastguard Worker  ret void
16*9880d681SAndroid Build Coastguard Worker}
17*9880d681SAndroid Build Coastguard Worker
18*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_call_explicit_sret:
19*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: mov  x8
20*9880d681SAndroid Build Coastguard Worker; CHECK: bl _test_explicit_sret
21*9880d681SAndroid Build Coastguard Worker; CHECK: ret
22*9880d681SAndroid Build Coastguard Workerdefine void @test_call_explicit_sret(i1024* sret %arg) #0 {
23*9880d681SAndroid Build Coastguard Worker  call void @test_explicit_sret(i1024* %arg)
24*9880d681SAndroid Build Coastguard Worker  ret void
25*9880d681SAndroid Build Coastguard Worker}
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_unused:
28*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x8, sp
29*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl _test_explicit_sret
30*9880d681SAndroid Build Coastguard Worker; CHECK: ret
31*9880d681SAndroid Build Coastguard Workerdefine void @test_tailcall_explicit_sret_alloca_unused() #0 {
32*9880d681SAndroid Build Coastguard Worker  %l = alloca i1024, align 8
33*9880d681SAndroid Build Coastguard Worker  tail call void @test_explicit_sret(i1024* %l)
34*9880d681SAndroid Build Coastguard Worker  ret void
35*9880d681SAndroid Build Coastguard Worker}
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_dummyusers:
38*9880d681SAndroid Build Coastguard Worker; CHECK: ldr [[PTRLOAD1:x[0-9]+]], [x0]
39*9880d681SAndroid Build Coastguard Worker; CHECK: str [[PTRLOAD1]], [sp]
40*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x8, sp
41*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl _test_explicit_sret
42*9880d681SAndroid Build Coastguard Worker; CHECK: ret
43*9880d681SAndroid Build Coastguard Workerdefine void @test_tailcall_explicit_sret_alloca_dummyusers(i1024* %ptr) #0 {
44*9880d681SAndroid Build Coastguard Worker  %l = alloca i1024, align 8
45*9880d681SAndroid Build Coastguard Worker  %r = load i1024, i1024* %ptr, align 8
46*9880d681SAndroid Build Coastguard Worker  store i1024 %r, i1024* %l, align 8
47*9880d681SAndroid Build Coastguard Worker  tail call void @test_explicit_sret(i1024* %l)
48*9880d681SAndroid Build Coastguard Worker  ret void
49*9880d681SAndroid Build Coastguard Worker}
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker; This is too conservative, but doesn't really happen in practice.
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_tailcall_explicit_sret_gep:
54*9880d681SAndroid Build Coastguard Worker; CHECK: add  x8, x0, #128
55*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl _test_explicit_sret
56*9880d681SAndroid Build Coastguard Worker; CHECK: ret
57*9880d681SAndroid Build Coastguard Workerdefine void @test_tailcall_explicit_sret_gep(i1024* %ptr) #0 {
58*9880d681SAndroid Build Coastguard Worker  %ptr2 = getelementptr i1024, i1024* %ptr, i32 1
59*9880d681SAndroid Build Coastguard Worker  tail call void @test_explicit_sret(i1024* %ptr2)
60*9880d681SAndroid Build Coastguard Worker  ret void
61*9880d681SAndroid Build Coastguard Worker}
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_returned:
64*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x[[CALLERX8NUM:[0-9]+]], x8
65*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x8, sp
66*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: bl _test_explicit_sret
67*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ldr [[CALLERSRET1:x[0-9]+]], [sp]
68*9880d681SAndroid Build Coastguard Worker; CHECK: str [[CALLERSRET1:x[0-9]+]], [x[[CALLERX8NUM]]]
69*9880d681SAndroid Build Coastguard Worker; CHECK: ret
70*9880d681SAndroid Build Coastguard Workerdefine i1024 @test_tailcall_explicit_sret_alloca_returned() #0 {
71*9880d681SAndroid Build Coastguard Worker  %l = alloca i1024, align 8
72*9880d681SAndroid Build Coastguard Worker  tail call void @test_explicit_sret(i1024* %l)
73*9880d681SAndroid Build Coastguard Worker  %r = load i1024, i1024* %l, align 8
74*9880d681SAndroid Build Coastguard Worker  ret i1024 %r
75*9880d681SAndroid Build Coastguard Worker}
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_indirect_tailcall_explicit_sret_nosret_arg:
78*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: mov  x[[CALLERX8NUM:[0-9]+]], x8
79*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: mov  [[FPTR:x[0-9]+]], x0
80*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x0, sp
81*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: blr [[FPTR]]
82*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ldr [[CALLERSRET1:x[0-9]+]], [sp]
83*9880d681SAndroid Build Coastguard Worker; CHECK: str [[CALLERSRET1:x[0-9]+]], [x[[CALLERX8NUM]]]
84*9880d681SAndroid Build Coastguard Worker; CHECK: ret
85*9880d681SAndroid Build Coastguard Workerdefine void @test_indirect_tailcall_explicit_sret_nosret_arg(i1024* sret %arg, void (i1024*)* %f) #0 {
86*9880d681SAndroid Build Coastguard Worker  %l = alloca i1024, align 8
87*9880d681SAndroid Build Coastguard Worker  tail call void %f(i1024* %l)
88*9880d681SAndroid Build Coastguard Worker  %r = load i1024, i1024* %l, align 8
89*9880d681SAndroid Build Coastguard Worker  store i1024 %r, i1024* %arg, align 8
90*9880d681SAndroid Build Coastguard Worker  ret void
91*9880d681SAndroid Build Coastguard Worker}
92*9880d681SAndroid Build Coastguard Worker
93*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _test_indirect_tailcall_explicit_sret_:
94*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x[[CALLERX8NUM:[0-9]+]], x8
95*9880d681SAndroid Build Coastguard Worker; CHECK: mov  x8, sp
96*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: blr x0
97*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ldr [[CALLERSRET1:x[0-9]+]], [sp]
98*9880d681SAndroid Build Coastguard Worker; CHECK: str [[CALLERSRET1:x[0-9]+]], [x[[CALLERX8NUM]]]
99*9880d681SAndroid Build Coastguard Worker; CHECK: ret
100*9880d681SAndroid Build Coastguard Workerdefine void @test_indirect_tailcall_explicit_sret_(i1024* sret %arg, i1024 ()* %f) #0 {
101*9880d681SAndroid Build Coastguard Worker  %ret = tail call i1024 %f()
102*9880d681SAndroid Build Coastguard Worker  store i1024 %ret, i1024* %arg, align 8
103*9880d681SAndroid Build Coastguard Worker  ret void
104*9880d681SAndroid Build Coastguard Worker}
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind }
107