llvm.org GIT mirror llvm / 70c7566
Merging r233410: ------------------------------------------------------------------------ r233410 | ahmed.bougacha | 2015-03-27 16:35:49 -0400 (Fri, 27 Mar 2015) | 10 lines [CodeGen] Don't attempt a tail-call with a non-forwarded explicit sret. Tailcalls are only OK with forwarded sret pointers. With explicit sret, one approximation is to check that the pointer isn't an Instruction, as in that case it might point into some local memory (alloca). That's not OK with tailcalls. Explicit sret counterpart to r233409. Differential Revison: http://reviews.llvm.org/D8510 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@236067 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 5 years ago
2 changed file(s) with 111 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
57265726 // Skip the first return-type Attribute to get to params.
57275727 Entry.setAttributes(&CS, i - CS.arg_begin() + 1);
57285728 Args.push_back(Entry);
5729
5730 // If we have an explicit sret argument that is an Instruction, (i.e., it
5731 // might point to function-local memory), we can't meaningfully tail-call.
5732 if (Entry.isSRet && isa(V))
5733 isTailCall = false;
57295734 }
57305735
57315736 // Check if target-independent constraints permit a tail call here.
0 ; RUN: llc < %s -mtriple arm64-apple-darwin -aarch64-load-store-opt=false -asm-verbose=false | FileCheck %s
1 ; Disable the load/store optimizer to avoid having LDP/STPs and simplify checks.
2
3 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
4
5 ; Check that we don't try to tail-call with a non-forwarded sret parameter.
6 declare void @test_explicit_sret(i1024* sret) #0
7
8 ; This is the only OK case, where we forward the explicit sret pointer.
9
10 ; CHECK-LABEL: _test_tailcall_explicit_sret:
11 ; CHECK-NEXT: b _test_explicit_sret
12 define void @test_tailcall_explicit_sret(i1024* sret %arg) #0 {
13 tail call void @test_explicit_sret(i1024* %arg)
14 ret void
15 }
16
17 ; CHECK-LABEL: _test_call_explicit_sret:
18 ; CHECK-NOT: mov x8
19 ; CHECK: bl _test_explicit_sret
20 ; CHECK: ret
21 define void @test_call_explicit_sret(i1024* sret %arg) #0 {
22 call void @test_explicit_sret(i1024* %arg)
23 ret void
24 }
25
26 ; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_unused:
27 ; CHECK: mov x8, sp
28 ; CHECK-NEXT: bl _test_explicit_sret
29 ; CHECK: ret
30 define void @test_tailcall_explicit_sret_alloca_unused() #0 {
31 %l = alloca i1024, align 8
32 tail call void @test_explicit_sret(i1024* %l)
33 ret void
34 }
35
36 ; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_dummyusers:
37 ; CHECK: ldr [[PTRLOAD1:x[0-9]+]], [x0]
38 ; CHECK: str [[PTRLOAD1]], [sp]
39 ; CHECK: mov x8, sp
40 ; CHECK-NEXT: bl _test_explicit_sret
41 ; CHECK: ret
42 define void @test_tailcall_explicit_sret_alloca_dummyusers(i1024* %ptr) #0 {
43 %l = alloca i1024, align 8
44 %r = load i1024* %ptr, align 8
45 store i1024 %r, i1024* %l, align 8
46 tail call void @test_explicit_sret(i1024* %l)
47 ret void
48 }
49
50 ; This is too conservative, but doesn't really happen in practice.
51
52 ; CHECK-LABEL: _test_tailcall_explicit_sret_gep:
53 ; CHECK: add x8, x0, #128
54 ; CHECK-NEXT: bl _test_explicit_sret
55 ; CHECK: ret
56 define void @test_tailcall_explicit_sret_gep(i1024* %ptr) #0 {
57 %ptr2 = getelementptr i1024* %ptr, i32 1
58 tail call void @test_explicit_sret(i1024* %ptr2)
59 ret void
60 }
61
62 ; CHECK-LABEL: _test_tailcall_explicit_sret_alloca_returned:
63 ; CHECK: mov x[[CALLERX8NUM:[0-9]+]], x8
64 ; CHECK: mov x8, sp
65 ; CHECK-NEXT: bl _test_explicit_sret
66 ; CHECK-NEXT: ldr [[CALLERSRET1:x[0-9]+]], [sp]
67 ; CHECK: str [[CALLERSRET1:x[0-9]+]], [x[[CALLERX8NUM]]]
68 ; CHECK: ret
69 define i1024 @test_tailcall_explicit_sret_alloca_returned() #0 {
70 %l = alloca i1024, align 8
71 tail call void @test_explicit_sret(i1024* %l)
72 %r = load i1024* %l, align 8
73 ret i1024 %r
74 }
75
76 ; CHECK-LABEL: _test_indirect_tailcall_explicit_sret_nosret_arg:
77 ; CHECK-DAG: mov x[[CALLERX8NUM:[0-9]+]], x8
78 ; CHECK-DAG: mov [[FPTR:x[0-9]+]], x0
79 ; CHECK: mov x0, sp
80 ; CHECK-NEXT: blr [[FPTR]]
81 ; CHECK-NEXT: ldr [[CALLERSRET1:x[0-9]+]], [sp]
82 ; CHECK: str [[CALLERSRET1:x[0-9]+]], [x[[CALLERX8NUM]]]
83 ; CHECK: ret
84 define void @test_indirect_tailcall_explicit_sret_nosret_arg(i1024* sret %arg, void (i1024*)* %f) #0 {
85 %l = alloca i1024, align 8
86 tail call void %f(i1024* %l)
87 %r = load i1024* %l, align 8
88 store i1024 %r, i1024* %arg, align 8
89 ret void
90 }
91
92 ; CHECK-LABEL: _test_indirect_tailcall_explicit_sret_:
93 ; CHECK: mov x[[CALLERX8NUM:[0-9]+]], x8
94 ; CHECK: mov x8, sp
95 ; CHECK-NEXT: blr x0
96 ; CHECK-NEXT: ldr [[CALLERSRET1:x[0-9]+]], [sp]
97 ; CHECK: str [[CALLERSRET1:x[0-9]+]], [x[[CALLERX8NUM]]]
98 ; CHECK: ret
99 define void @test_indirect_tailcall_explicit_sret_(i1024* sret %arg, i1024 ()* %f) #0 {
100 %ret = tail call i1024 %f()
101 store i1024 %ret, i1024* %arg, align 8
102 ret void
103 }
104
105 attributes #0 = { nounwind }