1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s 2 3 target datalayout = "e-p:64:64" 4 target triple = "x86_64-unknown-linux-gnu" 5 6 ; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [0 x i8], [4 x i8*], [8 x i8] } { [0 x i8] zeroinitializer, [4 x i8*] [i8* null, i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf1i32 to i8*)], [8 x i8] c"\01\00\00\00\01\00\00\00" }, !type [[T8:![0-9]+]] 7 @vt1 = constant [4 x i8*] [ 8 i8* null, 9 i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 10 i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 11 i8* bitcast (i32 (i8*)* @vf1i32 to i8*) 12 ], !type !1 13 14 ; CHECK: [[VT2DATA:@[^ ]*]] = private constant { [0 x i8], [3 x i8*], [8 x i8] } { [0 x i8] zeroinitializer, [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf2i32 to i8*)], [8 x i8] c"\02\00\00\00\02\00\00\00" }, !type [[T0:![0-9]+]] 15 @vt2 = constant [3 x i8*] [ 16 i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 17 i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 18 i8* bitcast (i32 (i8*)* @vf2i32 to i8*) 19 ], !type !0 20 21 ; CHECK: [[VT3DATA:@[^ ]*]] = private constant { [0 x i8], [4 x i8*], [8 x i8] } { [0 x i8] zeroinitializer, [4 x i8*] [i8* null, i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf3i32 to i8*)], [8 x i8] c"\03\00\00\00\01\00\00\00" }, !type [[T8]] 22 @vt3 = constant [4 x i8*] [ 23 i8* null, 24 i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 25 i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 26 i8* bitcast (i32 (i8*)* @vf3i32 to i8*) 27 ], !type !1 28 29 ; CHECK: [[VT4DATA:@[^ ]*]] = private constant { [0 x i8], [3 x i8*], [8 x i8] } { [0 x i8] zeroinitializer, [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf4i32 to i8*)], [8 x i8] c"\04\00\00\00\02\00\00\00" }, !type [[T0]] 30 @vt4 = constant [3 x i8*] [ 31 i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 32 i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 33 i8* bitcast (i32 (i8*)* @vf4i32 to i8*) 34 ], !type !0 35 36 ; CHECK: @vt1 = alias [4 x i8*], getelementptr inbounds ({ [0 x i8], [4 x i8*], [8 x i8] }, { [0 x i8], [4 x i8*], [8 x i8] }* [[VT1DATA]], i32 0, i32 1) 37 ; CHECK: @vt2 = alias [3 x i8*], getelementptr inbounds ({ [0 x i8], [3 x i8*], [8 x i8] }, { [0 x i8], [3 x i8*], [8 x i8] }* [[VT2DATA]], i32 0, i32 1) 38 ; CHECK: @vt3 = alias [4 x i8*], getelementptr inbounds ({ [0 x i8], [4 x i8*], [8 x i8] }, { [0 x i8], [4 x i8*], [8 x i8] }* [[VT3DATA]], i32 0, i32 1) 39 ; CHECK: @vt4 = alias [3 x i8*], getelementptr inbounds ({ [0 x i8], [3 x i8*], [8 x i8] }, { [0 x i8], [3 x i8*], [8 x i8] }* [[VT4DATA]], i32 0, i32 1) 40 41 define i1 @vf0i1(i8* %this) readnone { 42 ret i1 0 43 } 44 45 define i1 @vf1i1(i8* %this) readnone { 46 ret i1 1 47 } 48 49 define i32 @vf1i32(i8* %this) readnone { 50 ret i32 1 51 } 52 53 define i32 @vf2i32(i8* %this) readnone { 54 ret i32 2 55 } 56 57 define i32 @vf3i32(i8* %this) readnone { 58 ret i32 3 59 } 60 61 define i32 @vf4i32(i8* %this) readnone { 62 ret i32 4 63 } 64 65 ; CHECK: define i1 @call1( 66 define i1 @call1(i8* %obj) { 67 %vtableptr = bitcast i8* %obj to [3 x i8*]** 68 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 69 ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 70 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 71 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") 72 call void @llvm.assume(i1 %p) 73 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0 74 %fptr = load i8*, i8** %fptrptr 75 %fptr_casted = bitcast i8* %fptr to i1 (i8*)* 76 ; CHECK: [[VTGEP1:%[^ ]*]] = getelementptr i8, i8* [[VT1]], i64 28 77 ; CHECK: [[VTLOAD1:%[^ ]*]] = load i8, i8* [[VTGEP1]] 78 ; CHECK: [[VTAND1:%[^ ]*]] = and i8 [[VTLOAD1]], 2 79 ; CHECK: [[VTCMP1:%[^ ]*]] = icmp ne i8 [[VTAND1]], 0 80 %result = call i1 %fptr_casted(i8* %obj) 81 ; CHECK: ret i1 [[VTCMP1]] 82 ret i1 %result 83 } 84 85 ; CHECK: define i1 @call2( 86 define i1 @call2(i8* %obj) { 87 %vtableptr = bitcast i8* %obj to [3 x i8*]** 88 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 89 ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 90 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 91 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") 92 call void @llvm.assume(i1 %p) 93 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 1 94 %fptr = load i8*, i8** %fptrptr 95 %fptr_casted = bitcast i8* %fptr to i1 (i8*)* 96 ; CHECK: [[VTGEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2]], i64 28 97 ; CHECK: [[VTLOAD2:%[^ ]*]] = load i8, i8* [[VTGEP2]] 98 ; CHECK: [[VTAND2:%[^ ]*]] = and i8 [[VTLOAD2]], 1 99 ; CHECK: [[VTCMP2:%[^ ]*]] = icmp ne i8 [[VTAND2]], 0 100 %result = call i1 %fptr_casted(i8* %obj) 101 ; CHECK: ret i1 [[VTCMP2]] 102 ret i1 %result 103 } 104 105 ; CHECK: define i32 @call3( 106 define i32 @call3(i8* %obj) { 107 %vtableptr = bitcast i8* %obj to [3 x i8*]** 108 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 109 ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 110 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 111 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") 112 call void @llvm.assume(i1 %p) 113 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 2 114 %fptr = load i8*, i8** %fptrptr 115 %fptr_casted = bitcast i8* %fptr to i32 (i8*)* 116 ; CHECK: [[VTGEP3:%[^ ]*]] = getelementptr i8, i8* [[VT3]], i64 24 117 ; CHECK: [[VTBC3:%[^ ]*]] = bitcast i8* [[VTGEP3]] to i32* 118 ; CHECK: [[VTLOAD3:%[^ ]*]] = load i32, i32* [[VTBC3]] 119 %result = call i32 %fptr_casted(i8* %obj) 120 ; CHECK: ret i32 [[VTLOAD3]] 121 ret i32 %result 122 } 123 124 declare i1 @llvm.type.test(i8*, metadata) 125 declare void @llvm.assume(i1) 126 127 ; CHECK: [[T8]] = !{i32 8, !"typeid"} 128 ; CHECK: [[T0]] = !{i32 0, !"typeid"} 129 130 !0 = !{i32 0, !"typeid"} 131 !1 = !{i32 8, !"typeid"} 132