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 { ptr }
39 @_ZTV4Impl = linkonce_odr dso_local unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI4Impl, ptr @_ZN4Impl3RunEv] }, align 8
40 @_ZTVN10__cxxabiv120__si_class_type_infoE = external dso_local global ptr
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 ptr
43 @_ZTS9Interface = linkonce_odr dso_local constant [11 x i8] c"9Interface\00", align 1
44 @_ZTI9Interface = linkonce_odr dso_local constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS9Interface }, align 8
45 @_ZTI4Impl = linkonce_odr dso_local constant { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr @_ZTS4Impl, ptr @_ZTI9Interface }, align 8
46 @_ZTV9Interface = linkonce_odr dso_local unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI9Interface, ptr @__cxa_pure_virtual] }, align 8
48 define dso_local void @_Z4Testv() local_unnamed_addr {
50 %o = alloca %class.Impl, align 8
51 call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %o)
52 call void @_ZN4ImplC2Ev(ptr nonnull %o)
53 call fastcc void @_ZL11IndirectRunR9Interface(ptr nonnull dereferenceable(8) %o)
54 call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %o)
58 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
60 define linkonce_odr dso_local void @_ZN4ImplC2Ev(ptr %this) unnamed_addr align 2 {
62 call void @_ZN9InterfaceC2Ev(ptr %this)
63 store ptr getelementptr inbounds inrange(-16, 8) ({ [3 x ptr] }, ptr @_ZTV4Impl, i64 0, i32 0, i64 2), ptr %this, align 8
64 %f = getelementptr inbounds %class.Impl, ptr %this, i64 0, i32 1
65 store i32 3, ptr %f, align 8
69 define internal fastcc void @_ZL11IndirectRunR9Interface(ptr dereferenceable(8) %o) unnamed_addr {
71 %vtable = load ptr, ptr %o, align 8
72 %0 = load ptr, ptr %vtable, align 8
73 call void %0(ptr nonnull %o)
77 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
79 define linkonce_odr dso_local void @_ZN9InterfaceC2Ev(ptr %this) unnamed_addr align 2 {
81 store ptr getelementptr inbounds inrange(-16, 8) ({ [3 x ptr] }, ptr @_ZTV9Interface, i64 0, i32 0, i64 2), ptr %this, align 8
85 define linkonce_odr dso_local void @_ZN4Impl3RunEv(ptr %this) unnamed_addr align 2 {
87 %ref.tmp = alloca ptr, align 8
88 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %ref.tmp)
89 store ptr %this, ptr %ref.tmp, align 8
90 call void @_Z13DoNotOptimizeIP4ImplEvRKT_(ptr nonnull dereferenceable(8) %ref.tmp)
91 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %ref.tmp)
95 declare dso_local void @__cxa_pure_virtual() unnamed_addr
97 define linkonce_odr dso_local void @_Z13DoNotOptimizeIP4ImplEvRKT_(ptr dereferenceable(8) %var) local_unnamed_addr {
99 call void asm sideeffect "", "=*m,*m,~{dirflag},~{fpsr},~{flags}"(ptr elementtype(ptr) nonnull %var, ptr elementtype(ptr) nonnull %var)
104 ; Based on clang/test/CodeGenCXX/member-function-pointer-calls.cpp.
105 ; Check that vf1 and vf2 are inlined into g1 and g2.
114 ; virtual int vf1() { return 1; }
115 ; virtual int vf2() { return 2; }
118 ;int f(A* a, int (A::*fp)()) {
123 ; return f(&a, &A::vf1);
127 ; return f(&a, &A::vf2);
130 %struct.A = type { ptr }
132 @_ZTV1A = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr @_ZTI1A, ptr @_ZN1A3vf1Ev, ptr @_ZN1A3vf2Ev] }, align 8
133 @_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00", align 1
134 @_ZTI1A = linkonce_odr constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1A }, align 8
136 define i32 @_Z1fP1AMS_FivE(ptr %a, i64 %fp.coerce0, i64 %fp.coerce1) {
138 %0 = getelementptr inbounds i8, ptr %a, i64 %fp.coerce1
139 %1 = and i64 %fp.coerce0, 1
140 %memptr.isvirtual = icmp eq i64 %1, 0
141 br i1 %memptr.isvirtual, label %memptr.nonvirtual, label %memptr.virtual
143 memptr.virtual: ; preds = %entry
144 %vtable = load ptr, ptr %0, align 8
145 %2 = add i64 %fp.coerce0, -1
146 %3 = getelementptr i8, ptr %vtable, i64 %2
147 %memptr.virtualfn = load ptr, ptr %3, align 8
150 memptr.nonvirtual: ; preds = %entry
151 %memptr.nonvirtualfn = inttoptr i64 %fp.coerce0 to ptr
154 memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
155 %4 = phi ptr [ %memptr.virtualfn, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
156 %call = call i32 %4(ptr %0)
160 define i32 @_Z2g1v() {
162 %a = alloca %struct.A, align 8
163 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %a)
164 call void @_ZN1AC1Ev(ptr nonnull %a)
165 %call = call i32 @_Z1fP1AMS_FivE(ptr nonnull %a, i64 1, i64 0)
166 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %a)
170 define linkonce_odr void @_ZN1AC1Ev(ptr %this) align 2 {
172 call void @_ZN1AC2Ev(ptr %this)
176 define i32 @_Z2g2v() {
178 %a = alloca %struct.A, align 8
179 call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %a)
180 call void @_ZN1AC1Ev(ptr nonnull %a)
181 %call = call i32 @_Z1fP1AMS_FivE(ptr nonnull %a, i64 9, i64 0)
182 call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %a)
186 define linkonce_odr void @_ZN1AC2Ev(ptr %this) align 2 {
188 store ptr getelementptr inbounds inrange(-16, 8) ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, i32 0, i64 2), ptr %this, align 8
192 define linkonce_odr i32 @_ZN1A3vf1Ev(ptr %this) align 2 {
197 define linkonce_odr i32 @_ZN1A3vf2Ev(ptr %this) align 2 {