xref: /llvm-project/llvm/test/CodeGen/X86/this-return-64.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; RUN: llc < %s -mtriple=x86_64-pc-win32 | FileCheck %s
2
3%struct.A = type { i8 }
4%struct.B = type { i32 }
5%struct.C = type { %struct.B }
6%struct.D = type { %struct.B }
7%struct.E = type { %struct.B }
8
9declare ptr @A_ctor(ptr returned)
10declare ptr @B_ctor(ptr returned, i32)
11
12declare ptr @A_ctor_nothisret(ptr)
13declare ptr @B_ctor_nothisret(ptr, i32)
14
15define ptr @C_ctor(ptr %this, i32 %y) {
16entry:
17; CHECK-LABEL: C_ctor:
18; CHECK: jmp     B_ctor                  # TAILCALL
19  %call = tail call ptr @B_ctor(ptr %this, i32 %y)
20  ret ptr %this
21}
22
23define ptr @C_ctor_nothisret(ptr %this, i32 %y) {
24entry:
25; CHECK-LABEL: C_ctor_nothisret:
26; CHECK-NOT: jmp     B_ctor_nothisret
27  %call = tail call ptr @B_ctor_nothisret(ptr %this, i32 %y)
28  ret ptr %this
29}
30
31define ptr @D_ctor(ptr %this, i32 %y) {
32entry:
33; CHECK-LABEL: D_ctor:
34; CHECK: movq    %rcx, [[SAVETHIS:%r[0-9a-z]+]]
35; CHECK: callq   A_ctor
36; CHECK: movq    [[SAVETHIS]], %rcx
37; CHECK: jmp     B_ctor                  # TAILCALL
38  %call = tail call ptr @A_ctor(ptr %this)
39  %call2 = tail call ptr @B_ctor(ptr %this, i32 %y)
40; (this next line would never be generated by Clang, actually)
41  ret ptr %call
42}
43
44define ptr @D_ctor_nothisret(ptr %this, i32 %y) {
45entry:
46; CHECK-LABEL: D_ctor_nothisret:
47; CHECK: movq    %rcx, [[SAVETHIS:%r[0-9a-z]+]]
48; CHECK: callq   A_ctor_nothisret
49; CHECK: movq    [[SAVETHIS]], %rcx
50; CHECK-NOT: jmp     B_ctor_nothisret
51  %call = tail call ptr @A_ctor_nothisret(ptr %this)
52  %call2 = tail call ptr @B_ctor_nothisret(ptr %this, i32 %y)
53; (this next line would never be generated by Clang, actually)
54  ret ptr %call
55}
56
57define ptr @E_ctor(ptr %this, i32 %x) {
58entry:
59; CHECK-LABEL: E_ctor:
60; CHECK: movq    %rcx, [[SAVETHIS:%r[0-9a-z]+]]
61; CHECK: callq   B_ctor
62; CHECK: movq    [[SAVETHIS]], %rcx
63; CHECK: jmp     B_ctor                  # TAILCALL
64  %call = tail call ptr @B_ctor(ptr %this, i32 %x)
65  %call4 = tail call ptr @B_ctor(ptr %this, i32 %x)
66  ret ptr %this
67}
68
69define ptr @E_ctor_nothisret(ptr %this, i32 %x) {
70entry:
71; CHECK-LABEL: E_ctor_nothisret:
72; CHECK: movq    %rcx, [[SAVETHIS:%r[0-9a-z]+]]
73; CHECK: callq   B_ctor_nothisret
74; CHECK: movq    [[SAVETHIS]], %rcx
75; CHECK-NOT: jmp     B_ctor_nothisret
76  %call = tail call ptr @B_ctor_nothisret(ptr %this, i32 %x)
77  %call4 = tail call ptr @B_ctor_nothisret(ptr %this, i32 %x)
78  ret ptr %this
79}
80