1 ; RUN: llc -verify-machineinstrs -mtriple=x86_64-unknown-windows-msvc -o - %s | FileCheck --check-prefix=CHECK --check-prefix=OPT %s
2 ; RUN: llc -O0 -verify-machineinstrs -mtriple=x86_64-unknown-windows-msvc -o - %s | FileCheck %s
4 ; Parameter with swiftself should be allocated to r13.
5 ; CHECK-LABEL: swiftself_param:
6 ; CHECK: movq %r13, %rax
7 define ptr@swiftself_param(ptr swiftself %addr0) {
11 ; Check that r13 is used to pass a swiftself argument.
12 ; CHECK-LABEL: call_swiftself:
13 ; CHECK: movq %rcx, %r13
14 ; CHECK: callq swiftself_param
15 define ptr@call_swiftself(ptr %arg) {
16 %res = call ptr@swiftself_param(ptr swiftself %arg)
20 ; r13 should be saved by the callee even if used for swiftself
21 ; CHECK-LABEL: swiftself_clobber:
25 define ptr@swiftself_clobber(ptr swiftself %addr0) {
26 call void asm sideeffect "nop", "~{r13}"()
30 ; Demonstrate that we do not need any movs when calling multiple functions
31 ; with swiftself argument.
32 ; CHECK-LABEL: swiftself_passthrough:
33 ; OPT-NOT: mov{{.*}}r13
34 ; OPT: callq swiftself_param
35 ; OPT-NOT: mov{{.*}}r13
36 ; OPT-NEXT: callq swiftself_param
37 define void @swiftself_passthrough(ptr swiftself %addr0) {
38 call ptr@swiftself_param(ptr swiftself %addr0)
39 call ptr@swiftself_param(ptr swiftself %addr0)
43 ; We can use a tail call if the callee swiftself is the same as the caller one.
44 ; This should also work with fast-isel.
45 ; CHECK-LABEL: swiftself_tail:
46 ; CHECK: jmp swiftself_param
48 define ptr @swiftself_tail(ptr swiftself %addr0) {
49 call void asm sideeffect "", "~{r13}"()
50 %res = tail call ptr @swiftself_param(ptr swiftself %addr0)
54 ; We can not use a tail call if the callee swiftself is not the same as the
56 ; CHECK-LABEL: swiftself_notail:
57 ; CHECK: movq %rcx, %r13
58 ; CHECK: callq swiftself_param
60 define ptr @swiftself_notail(ptr swiftself %addr0, ptr %addr1) nounwind {
61 %res = tail call ptr @swiftself_param(ptr swiftself %addr1)