1*9880d681SAndroid Build Coastguard Worker; RUN: opt -S -Os < %s | FileCheck %s 2*9880d681SAndroid Build Coastguard Workertarget 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" 3*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-darwin10.0.0" 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker; Simple devirt testcase, requires iteration between inliner and GVN. 7*9880d681SAndroid Build Coastguard Worker; rdar://6295824 8*9880d681SAndroid Build Coastguard Workerdefine i32 @foo(i32 ()** noalias %p, i64* noalias %q) nounwind ssp { 9*9880d681SAndroid Build Coastguard Workerentry: 10*9880d681SAndroid Build Coastguard Worker store i32 ()* @bar, i32 ()** %p 11*9880d681SAndroid Build Coastguard Worker store i64 0, i64* %q 12*9880d681SAndroid Build Coastguard Worker %tmp3 = load i32 ()*, i32 ()** %p ; <i32 ()*> [#uses=1] 13*9880d681SAndroid Build Coastguard Worker %call = call i32 %tmp3() ; <i32> [#uses=1] 14*9880d681SAndroid Build Coastguard Worker %X = add i32 %call, 4 15*9880d681SAndroid Build Coastguard Worker ret i32 %X 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: @foo( 18*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: entry: 19*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store 20*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store 21*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i32 11 22*9880d681SAndroid Build Coastguard Worker} 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Workerdefine internal i32 @bar() nounwind ssp { 25*9880d681SAndroid Build Coastguard Workerentry: 26*9880d681SAndroid Build Coastguard Worker ret i32 7 27*9880d681SAndroid Build Coastguard Worker} 28*9880d681SAndroid Build Coastguard Worker 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker;; More complex devirt case, from PR6724 31*9880d681SAndroid Build Coastguard Worker; CHECK: @_Z1gv() 32*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: entry: 33*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ret i32 7 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker%0 = type { i8*, i8* } 36*9880d681SAndroid Build Coastguard Worker%1 = type { i8*, i8*, i32, i32, i8*, i64, i8*, i64 } 37*9880d681SAndroid Build Coastguard Worker%2 = type { i8*, i8*, i8* } 38*9880d681SAndroid Build Coastguard Worker%struct.A = type { i8** } 39*9880d681SAndroid Build Coastguard Worker%struct.B = type { i8** } 40*9880d681SAndroid Build Coastguard Worker%struct.C = type { [16 x i8] } 41*9880d681SAndroid Build Coastguard Worker%struct.D = type { [16 x i8] } 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard Worker@_ZTV1D = linkonce_odr constant [6 x i8*] [i8* null, i8* bitcast (%2* @_ZTI1D to i8*), i8* bitcast (i32 (%struct.C*)* @_ZN1D1fEv to i8*), i8* inttoptr (i64 -8 to i8*), i8* bitcast (%2* @_ZTI1D to i8*), i8* bitcast (i32 (%struct.C*)* @_ZThn8_N1D1fEv to i8*)] ; <[6 x i8*]*> [#uses=2] 44*9880d681SAndroid Build Coastguard Worker@_ZTVN10__cxxabiv120__si_class_type_infoE = external global i8* ; <i8**> [#uses=1] 45*9880d681SAndroid Build Coastguard Worker@_ZTS1D = linkonce_odr constant [3 x i8] c"1D\00" ; <[3 x i8]*> [#uses=1] 46*9880d681SAndroid Build Coastguard Worker@_ZTVN10__cxxabiv121__vmi_class_type_infoE = external global i8* ; <i8**> [#uses=1] 47*9880d681SAndroid Build Coastguard Worker@_ZTS1C = linkonce_odr constant [3 x i8] c"1C\00" ; <[3 x i8]*> [#uses=1] 48*9880d681SAndroid Build Coastguard Worker@_ZTVN10__cxxabiv117__class_type_infoE = external global i8* ; <i8**> [#uses=1] 49*9880d681SAndroid Build Coastguard Worker@_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00" ; <[3 x i8]*> [#uses=1] 50*9880d681SAndroid Build Coastguard Worker@_ZTI1A = linkonce_odr constant %0 { 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) } ; <%0*> [#uses=1] 51*9880d681SAndroid Build Coastguard Worker@_ZTS1B = linkonce_odr constant [3 x i8] c"1B\00" ; <[3 x i8]*> [#uses=1] 52*9880d681SAndroid Build Coastguard Worker@_ZTI1B = linkonce_odr constant %0 { 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]* @_ZTS1B, i32 0, i32 0) } ; <%0*> [#uses=1] 53*9880d681SAndroid Build Coastguard Worker@_ZTI1C = linkonce_odr constant %1 { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1C, i32 0, i32 0), i32 0, i32 2, i8* bitcast (%0* @_ZTI1A to i8*), i64 2, i8* bitcast (%0* @_ZTI1B to i8*), i64 2050 } ; <%1*> [#uses=1] 54*9880d681SAndroid Build Coastguard Worker@_ZTI1D = linkonce_odr constant %2 { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1D, i32 0, i32 0), i8* bitcast (%1* @_ZTI1C to i8*) } ; <%2*> [#uses=1] 55*9880d681SAndroid Build Coastguard Worker@_ZTV1C = linkonce_odr constant [6 x i8*] [i8* null, i8* bitcast (%1* @_ZTI1C to i8*), i8* bitcast (i32 (%struct.C*)* @_ZN1C1fEv to i8*), i8* inttoptr (i64 -8 to i8*), i8* bitcast (%1* @_ZTI1C to i8*), i8* bitcast (i32 (%struct.C*)* @_ZThn8_N1C1fEv to i8*)] ; <[6 x i8*]*> [#uses=2] 56*9880d681SAndroid Build Coastguard Worker@_ZTV1B = linkonce_odr constant [3 x i8*] [i8* null, i8* bitcast (%0* @_ZTI1B to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1B1fEv to i8*)] ; <[3 x i8*]*> [#uses=1] 57*9880d681SAndroid Build Coastguard Worker@_ZTV1A = linkonce_odr constant [3 x i8*] [i8* null, i8* bitcast (%0* @_ZTI1A to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A1fEv to i8*)] ; <[3 x i8*]*> [#uses=1] 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Workerdefine i32 @_Z1gv() ssp { 60*9880d681SAndroid Build Coastguard Workerentry: 61*9880d681SAndroid Build Coastguard Worker %d = alloca %struct.C, align 8 ; <%struct.C*> [#uses=2] 62*9880d681SAndroid Build Coastguard Worker call void @_ZN1DC1Ev(%struct.C* %d) 63*9880d681SAndroid Build Coastguard Worker %call = call i32 @_Z1fP1D(%struct.C* %d) ; <i32> [#uses=1] 64*9880d681SAndroid Build Coastguard Worker %X = add i32 %call, 3 65*9880d681SAndroid Build Coastguard Worker ret i32 %X 66*9880d681SAndroid Build Coastguard Worker} 67*9880d681SAndroid Build Coastguard Worker 68*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr void @_ZN1DC1Ev(%struct.C* %this) inlinehint ssp align 2 { 69*9880d681SAndroid Build Coastguard Workerentry: 70*9880d681SAndroid Build Coastguard Worker call void @_ZN1DC2Ev(%struct.C* %this) 71*9880d681SAndroid Build Coastguard Worker ret void 72*9880d681SAndroid Build Coastguard Worker} 73*9880d681SAndroid Build Coastguard Worker 74*9880d681SAndroid Build Coastguard Workerdefine internal i32 @_Z1fP1D(%struct.C* %d) ssp { 75*9880d681SAndroid Build Coastguard Workerentry: 76*9880d681SAndroid Build Coastguard Worker %0 = icmp eq %struct.C* %d, null ; <i1> [#uses=1] 77*9880d681SAndroid Build Coastguard Worker br i1 %0, label %cast.end, label %cast.notnull 78*9880d681SAndroid Build Coastguard Worker 79*9880d681SAndroid Build Coastguard Workercast.notnull: ; preds = %entry 80*9880d681SAndroid Build Coastguard Worker %1 = bitcast %struct.C* %d to i8* ; <i8*> [#uses=1] 81*9880d681SAndroid Build Coastguard Worker %add.ptr = getelementptr i8, i8* %1, i64 8 ; <i8*> [#uses=1] 82*9880d681SAndroid Build Coastguard Worker %2 = bitcast i8* %add.ptr to %struct.A* ; <%struct.A*> [#uses=1] 83*9880d681SAndroid Build Coastguard Worker br label %cast.end 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Workercast.end: ; preds = %entry, %cast.notnull 86*9880d681SAndroid Build Coastguard Worker %3 = phi %struct.A* [ %2, %cast.notnull ], [ null, %entry ] ; <%struct.A*> [#uses=2] 87*9880d681SAndroid Build Coastguard Worker %4 = bitcast %struct.A* %3 to i32 (%struct.A*)*** ; <i32 (%struct.A*)***> [#uses=1] 88*9880d681SAndroid Build Coastguard Worker %5 = load i32 (%struct.A*)**, i32 (%struct.A*)*** %4 ; <i32 (%struct.A*)**> [#uses=1] 89*9880d681SAndroid Build Coastguard Worker %vfn = getelementptr inbounds i32 (%struct.A*)*, i32 (%struct.A*)** %5, i64 0 ; <i32 (%struct.A*)**> [#uses=1] 90*9880d681SAndroid Build Coastguard Worker %6 = load i32 (%struct.A*)*, i32 (%struct.A*)** %vfn ; <i32 (%struct.A*)*> [#uses=1] 91*9880d681SAndroid Build Coastguard Worker %call = call i32 %6(%struct.A* %3) ; <i32> [#uses=1] 92*9880d681SAndroid Build Coastguard Worker ret i32 %call 93*9880d681SAndroid Build Coastguard Worker} 94*9880d681SAndroid Build Coastguard Worker 95*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZN1D1fEv(%struct.C* %this) ssp align 2 { 96*9880d681SAndroid Build Coastguard Workerentry: 97*9880d681SAndroid Build Coastguard Worker ret i32 4 98*9880d681SAndroid Build Coastguard Worker} 99*9880d681SAndroid Build Coastguard Worker 100*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZThn8_N1D1fEv(%struct.C* %this) { 101*9880d681SAndroid Build Coastguard Workerentry: 102*9880d681SAndroid Build Coastguard Worker %0 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 103*9880d681SAndroid Build Coastguard Worker %1 = getelementptr inbounds i8, i8* %0, i64 -8 ; <i8*> [#uses=1] 104*9880d681SAndroid Build Coastguard Worker %2 = bitcast i8* %1 to %struct.C* ; <%struct.C*> [#uses=1] 105*9880d681SAndroid Build Coastguard Worker %call = call i32 @_ZN1D1fEv(%struct.C* %2) ; <i32> [#uses=1] 106*9880d681SAndroid Build Coastguard Worker ret i32 %call 107*9880d681SAndroid Build Coastguard Worker} 108*9880d681SAndroid Build Coastguard Worker 109*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr void @_ZN1DC2Ev(%struct.C* %this) inlinehint ssp align 2 { 110*9880d681SAndroid Build Coastguard Workerentry: 111*9880d681SAndroid Build Coastguard Worker call void @_ZN1CC2Ev(%struct.C* %this) 112*9880d681SAndroid Build Coastguard Worker %0 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 113*9880d681SAndroid Build Coastguard Worker %1 = getelementptr inbounds i8, i8* %0, i64 0 ; <i8*> [#uses=1] 114*9880d681SAndroid Build Coastguard Worker %2 = bitcast i8* %1 to i8*** ; <i8***> [#uses=1] 115*9880d681SAndroid Build Coastguard Worker store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @_ZTV1D, i64 0, i64 2), i8*** %2 116*9880d681SAndroid Build Coastguard Worker %3 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 117*9880d681SAndroid Build Coastguard Worker %4 = getelementptr inbounds i8, i8* %3, i64 8 ; <i8*> [#uses=1] 118*9880d681SAndroid Build Coastguard Worker %5 = bitcast i8* %4 to i8*** ; <i8***> [#uses=1] 119*9880d681SAndroid Build Coastguard Worker store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @_ZTV1D, i64 0, i64 5), i8*** %5 120*9880d681SAndroid Build Coastguard Worker ret void 121*9880d681SAndroid Build Coastguard Worker} 122*9880d681SAndroid Build Coastguard Worker 123*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr void @_ZN1CC2Ev(%struct.C* %this) inlinehint ssp align 2 { 124*9880d681SAndroid Build Coastguard Workerentry: 125*9880d681SAndroid Build Coastguard Worker %0 = bitcast %struct.C* %this to %struct.A* ; <%struct.A*> [#uses=1] 126*9880d681SAndroid Build Coastguard Worker call void @_ZN1AC2Ev(%struct.A* %0) 127*9880d681SAndroid Build Coastguard Worker %1 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 128*9880d681SAndroid Build Coastguard Worker %2 = getelementptr inbounds i8, i8* %1, i64 8 ; <i8*> [#uses=1] 129*9880d681SAndroid Build Coastguard Worker %3 = bitcast i8* %2 to %struct.A* ; <%struct.A*> [#uses=1] 130*9880d681SAndroid Build Coastguard Worker call void @_ZN1BC2Ev(%struct.A* %3) 131*9880d681SAndroid Build Coastguard Worker %4 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 132*9880d681SAndroid Build Coastguard Worker %5 = getelementptr inbounds i8, i8* %4, i64 0 ; <i8*> [#uses=1] 133*9880d681SAndroid Build Coastguard Worker %6 = bitcast i8* %5 to i8*** ; <i8***> [#uses=1] 134*9880d681SAndroid Build Coastguard Worker store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @_ZTV1C, i64 0, i64 2), i8*** %6 135*9880d681SAndroid Build Coastguard Worker %7 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 136*9880d681SAndroid Build Coastguard Worker %8 = getelementptr inbounds i8, i8* %7, i64 8 ; <i8*> [#uses=1] 137*9880d681SAndroid Build Coastguard Worker %9 = bitcast i8* %8 to i8*** ; <i8***> [#uses=1] 138*9880d681SAndroid Build Coastguard Worker store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @_ZTV1C, i64 0, i64 5), i8*** %9 139*9880d681SAndroid Build Coastguard Worker ret void 140*9880d681SAndroid Build Coastguard Worker} 141*9880d681SAndroid Build Coastguard Worker 142*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZN1C1fEv(%struct.C* %this) ssp align 2 { 143*9880d681SAndroid Build Coastguard Workerentry: 144*9880d681SAndroid Build Coastguard Worker ret i32 3 145*9880d681SAndroid Build Coastguard Worker} 146*9880d681SAndroid Build Coastguard Worker 147*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZThn8_N1C1fEv(%struct.C* %this) { 148*9880d681SAndroid Build Coastguard Workerentry: 149*9880d681SAndroid Build Coastguard Worker %0 = bitcast %struct.C* %this to i8* ; <i8*> [#uses=1] 150*9880d681SAndroid Build Coastguard Worker %1 = getelementptr inbounds i8, i8* %0, i64 -8 ; <i8*> [#uses=1] 151*9880d681SAndroid Build Coastguard Worker %2 = bitcast i8* %1 to %struct.C* ; <%struct.C*> [#uses=1] 152*9880d681SAndroid Build Coastguard Worker %call = call i32 @_ZN1C1fEv(%struct.C* %2) ; <i32> [#uses=1] 153*9880d681SAndroid Build Coastguard Worker ret i32 %call 154*9880d681SAndroid Build Coastguard Worker} 155*9880d681SAndroid Build Coastguard Worker 156*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr void @_ZN1AC2Ev(%struct.A* %this) inlinehint ssp align 2 { 157*9880d681SAndroid Build Coastguard Workerentry: 158*9880d681SAndroid Build Coastguard Worker %0 = bitcast %struct.A* %this to i8* ; <i8*> [#uses=1] 159*9880d681SAndroid Build Coastguard Worker %1 = getelementptr inbounds i8, i8* %0, i64 0 ; <i8*> [#uses=1] 160*9880d681SAndroid Build Coastguard Worker %2 = bitcast i8* %1 to i8*** ; <i8***> [#uses=1] 161*9880d681SAndroid Build Coastguard Worker store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTV1A, i64 0, i64 2), i8*** %2 162*9880d681SAndroid Build Coastguard Worker ret void 163*9880d681SAndroid Build Coastguard Worker} 164*9880d681SAndroid Build Coastguard Worker 165*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr void @_ZN1BC2Ev(%struct.A* %this) inlinehint ssp align 2 { 166*9880d681SAndroid Build Coastguard Workerentry: 167*9880d681SAndroid Build Coastguard Worker %0 = bitcast %struct.A* %this to i8* ; <i8*> [#uses=1] 168*9880d681SAndroid Build Coastguard Worker %1 = getelementptr inbounds i8, i8* %0, i64 0 ; <i8*> [#uses=1] 169*9880d681SAndroid Build Coastguard Worker %2 = bitcast i8* %1 to i8*** ; <i8***> [#uses=1] 170*9880d681SAndroid Build Coastguard Worker store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @_ZTV1B, i64 0, i64 2), i8*** %2 171*9880d681SAndroid Build Coastguard Worker ret void 172*9880d681SAndroid Build Coastguard Worker} 173*9880d681SAndroid Build Coastguard Worker 174*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZN1B1fEv(%struct.A* %this) ssp align 2 { 175*9880d681SAndroid Build Coastguard Workerentry: 176*9880d681SAndroid Build Coastguard Worker ret i32 2 177*9880d681SAndroid Build Coastguard Worker} 178*9880d681SAndroid Build Coastguard Worker 179*9880d681SAndroid Build Coastguard Workerdefine linkonce_odr i32 @_ZN1A1fEv(%struct.A* %this) ssp align 2 { 180*9880d681SAndroid Build Coastguard Workerentry: 181*9880d681SAndroid Build Coastguard Worker ret i32 1 182*9880d681SAndroid Build Coastguard Worker} 183