blob: 1e06b34c7052905695bdcae233c1fb9f7d59e1e9 [file] [log] [blame]
Matthias Braun707e02c2016-04-13 21:43:25 +00001; RUN: llc -verify-machineinstrs -mtriple=armv7k-apple-ios8.0 -mcpu=cortex-a7 -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT --check-prefix=TAILCALL %s
2; RUN: llc -O0 -verify-machineinstrs -mtriple=armv7k-apple-ios8.0 -mcpu=cortex-a7 -o - %s | FileCheck %s
Manman Renf46262e2016-03-29 17:37:21 +00003
Matthias Braun707e02c2016-04-13 21:43:25 +00004; RUN: llc -verify-machineinstrs -mtriple=armv7-apple-ios -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s
5; RUN: llc -O0 -verify-machineinstrs -mtriple=armv7-apple-ios -o - %s | FileCheck %s
Manman Renf46262e2016-03-29 17:37:21 +00006
Matthias Braun707e02c2016-04-13 21:43:25 +00007; Parameter with swiftself should be allocated to r10.
8; CHECK-LABEL: swiftself_param:
9; CHECK: mov r0, r10
Oliver Stannard9aa6f012016-08-23 09:19:22 +000010define i8 *@swiftself_param(i8* swiftself %addr0) "no-frame-pointer-elim"="true" {
Matthias Braun707e02c2016-04-13 21:43:25 +000011 ret i8 *%addr0
Manman Renf46262e2016-03-29 17:37:21 +000012}
13
Matthias Braun707e02c2016-04-13 21:43:25 +000014; Check that r10 is used to pass a swiftself argument.
15; CHECK-LABEL: call_swiftself:
16; CHECK: mov r10, r0
17; CHECK: bl {{_?}}swiftself_param
Oliver Stannard9aa6f012016-08-23 09:19:22 +000018define i8 *@call_swiftself(i8* %arg) "no-frame-pointer-elim"="true" {
Matthias Braun707e02c2016-04-13 21:43:25 +000019 %res = call i8 *@swiftself_param(i8* swiftself %arg)
20 ret i8 *%res
21}
Manman Renf46262e2016-03-29 17:37:21 +000022
Matthias Braun707e02c2016-04-13 21:43:25 +000023; r10 should be saved by the callee even if used for swiftself
24; CHECK-LABEL: swiftself_clobber:
25; CHECK: push {r10}
26; ...
27; CHECK: pop {r10}
Oliver Stannard9aa6f012016-08-23 09:19:22 +000028define i8 *@swiftself_clobber(i8* swiftself %addr0) "no-frame-pointer-elim"="true" {
Matthias Braun707e02c2016-04-13 21:43:25 +000029 call void asm sideeffect "", "~{r10}"()
30 ret i8 *%addr0
31}
Manman Renf46262e2016-03-29 17:37:21 +000032
Matthias Braun707e02c2016-04-13 21:43:25 +000033; Demonstrate that we do not need any movs when calling multiple functions
34; with swiftself argument.
35; CHECK-LABEL: swiftself_passthrough:
36; OPT-NOT: mov{{.*}}r10
37; OPT: bl {{_?}}swiftself_param
38; OPT-NOT: mov{{.*}}r10
39; OPT-NEXT: bl {{_?}}swiftself_param
Oliver Stannard9aa6f012016-08-23 09:19:22 +000040define void @swiftself_passthrough(i8* swiftself %addr0) "no-frame-pointer-elim"="true" {
Matthias Braun707e02c2016-04-13 21:43:25 +000041 call i8 *@swiftself_param(i8* swiftself %addr0)
42 call i8 *@swiftself_param(i8* swiftself %addr0)
Manman Renf46262e2016-03-29 17:37:21 +000043 ret void
44}
Matthias Braun707e02c2016-04-13 21:43:25 +000045
46; We can use a tail call if the callee swiftself is the same as the caller one.
47; CHECK-LABEL: swiftself_tail:
48; TAILCALL: b {{_?}}swiftself_param
49; TAILCALL-NOT: pop
Oliver Stannard9aa6f012016-08-23 09:19:22 +000050define i8* @swiftself_tail(i8* swiftself %addr0) "no-frame-pointer-elim"="true" {
Matthias Braun707e02c2016-04-13 21:43:25 +000051 call void asm sideeffect "", "~{r10}"()
52 %res = tail call i8* @swiftself_param(i8* swiftself %addr0)
53 ret i8* %res
54}
55
56; We can not use a tail call if the callee swiftself is not the same as the
57; caller one.
58; CHECK-LABEL: swiftself_notail:
59; CHECK: mov r10, r0
60; CHECK: bl {{_?}}swiftself_param
61; CHECK: pop
Oliver Stannard9aa6f012016-08-23 09:19:22 +000062define i8* @swiftself_notail(i8* swiftself %addr0, i8* %addr1) nounwind "no-frame-pointer-elim"="true" {
Matthias Braun707e02c2016-04-13 21:43:25 +000063 %res = tail call i8* @swiftself_param(i8* swiftself %addr1)
64 ret i8* %res
65}
Arnold Schwaighoferdb7bbcb2017-02-08 22:30:47 +000066
67; We cannot pretend that 'r0' is alive across the thisreturn_attribute call as
68; we normally would. We marked the first parameter with swiftself which means it
69; will no longer be passed in r0.
70declare swiftcc i8* @thisreturn_attribute(i8* returned swiftself)
71; OPT-LABEL: swiftself_nothisreturn:
72; OPT-DAG: mov [[CSREG:r[1-9].*]], r0
73; OPT-DAG: ldr r10, [r10]
74; OPT: bl {{_?}}thisreturn_attribute
75; OPT: str r0, {{\[}}[[CSREG]]
76define hidden swiftcc void @swiftself_nothisreturn(i8** noalias nocapture sret, i8** noalias nocapture readonly swiftself) {
77entry:
78 %2 = load i8*, i8** %1, align 8
79 %3 = tail call swiftcc i8* @thisreturn_attribute(i8* swiftself %2)
80 store i8* %3, i8** %0, align 8
81 ret void
82}