xref: /llvm-project/llvm/test/CodeGen/AArch64/arm64-this-return.ll (revision b1f9440fa9286638bb1fe72a14d220770d1987cc)
1; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2; RUN: llc < %s -mtriple=arm64-eabi | FileCheck %s
3; RUN: llc < %s -mtriple=arm64-eabi -global-isel -global-isel-abort=1 | FileCheck %s
4; RUN: llc < %s -mtriple=arm64-eabi -global-isel -global-isel-abort=1 -stop-after=irtranslator | FileCheck %s --check-prefix=GISEL-MIR
5
6%struct.A = type { i8 }
7%struct.B = type { i32 }
8%struct.C = type { %struct.B }
9%struct.D = type { %struct.B }
10%struct.E = type { %struct.B, %struct.B }
11
12declare ptr @A_ctor_base(ptr returned)
13declare ptr @B_ctor_base(ptr returned, i32)
14declare ptr @B_ctor_complete(ptr returned, i32)
15
16declare ptr @A_ctor_base_nothisret(ptr)
17declare ptr @B_ctor_base_nothisret(ptr, i32)
18declare ptr @B_ctor_complete_nothisret(ptr, i32)
19
20define ptr @C_ctor_base(ptr returned %this, i32 %x) {
21  ; GISEL-MIR-LABEL: name: C_ctor_base
22  ; GISEL-MIR: bb.1.entry:
23  ; GISEL-MIR:   liveins: $w1, $x0
24  ; GISEL-MIR:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
25  ; GISEL-MIR:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
26  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
27  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
28  ; GISEL-MIR:   BL @A_ctor_base, csr_aarch64_aapcs_thisreturn, implicit-def $lr, implicit $sp, implicit $x0
29  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
30  ; GISEL-MIR:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[COPY]](p0)
31  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
32  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
33  ; GISEL-MIR:   TCRETURNdi @B_ctor_base, 0, csr_aarch64_aapcs, implicit $sp, implicit $x0, implicit $w1
34entry:
35; CHECK-LABEL: C_ctor_base:
36; CHECK-NOT: mov {{x[0-9]+}}, x0
37; CHECK: bl {{_?A_ctor_base}}
38; CHECK-NOT: mov x0, {{x[0-9]+}}
39; CHECK: b {{_?B_ctor_base}}
40  %call = tail call ptr @A_ctor_base(ptr returned %this)
41  %call2 = tail call ptr @B_ctor_base(ptr returned %this, i32 %x)
42  ret ptr %this
43}
44
45define ptr @C_ctor_base_nothisret(ptr %this, i32 %x) {
46  ; GISEL-MIR-LABEL: name: C_ctor_base_nothisret
47  ; GISEL-MIR: bb.1.entry:
48  ; GISEL-MIR:   liveins: $w1, $x0
49  ; GISEL-MIR:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
50  ; GISEL-MIR:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
51  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
52  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
53  ; GISEL-MIR:   BL @A_ctor_base_nothisret, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0, implicit-def $x0
54  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
55  ; GISEL-MIR:   [[COPY2:%[0-9]+]]:_(p0) = COPY $x0
56  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
57  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
58  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
59  ; GISEL-MIR:   BL @B_ctor_base_nothisret, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0, implicit $w1, implicit-def $x0
60  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
61  ; GISEL-MIR:   [[COPY3:%[0-9]+]]:_(p0) = COPY $x0
62  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
63  ; GISEL-MIR:   RET_ReallyLR implicit $x0
64entry:
65; CHECK-LABEL: C_ctor_base_nothisret:
66; CHECK: mov [[SAVETHIS:x[0-9]+]], x0
67; CHECK: bl {{_?A_ctor_base_nothisret}}
68; CHECK: mov x0, [[SAVETHIS]]
69; CHECK-NOT: b {{_?B_ctor_base_nothisret}}
70  %call = tail call ptr @A_ctor_base_nothisret(ptr %this)
71  %call2 = tail call ptr @B_ctor_base_nothisret(ptr %this, i32 %x)
72  ret ptr %this
73}
74
75define ptr @C_ctor_complete(ptr %this, i32 %x) {
76  ; GISEL-MIR-LABEL: name: C_ctor_complete
77  ; GISEL-MIR: bb.1.entry:
78  ; GISEL-MIR:   liveins: $w1, $x0
79  ; GISEL-MIR:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
80  ; GISEL-MIR:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
81  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
82  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
83  ; GISEL-MIR:   TCRETURNdi @C_ctor_base, 0, csr_aarch64_aapcs, implicit $sp, implicit $x0, implicit $w1
84entry:
85; CHECK-LABEL: C_ctor_complete:
86; CHECK: b {{_?C_ctor_base}}
87  %call = tail call ptr @C_ctor_base(ptr returned %this, i32 %x)
88  ret ptr %this
89}
90
91define ptr @C_ctor_complete_nothisret(ptr %this, i32 %x) {
92  ; GISEL-MIR-LABEL: name: C_ctor_complete_nothisret
93  ; GISEL-MIR: bb.1.entry:
94  ; GISEL-MIR:   liveins: $w1, $x0
95  ; GISEL-MIR:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
96  ; GISEL-MIR:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
97  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
98  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
99  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
100  ; GISEL-MIR:   BL @C_ctor_base_nothisret, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0, implicit $w1, implicit-def $x0
101  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
102  ; GISEL-MIR:   [[COPY2:%[0-9]+]]:_(p0) = COPY $x0
103  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
104  ; GISEL-MIR:   RET_ReallyLR implicit $x0
105entry:
106; CHECK-LABEL: C_ctor_complete_nothisret:
107; CHECK-NOT: b {{_?C_ctor_base_nothisret}}
108  %call = tail call ptr @C_ctor_base_nothisret(ptr %this, i32 %x)
109  ret ptr %this
110}
111
112define ptr @D_ctor_base(ptr %this, i32 %x) {
113  ; GISEL-MIR-LABEL: name: D_ctor_base
114  ; GISEL-MIR: bb.1.entry:
115  ; GISEL-MIR:   liveins: $w1, $x0
116  ; GISEL-MIR:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
117  ; GISEL-MIR:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
118  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
119  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
120  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
121  ; GISEL-MIR:   BL @B_ctor_complete, csr_aarch64_aapcs_thisreturn, implicit-def $lr, implicit $sp, implicit $x0, implicit $w1
122  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
123  ; GISEL-MIR:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[COPY]](p0)
124  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
125  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
126  ; GISEL-MIR:   TCRETURNdi @B_ctor_complete, 0, csr_aarch64_aapcs, implicit $sp, implicit $x0, implicit $w1
127entry:
128; CHECK-LABEL: D_ctor_base:
129; CHECK-NOT: mov {{x[0-9]+}}, x0
130; CHECK: bl {{_?B_ctor_complete}}
131; CHECK-NOT: mov x0, {{x[0-9]+}}
132; CHECK: b {{_?B_ctor_complete}}
133  %call = tail call ptr @B_ctor_complete(ptr returned %this, i32 %x)
134  %call2 = tail call ptr @B_ctor_complete(ptr returned %this, i32 %x)
135  ret ptr %this
136}
137
138define ptr @E_ctor_base(ptr %this, i32 %x) {
139  ; GISEL-MIR-LABEL: name: E_ctor_base
140  ; GISEL-MIR: bb.1.entry:
141  ; GISEL-MIR:   liveins: $w1, $x0
142  ; GISEL-MIR:   [[COPY:%[0-9]+]]:_(p0) = COPY $x0
143  ; GISEL-MIR:   [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
144  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
145  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
146  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
147  ; GISEL-MIR:   BL @B_ctor_complete, csr_aarch64_aapcs_thisreturn, implicit-def $lr, implicit $sp, implicit $x0, implicit $w1
148  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
149  ; GISEL-MIR:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[COPY]](p0)
150  ; GISEL-MIR:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
151  ; GISEL-MIR:   [[PTR_ADD:%[0-9]+]]:_(p0) = nuw nusw G_PTR_ADD [[COPY]], [[C]](s64)
152  ; GISEL-MIR:   ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
153  ; GISEL-MIR:   $x0 = COPY [[PTR_ADD]](p0)
154  ; GISEL-MIR:   $w1 = COPY [[COPY1]](s32)
155  ; GISEL-MIR:   BL @B_ctor_complete, csr_aarch64_aapcs_thisreturn, implicit-def $lr, implicit $sp, implicit $x0, implicit $w1
156  ; GISEL-MIR:   ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
157  ; GISEL-MIR:   [[COPY3:%[0-9]+]]:_(p0) = COPY [[PTR_ADD]](p0)
158  ; GISEL-MIR:   $x0 = COPY [[COPY]](p0)
159  ; GISEL-MIR:   RET_ReallyLR implicit $x0
160entry:
161; CHECK-LABEL: E_ctor_base:
162; CHECK-NOT: b {{_?B_ctor_complete}}
163  %call = tail call ptr @B_ctor_complete(ptr returned %this, i32 %x)
164  %b2 = getelementptr inbounds %struct.E, ptr %this, i32 0, i32 1
165  %call2 = tail call ptr @B_ctor_complete(ptr returned %b2, i32 %x)
166  ret ptr %this
167}
168