1; RUN: llc -verify-machineinstrs < %s -mtriple=i686-win32 | FileCheck %s 2; RUN: llc -verify-machineinstrs < %s -mtriple=i686-win32 -O0 | FileCheck %s 3 4; IR simplified from the following C++ snippet compiled for i686-windows-msvc: 5 6; struct A { A(); ~A(); int a; }; 7; 8; struct B { 9; virtual int f(int); 10; virtual int g(A, int, A); 11; virtual void h(A, int, A); 12; virtual A i(A, int, A); 13; virtual A j(int); 14; }; 15; 16; int (B::*mp_f)(int) = &B::f; 17; int (B::*mp_g)(A, int, A) = &B::g; 18; void (B::*mp_h)(A, int, A) = &B::h; 19; A (B::*mp_i)(A, int, A) = &B::i; 20; A (B::*mp_j)(int) = &B::j; 21 22; Each member pointer creates a thunk. The ones with inalloca are required to 23; tail calls by the ABI, even at O0. 24 25%struct.B = type { i32 (...)** } 26%struct.A = type { i32 } 27 28; CHECK-LABEL: f_thunk: 29; CHECK: jmpl 30; CHECK-NOT: ret 31define x86_thiscallcc i32 @f_thunk(%struct.B* %this, i32) { 32entry: 33 %1 = bitcast %struct.B* %this to i32 (%struct.B*, i32)*** 34 %vtable = load i32 (%struct.B*, i32)**, i32 (%struct.B*, i32)*** %1 35 %2 = load i32 (%struct.B*, i32)*, i32 (%struct.B*, i32)** %vtable 36 %3 = musttail call x86_thiscallcc i32 %2(%struct.B* %this, i32 %0) 37 ret i32 %3 38} 39 40; Inalloca thunks shouldn't require any stores to the stack. 41; CHECK-LABEL: g_thunk: 42; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 43; CHECK: jmpl 44; CHECK-NOT: ret 45define x86_thiscallcc i32 @g_thunk(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca) { 46entry: 47 %1 = bitcast %struct.B* %this to i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** 48 %vtable = load i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)**, i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** %1 49 %vfn = getelementptr inbounds i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vtable, i32 1 50 %2 = load i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vfn 51 %3 = musttail call x86_thiscallcc i32 %2(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca %0) 52 ret i32 %3 53} 54 55; Preallocated thunks shouldn't require any stores to the stack. 56; CHECK-LABEL: g_thunk_preallocated: 57; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 58; CHECK: jmpl 59; CHECK-NOT: ret 60define x86_thiscallcc i32 @g_thunk_preallocated(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* preallocated(<{ %struct.A, i32, %struct.A }>)) { 61entry: 62 %1 = bitcast %struct.B* %this to i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** 63 %vtable = load i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)**, i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** %1 64 %vfn = getelementptr inbounds i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vtable, i32 1 65 %2 = load i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vfn 66 %3 = musttail call x86_thiscallcc i32 %2(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* preallocated(<{ %struct.A, i32, %struct.A }>) %0) 67 ret i32 %3 68} 69 70; CHECK-LABEL: h_thunk: 71; CHECK: jmpl 72; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 73; CHECK-NOT: ret 74define x86_thiscallcc void @h_thunk(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca) { 75entry: 76 %1 = bitcast %struct.B* %this to void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** 77 %vtable = load void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)**, void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** %1 78 %vfn = getelementptr inbounds void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vtable, i32 2 79 %2 = load void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vfn 80 musttail call x86_thiscallcc void %2(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* inalloca %0) 81 ret void 82} 83 84; CHECK-LABEL: h_thunk_preallocated: 85; CHECK: jmpl 86; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 87; CHECK-NOT: ret 88define x86_thiscallcc void @h_thunk_preallocated(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* preallocated(<{ %struct.A, i32, %struct.A }>)) { 89entry: 90 %1 = bitcast %struct.B* %this to void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** 91 %vtable = load void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)**, void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*** %1 92 %vfn = getelementptr inbounds void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vtable, i32 2 93 %2 = load void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)*, void (%struct.B*, <{ %struct.A, i32, %struct.A }>*)** %vfn 94 musttail call x86_thiscallcc void %2(%struct.B* %this, <{ %struct.A, i32, %struct.A }>* preallocated(<{ %struct.A, i32, %struct.A }>) %0) 95 ret void 96} 97 98; CHECK-LABEL: i_thunk: 99; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 100; CHECK: jmpl 101; CHECK-NOT: ret 102define x86_thiscallcc %struct.A* @i_thunk(%struct.B* %this, <{ %struct.A*, %struct.A, i32, %struct.A }>* inalloca) { 103entry: 104 %1 = bitcast %struct.B* %this to %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*** 105 %vtable = load %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)**, %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*** %1 106 %vfn = getelementptr inbounds %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*, %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)** %vtable, i32 3 107 %2 = load %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*, %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)** %vfn 108 %3 = musttail call x86_thiscallcc %struct.A* %2(%struct.B* %this, <{ %struct.A*, %struct.A, i32, %struct.A }>* inalloca %0) 109 ret %struct.A* %3 110} 111 112; CHECK-LABEL: i_thunk_preallocated: 113; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 114; CHECK: jmpl 115; CHECK-NOT: ret 116define x86_thiscallcc %struct.A* @i_thunk_preallocated(%struct.B* %this, <{ %struct.A*, %struct.A, i32, %struct.A }>* preallocated(<{ %struct.A*, %struct.A, i32, %struct.A }>)) { 117entry: 118 %1 = bitcast %struct.B* %this to %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*** 119 %vtable = load %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)**, %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*** %1 120 %vfn = getelementptr inbounds %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*, %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)** %vtable, i32 3 121 %2 = load %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)*, %struct.A* (%struct.B*, <{ %struct.A*, %struct.A, i32, %struct.A }>*)** %vfn 122 %3 = musttail call x86_thiscallcc %struct.A* %2(%struct.B* %this, <{ %struct.A*, %struct.A, i32, %struct.A }>* preallocated(<{ %struct.A*, %struct.A, i32, %struct.A }>) %0) 123 ret %struct.A* %3 124} 125 126; CHECK-LABEL: j_thunk: 127; CHECK: jmpl 128; CHECK-NOT: ret 129define x86_thiscallcc void @j_thunk(%struct.A* noalias sret %agg.result, %struct.B* %this, i32) { 130entry: 131 %1 = bitcast %struct.B* %this to void (%struct.A*, %struct.B*, i32)*** 132 %vtable = load void (%struct.A*, %struct.B*, i32)**, void (%struct.A*, %struct.B*, i32)*** %1 133 %vfn = getelementptr inbounds void (%struct.A*, %struct.B*, i32)*, void (%struct.A*, %struct.B*, i32)** %vtable, i32 4 134 %2 = load void (%struct.A*, %struct.B*, i32)*, void (%struct.A*, %struct.B*, i32)** %vfn 135 musttail call x86_thiscallcc void %2(%struct.A* sret %agg.result, %struct.B* %this, i32 %0) 136 ret void 137} 138 139; CHECK-LABEL: _stdcall_thunk@8: 140; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 141; CHECK: jmpl 142; CHECK-NOT: ret 143define x86_stdcallcc i32 @stdcall_thunk(<{ %struct.B*, %struct.A }>* inalloca) { 144entry: 145 %this_ptr = getelementptr inbounds <{ %struct.B*, %struct.A }>, <{ %struct.B*, %struct.A }>* %0, i32 0, i32 0 146 %this = load %struct.B*, %struct.B** %this_ptr 147 %1 = bitcast %struct.B* %this to i32 (<{ %struct.B*, %struct.A }>*)*** 148 %vtable = load i32 (<{ %struct.B*, %struct.A }>*)**, i32 (<{ %struct.B*, %struct.A }>*)*** %1 149 %vfn = getelementptr inbounds i32 (<{ %struct.B*, %struct.A }>*)*, i32 (<{ %struct.B*, %struct.A }>*)** %vtable, i32 1 150 %2 = load i32 (<{ %struct.B*, %struct.A }>*)*, i32 (<{ %struct.B*, %struct.A }>*)** %vfn 151 %3 = musttail call x86_stdcallcc i32 %2(<{ %struct.B*, %struct.A }>* inalloca %0) 152 ret i32 %3 153} 154 155; CHECK-LABEL: _stdcall_thunk_preallocated@8: 156; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 157; CHECK: jmpl 158; CHECK-NOT: ret 159define x86_stdcallcc i32 @stdcall_thunk_preallocated(<{ %struct.B*, %struct.A }>* preallocated(<{ %struct.B*, %struct.A }>)) { 160entry: 161 %this_ptr = getelementptr inbounds <{ %struct.B*, %struct.A }>, <{ %struct.B*, %struct.A }>* %0, i32 0, i32 0 162 %this = load %struct.B*, %struct.B** %this_ptr 163 %1 = bitcast %struct.B* %this to i32 (<{ %struct.B*, %struct.A }>*)*** 164 %vtable = load i32 (<{ %struct.B*, %struct.A }>*)**, i32 (<{ %struct.B*, %struct.A }>*)*** %1 165 %vfn = getelementptr inbounds i32 (<{ %struct.B*, %struct.A }>*)*, i32 (<{ %struct.B*, %struct.A }>*)** %vtable, i32 1 166 %2 = load i32 (<{ %struct.B*, %struct.A }>*)*, i32 (<{ %struct.B*, %struct.A }>*)** %vfn 167 %3 = musttail call x86_stdcallcc i32 %2(<{ %struct.B*, %struct.A }>* preallocated(<{ %struct.B*, %struct.A }>) %0) 168 ret i32 %3 169} 170 171; CHECK-LABEL: @fastcall_thunk@8: 172; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 173; CHECK: jmpl 174; CHECK-NOT: ret 175define x86_fastcallcc i32 @fastcall_thunk(%struct.B* inreg %this, <{ %struct.A }>* inalloca) { 176entry: 177 %1 = bitcast %struct.B* %this to i32 (%struct.B*, <{ %struct.A }>*)*** 178 %vtable = load i32 (%struct.B*, <{ %struct.A }>*)**, i32 (%struct.B*, <{ %struct.A }>*)*** %1 179 %vfn = getelementptr inbounds i32 (%struct.B*, <{ %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A }>*)** %vtable, i32 1 180 %2 = load i32 (%struct.B*, <{ %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A }>*)** %vfn 181 %3 = musttail call x86_fastcallcc i32 %2(%struct.B* inreg %this, <{ %struct.A }>* inalloca %0) 182 ret i32 %3 183} 184 185; CHECK-LABEL: @fastcall_thunk_preallocated@8: 186; CHECK-NOT: mov %{{.*}}, {{.*(.*esp.*)}} 187; CHECK: jmpl 188; CHECK-NOT: ret 189define x86_fastcallcc i32 @fastcall_thunk_preallocated(%struct.B* inreg %this, <{ %struct.A }>* preallocated(<{ %struct.A }>)) { 190entry: 191 %1 = bitcast %struct.B* %this to i32 (%struct.B*, <{ %struct.A }>*)*** 192 %vtable = load i32 (%struct.B*, <{ %struct.A }>*)**, i32 (%struct.B*, <{ %struct.A }>*)*** %1 193 %vfn = getelementptr inbounds i32 (%struct.B*, <{ %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A }>*)** %vtable, i32 1 194 %2 = load i32 (%struct.B*, <{ %struct.A }>*)*, i32 (%struct.B*, <{ %struct.A }>*)** %vfn 195 %3 = musttail call x86_fastcallcc i32 %2(%struct.B* inreg %this, <{ %struct.A }>* preallocated(<{ %struct.A }>) %0) 196 ret i32 %3 197} 198