1 ; RUN: llc -verify-machineinstrs -mtriple=aarch64-apple-ios -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s
2 ; RUN: llc -O0 -fast-isel -verify-machineinstrs -mtriple=aarch64-apple-ios -o - %s | FileCheck %s
3 ; RUN: llc -verify-machineinstrs -mtriple=aarch64-unknown-linux-gnu -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s
5 ; Parameter with swiftself should be allocated to x20.
6 ; CHECK-LABEL: swiftself_param:
9 define i8* @swiftself_param(i8* swiftself %addr0) {
13 ; Check that x20 is used to pass a swiftself argument.
14 ; CHECK-LABEL: call_swiftself:
16 ; CHECK: bl {{_?}}swiftself_param
18 define i8 *@call_swiftself(i8* %arg) {
19 %res = call i8 *@swiftself_param(i8* swiftself %arg)
23 ; x20 should be saved by the callee even if used for swiftself
24 ; CHECK-LABEL: swiftself_clobber:
25 ; CHECK: {{stp|str}} {{.*}}x20{{.*}}sp
27 ; CHECK: {{ldp|ldr}} {{.*}}x20{{.*}}sp
29 define i8 *@swiftself_clobber(i8* swiftself %addr0) {
30 call void asm sideeffect "", "~{x20}"()
34 ; Demonstrate that we do not need any movs when calling multiple functions
35 ; with swiftself argument.
36 ; CHECK-LABEL: swiftself_passthrough:
37 ; OPT-NOT: mov{{.*}}x20
38 ; OPT: bl {{_?}}swiftself_param
39 ; OPT-NOT: mov{{.*}}x20
40 ; OPT-NEXT: bl {{_?}}swiftself_param
42 define void @swiftself_passthrough(i8* swiftself %addr0) {
43 call i8 *@swiftself_param(i8* swiftself %addr0)
44 call i8 *@swiftself_param(i8* swiftself %addr0)
48 ; We can use a tail call if the callee swiftself is the same as the caller one.
49 ; This should also work with fast-isel.
50 ; CHECK-LABEL: swiftself_tail:
51 ; CHECK: b {{_?}}swiftself_param
53 define i8* @swiftself_tail(i8* swiftself %addr0) {
54 call void asm sideeffect "", "~{x20}"()
55 %res = tail call i8* @swiftself_param(i8* swiftself %addr0)
59 ; We can not use a tail call if the callee swiftself is not the same as the
61 ; CHECK-LABEL: swiftself_notail:
63 ; CHECK: bl {{_?}}swiftself_param
65 define i8* @swiftself_notail(i8* swiftself %addr0, i8* %addr1) nounwind {
66 %res = tail call i8* @swiftself_param(i8* swiftself %addr1)
70 ; We cannot pretend that 'x0' is alive across the thisreturn_attribute call as
71 ; we normally would. We marked the first parameter with swiftself which means it
72 ; will no longer be passed in x0.
73 declare swiftcc i8* @thisreturn_attribute(i8* returned swiftself)
74 ; OPT-LABEL: swiftself_nothisreturn:
75 ; OPT-DAG: ldr x20, [x20]
76 ; OPT-DAG: mov [[CSREG:x[1-9].*]], x8
77 ; OPT: bl {{_?}}thisreturn_attribute
78 ; OPT: str x0, {{\[}}[[CSREG]]
80 define hidden swiftcc void @swiftself_nothisreturn(i8** noalias nocapture sret, i8** noalias nocapture readonly swiftself) {
82 %2 = load i8*, i8** %1, align 8
83 %3 = tail call swiftcc i8* @thisreturn_attribute(i8* swiftself %2)
84 store i8* %3, i8** %0, align 8