1 ; RUN: opt -S -Os < %s | FileCheck %s
2 ; RUN: opt -S -aa-pipeline=basic-aa -passes='default<Os>' < %s | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
4 target triple = "x86_64-apple-darwin10.0.0"
7 ; Simple devirt testcase, requires iteration between inliner and GVN.
9 define i32 @foo(ptr noalias %p, ptr noalias %q) nounwind ssp {
11 store ptr @bar, ptr %p
13 %tmp3 = load ptr, ptr %p ; <ptr> [#uses=1]
14 %call = call i32 %tmp3() ; <i32> [#uses=1]
22 ; CHECK-NEXT: ret i32 11
25 define internal i32 @bar() nounwind ssp {
31 ;; More complex devirt case, from PR6724
34 ; CHECK-NEXT: ret i32 7
36 %0 = type { ptr, ptr }
37 %1 = type { ptr, ptr, i32, i32, ptr, i64, ptr, i64 }
38 %2 = type { ptr, ptr, ptr }
39 %struct.A = type { ptr }
40 %struct.B = type { ptr }
41 %struct.C = type { [16 x i8] }
42 %struct.D = type { [16 x i8] }
44 @_ZTV1D = linkonce_odr constant [6 x ptr] [ptr null, ptr @_ZTI1D, ptr @_ZN1D1fEv, ptr inttoptr (i64 -8 to ptr), ptr @_ZTI1D, ptr @_ZThn8_N1D1fEv] ; <ptr> [#uses=2]
45 @_ZTVN10__cxxabiv120__si_class_type_infoE = external global ptr ; <ptr> [#uses=1]
46 @_ZTS1D = linkonce_odr constant [3 x i8] c"1D\00" ; <ptr> [#uses=1]
47 @_ZTVN10__cxxabiv121__vmi_class_type_infoE = external global ptr ; <ptr> [#uses=1]
48 @_ZTS1C = linkonce_odr constant [3 x i8] c"1C\00" ; <ptr> [#uses=1]
49 @_ZTVN10__cxxabiv117__class_type_infoE = external global ptr ; <ptr> [#uses=1]
50 @_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00" ; <ptr> [#uses=1]
51 @_ZTI1A = linkonce_odr constant %0 { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1A } ; <ptr> [#uses=1]
52 @_ZTS1B = linkonce_odr constant [3 x i8] c"1B\00" ; <ptr> [#uses=1]
53 @_ZTI1B = linkonce_odr constant %0 { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1B } ; <ptr> [#uses=1]
54 @_ZTI1C = linkonce_odr constant %1 { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i64 2), ptr @_ZTS1C, i32 0, i32 2, ptr @_ZTI1A, i64 2, ptr @_ZTI1B, i64 2050 } ; <ptr> [#uses=1]
55 @_ZTI1D = linkonce_odr constant %2 { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2), ptr @_ZTS1D, ptr @_ZTI1C } ; <ptr> [#uses=1]
56 @_ZTV1C = linkonce_odr constant [6 x ptr] [ptr null, ptr @_ZTI1C, ptr @_ZN1C1fEv, ptr inttoptr (i64 -8 to ptr), ptr @_ZTI1C, ptr @_ZThn8_N1C1fEv] ; <ptr> [#uses=2]
57 @_ZTV1B = linkonce_odr constant [3 x ptr] [ptr null, ptr @_ZTI1B, ptr @_ZN1B1fEv] ; <ptr> [#uses=1]
58 @_ZTV1A = linkonce_odr constant [3 x ptr] [ptr null, ptr @_ZTI1A, ptr @_ZN1A1fEv] ; <ptr> [#uses=1]
60 define i32 @_Z1gv() ssp {
62 %d = alloca %struct.C, align 8 ; <ptr> [#uses=2]
63 call void @_ZN1DC1Ev(ptr %d)
64 %call = call i32 @_Z1fP1D(ptr %d) ; <i32> [#uses=1]
69 define linkonce_odr void @_ZN1DC1Ev(ptr %this) inlinehint ssp align 2 {
71 call void @_ZN1DC2Ev(ptr %this)
75 define internal i32 @_Z1fP1D(ptr %d) ssp {
77 %0 = icmp eq ptr %d, null ; <i1> [#uses=1]
78 br i1 %0, label %cast.end, label %cast.notnull
80 cast.notnull: ; preds = %entry
81 %add.ptr = getelementptr i8, ptr %d, i64 8 ; <ptr> [#uses=1]
84 cast.end: ; preds = %entry, %cast.notnull
85 %1 = phi ptr [ %add.ptr, %cast.notnull ], [ null, %entry ] ; <ptr> [#uses=2]
86 %2 = load ptr, ptr %1 ; <ptr> [#uses=1]
87 %vfn = getelementptr inbounds ptr, ptr %2, i64 0 ; <ptr> [#uses=1]
88 %3 = load ptr, ptr %vfn ; <ptr> [#uses=1]
89 %call = call i32 %3(ptr %1) ; <i32> [#uses=1]
93 define linkonce_odr i32 @_ZN1D1fEv(ptr %this) ssp align 2 {
98 define linkonce_odr i32 @_ZThn8_N1D1fEv(ptr %this) ssp {
100 %0 = getelementptr inbounds i8, ptr %this, i64 -8 ; <ptr> [#uses=1]
101 %call = call i32 @_ZN1D1fEv(ptr %0) ; <i32> [#uses=1]
105 define linkonce_odr void @_ZN1DC2Ev(ptr %this) inlinehint ssp align 2 {
107 call void @_ZN1CC2Ev(ptr %this)
108 %0 = getelementptr inbounds i8, ptr %this, i64 0 ; <ptr> [#uses=1]
109 store ptr getelementptr inbounds ([6 x ptr], ptr @_ZTV1D, i64 0, i64 2), ptr %0
110 %1 = getelementptr inbounds i8, ptr %this, i64 8 ; <ptr> [#uses=1]
111 store ptr getelementptr inbounds ([6 x ptr], ptr @_ZTV1D, i64 0, i64 5), ptr %1
115 define linkonce_odr void @_ZN1CC2Ev(ptr %this) inlinehint ssp align 2 {
117 call void @_ZN1AC2Ev(ptr %this)
118 %0 = getelementptr inbounds i8, ptr %this, i64 8 ; <ptr> [#uses=1]
119 call void @_ZN1BC2Ev(ptr %0)
120 %1 = getelementptr inbounds i8, ptr %this, i64 0 ; <ptr> [#uses=1]
121 store ptr getelementptr inbounds ([6 x ptr], ptr @_ZTV1C, i64 0, i64 2), ptr %1
122 %2 = getelementptr inbounds i8, ptr %this, i64 8 ; <ptr> [#uses=1]
123 store ptr getelementptr inbounds ([6 x ptr], ptr @_ZTV1C, i64 0, i64 5), ptr %2
127 define linkonce_odr i32 @_ZN1C1fEv(ptr %this) ssp align 2 {
132 define linkonce_odr i32 @_ZThn8_N1C1fEv(ptr %this) {
134 %0 = getelementptr inbounds i8, ptr %this, i64 -8 ; <ptr> [#uses=1]
135 %call = call i32 @_ZN1C1fEv(ptr %0) ; <i32> [#uses=1]
139 define linkonce_odr void @_ZN1AC2Ev(ptr %this) inlinehint ssp align 2 {
141 %0 = getelementptr inbounds i8, ptr %this, i64 0 ; <ptr> [#uses=1]
142 store ptr getelementptr inbounds ([3 x ptr], ptr @_ZTV1A, i64 0, i64 2), ptr %0
146 define linkonce_odr void @_ZN1BC2Ev(ptr %this) inlinehint ssp align 2 {
148 %0 = getelementptr inbounds i8, ptr %this, i64 0 ; <ptr> [#uses=1]
149 store ptr getelementptr inbounds ([3 x ptr], ptr @_ZTV1B, i64 0, i64 2), ptr %0
153 define linkonce_odr i32 @_ZN1B1fEv(ptr %this) ssp align 2 {
158 define linkonce_odr i32 @_ZN1A1fEv(ptr %this) ssp align 2 {