1 ; RUN: opt < %s -passes='cgscc(devirt<4>(inline)),function(sroa,early-cse)' -S | FileCheck %s
2 ; RUN: opt < %s -passes='default<O3>' -S | FileCheck %s
4 ; Check that DoNotOptimize is inlined into Test.
11 ;void DoNotOptimize(const T& var) {
12 ; asm volatile("" : "+m"(const_cast<T&>(var)));
17 ; virtual void Run() = 0;
20 ;class Impl : public Interface {
23 ; void Run() { DoNotOptimize(this); }
29 ;static void IndirectRun(Interface& o) { o.Run(); }
36 %class.Impl = type <{ %class.Interface, i32, [4 x i8] }>
37 %class.Interface = type { i32 (...)** }
39 @_ZTV4Impl = linkonce_odr dso_local unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI4Impl to i8*), i8* bitcast (void (%class.Impl*)* @_ZN4Impl3RunEv to i8*)] }, align 8
40 @_ZTVN10__cxxabiv120__si_class_type_infoE = external dso_local global i8*
41 @_ZTS4Impl = linkonce_odr dso_local constant [6 x i8] c"4Impl\00", align 1
42 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
43 @_ZTS9Interface = linkonce_odr dso_local constant [11 x i8] c"9Interface\00", align 1
44 @_ZTI9Interface = linkonce_odr dso_local constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @_ZTS9Interface, i32 0, i32 0) }, align 8
45 @_ZTI4Impl = linkonce_odr dso_local constant { i8*, i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @_ZTS4Impl, i32 0, i32 0), i8* bitcast ({ i8*, i8* }* @_ZTI9Interface to i8*) }, align 8
46 @_ZTV9Interface = linkonce_odr dso_local unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI9Interface to i8*), i8* bitcast (void ()* @__cxa_pure_virtual to i8*)] }, align 8
48 define dso_local void @_Z4Testv() local_unnamed_addr {
50 %o = alloca %class.Impl, align 8
51 %0 = bitcast %class.Impl* %o to i8*
52 call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %0)
53 call void @_ZN4ImplC2Ev(%class.Impl* nonnull %o)
54 %1 = getelementptr inbounds %class.Impl, %class.Impl* %o, i64 0, i32 0
55 call fastcc void @_ZL11IndirectRunR9Interface(%class.Interface* nonnull dereferenceable(8) %1)
56 call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %0)
60 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
62 define linkonce_odr dso_local void @_ZN4ImplC2Ev(%class.Impl* %this) unnamed_addr align 2 {
64 %0 = getelementptr %class.Impl, %class.Impl* %this, i64 0, i32 0
65 call void @_ZN9InterfaceC2Ev(%class.Interface* %0)
66 %1 = getelementptr %class.Impl, %class.Impl* %this, i64 0, i32 0, i32 0
67 store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV4Impl, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %1, align 8
68 %f = getelementptr inbounds %class.Impl, %class.Impl* %this, i64 0, i32 1
69 store i32 3, i32* %f, align 8
73 define internal fastcc void @_ZL11IndirectRunR9Interface(%class.Interface* dereferenceable(8) %o) unnamed_addr {
75 %0 = bitcast %class.Interface* %o to void (%class.Interface*)***
76 %vtable = load void (%class.Interface*)**, void (%class.Interface*)*** %0, align 8
77 %1 = load void (%class.Interface*)*, void (%class.Interface*)** %vtable, align 8
78 call void %1(%class.Interface* nonnull %o)
82 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
84 define linkonce_odr dso_local void @_ZN9InterfaceC2Ev(%class.Interface* %this) unnamed_addr align 2 {
86 %0 = getelementptr %class.Interface, %class.Interface* %this, i64 0, i32 0
87 store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV9Interface, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
91 define linkonce_odr dso_local void @_ZN4Impl3RunEv(%class.Impl* %this) unnamed_addr align 2 {
93 %ref.tmp = alloca %class.Impl*, align 8
94 %0 = bitcast %class.Impl** %ref.tmp to i8*
95 call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0)
96 store %class.Impl* %this, %class.Impl** %ref.tmp, align 8
97 call void @_Z13DoNotOptimizeIP4ImplEvRKT_(%class.Impl** nonnull dereferenceable(8) %ref.tmp)
98 call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %0)
102 declare dso_local void @__cxa_pure_virtual() unnamed_addr
104 define linkonce_odr dso_local void @_Z13DoNotOptimizeIP4ImplEvRKT_(%class.Impl** dereferenceable(8) %var) local_unnamed_addr {
106 call void asm sideeffect "", "=*m,*m,~{dirflag},~{fpsr},~{flags}"(%class.Impl** nonnull %var, %class.Impl** nonnull %var)
111 ; Based on clang/test/CodeGenCXX/member-function-pointer-calls.cpp.
112 ; Check that vf1 and vf2 are inlined into g1 and g2.
121 ; virtual int vf1() { return 1; }
122 ; virtual int vf2() { return 2; }
125 ;int f(A* a, int (A::*fp)()) {
130 ; return f(&a, &A::vf1);
134 ; return f(&a, &A::vf2);
137 %struct.A = type { i32 (...)** }
139 @_ZTV1A = linkonce_odr unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A3vf1Ev to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A3vf2Ev to i8*)] }, align 8
140 @_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00", align 1
141 @_ZTI1A = linkonce_odr constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1A, i32 0, i32 0) }, align 8
143 define i32 @_Z1fP1AMS_FivE(%struct.A* %a, i64 %fp.coerce0, i64 %fp.coerce1) {
145 %0 = bitcast %struct.A* %a to i8*
146 %1 = getelementptr inbounds i8, i8* %0, i64 %fp.coerce1
147 %this.adjusted = bitcast i8* %1 to %struct.A*
148 %2 = and i64 %fp.coerce0, 1
149 %memptr.isvirtual = icmp eq i64 %2, 0
150 br i1 %memptr.isvirtual, label %memptr.nonvirtual, label %memptr.virtual
152 memptr.virtual: ; preds = %entry
153 %3 = bitcast i8* %1 to i8**
154 %vtable = load i8*, i8** %3, align 8
155 %4 = add i64 %fp.coerce0, -1
156 %5 = getelementptr i8, i8* %vtable, i64 %4
157 %6 = bitcast i8* %5 to i32 (%struct.A*)**
158 %memptr.virtualfn = load i32 (%struct.A*)*, i32 (%struct.A*)** %6, align 8
161 memptr.nonvirtual: ; preds = %entry
162 %memptr.nonvirtualfn = inttoptr i64 %fp.coerce0 to i32 (%struct.A*)*
165 memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
166 %7 = phi i32 (%struct.A*)* [ %memptr.virtualfn, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
167 %call = call i32 %7(%struct.A* %this.adjusted)
171 define i32 @_Z2g1v() {
173 %a = alloca %struct.A, align 8
174 %0 = bitcast %struct.A* %a to i8*
175 call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0)
176 call void @_ZN1AC1Ev(%struct.A* nonnull %a)
177 %call = call i32 @_Z1fP1AMS_FivE(%struct.A* nonnull %a, i64 1, i64 0)
178 call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %0)
182 define linkonce_odr void @_ZN1AC1Ev(%struct.A* %this) align 2 {
184 call void @_ZN1AC2Ev(%struct.A* %this)
188 define i32 @_Z2g2v() {
190 %a = alloca %struct.A, align 8
191 %0 = bitcast %struct.A* %a to i8*
192 call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0)
193 call void @_ZN1AC1Ev(%struct.A* nonnull %a)
194 %call = call i32 @_Z1fP1AMS_FivE(%struct.A* nonnull %a, i64 9, i64 0)
195 call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %0)
199 define linkonce_odr void @_ZN1AC2Ev(%struct.A* %this) align 2 {
201 %0 = getelementptr %struct.A, %struct.A* %this, i64 0, i32 0
202 store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
206 define linkonce_odr i32 @_ZN1A3vf1Ev(%struct.A* %this) align 2 {
211 define linkonce_odr i32 @_ZN1A3vf2Ev(%struct.A* %this) align 2 {