1 ; RUN: llc < %s -mtriple arm64-apple-darwin -aarch64-enable-ldst-opt=false -asm-verbose=false -disable-post-ra | FileCheck %s
2 ; Disable the load/store optimizer to avoid having LDP/STPs and simplify checks.
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
6 ; Check that we don't try to tail-call with a non-forwarded sret parameter.
7 declare void @test_explicit_sret(i1024* sret) #0
9 ; This is the only OK case, where we forward the explicit sret pointer.
11 ; CHECK-LABEL: _test_tailcall_explicit_sret:
12 ; CHECK-NEXT: b _test_explicit_sret
13 define void @test_tailcall_explicit_sret(i1024* sret %arg) #0 {
14 tail call void @test_explicit_sret(i1024* %arg)
18 ; CHECK-LABEL: _test_call_explicit_sret:
20 ; CHECK: bl _test_explicit_sret
22 define void @test_call_explicit_sret(i1024* sret %arg) #0 {
23 call void @test_explicit_sret(i1024* %arg)
27 ; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_unused:
29 ; CHECK-NEXT: bl _test_explicit_sret
31 define void @test_tailcall_explicit_sret_alloca_unused() #0 {
32 %l = alloca i1024, align 8
33 tail call void @test_explicit_sret(i1024* %l)
37 ; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_dummyusers:
38 ; CHECK: ldr [[PTRLOAD1:q[0-9]+]], [x0]
39 ; CHECK: str [[PTRLOAD1]], [sp]
41 ; CHECK-NEXT: bl _test_explicit_sret
43 define void @test_tailcall_explicit_sret_alloca_dummyusers(i1024* %ptr) #0 {
44 %l = alloca i1024, align 8
45 %r = load i1024, i1024* %ptr, align 8
46 store i1024 %r, i1024* %l, align 8
47 tail call void @test_explicit_sret(i1024* %l)
51 ; This is too conservative, but doesn't really happen in practice.
53 ; CHECK-LABEL: _test_tailcall_explicit_sret_gep:
54 ; CHECK: add x8, x0, #128
55 ; CHECK-NEXT: bl _test_explicit_sret
57 define void @test_tailcall_explicit_sret_gep(i1024* %ptr) #0 {
58 %ptr2 = getelementptr i1024, i1024* %ptr, i32 1
59 tail call void @test_explicit_sret(i1024* %ptr2)
63 ; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_returned:
64 ; CHECK: mov x[[CALLERX8NUM:[0-9]+]], x8
66 ; CHECK-NEXT: bl _test_explicit_sret
67 ; CHECK-NEXT: ldr [[CALLERSRET1:q[0-9]+]], [sp]
68 ; CHECK: str [[CALLERSRET1:q[0-9]+]], [x[[CALLERX8NUM]]]
70 define i1024 @test_tailcall_explicit_sret_alloca_returned() #0 {
71 %l = alloca i1024, align 8
72 tail call void @test_explicit_sret(i1024* %l)
73 %r = load i1024, i1024* %l, align 8
77 ; CHECK-LABEL: _test_indirect_tailcall_explicit_sret_nosret_arg:
78 ; CHECK-DAG: mov x[[CALLERX8NUM:[0-9]+]], x8
79 ; CHECK-DAG: mov [[FPTR:x[0-9]+]], x0
81 ; CHECK-NEXT: blr [[FPTR]]
82 ; CHECK: ldr [[CALLERSRET1:q[0-9]+]], [sp]
83 ; CHECK: str [[CALLERSRET1:q[0-9]+]], [x[[CALLERX8NUM]]]
85 define void @test_indirect_tailcall_explicit_sret_nosret_arg(i1024* sret %arg, void (i1024*)* %f) #0 {
86 %l = alloca i1024, align 8
87 tail call void %f(i1024* %l)
88 %r = load i1024, i1024* %l, align 8
89 store i1024 %r, i1024* %arg, align 8
93 ; CHECK-LABEL: _test_indirect_tailcall_explicit_sret_:
94 ; CHECK: mov x[[CALLERX8NUM:[0-9]+]], x8
97 ; CHECK: ldr [[CALLERSRET1:q[0-9]+]], [sp]
98 ; CHECK: str [[CALLERSRET1:q[0-9]+]], [x[[CALLERX8NUM]]]
100 define void @test_indirect_tailcall_explicit_sret_(i1024* sret %arg, i1024 ()* %f) #0 {
101 %ret = tail call i1024 %f()
102 store i1024 %ret, i1024* %arg, align 8
106 attributes #0 = { nounwind }