1; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %s | FileCheck %s 2 3target datalayout = "e-p:64:64" 4target triple = "x86_64-unknown-linux-gnu" 5 6; CHECK: private constant { [8 x i8], [1 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\00\00\00\00\01", [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf1 to i8*)], [0 x i8] zeroinitializer }, !type [[T8:![0-9]+]] 7; CHECK: private constant { [8 x i8], [1 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\00\00\00\00\02", [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf2 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]] 8; CHECK: private constant { [8 x i8], [1 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\00\00\00\00\01", [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf4 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]] 9; CHECK: private constant { [8 x i8], [1 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\00\00\00\00\02", [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf8 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]] 10 11@vt1 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf1 to i8*)], !type !0 12@vt2 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf2 to i8*)], !type !0 13@vt4 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf4 to i8*)], !type !0 14@vt8 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf8 to i8*)], !type !0 15 16define i1 @vf1(i8* %this, i32 %arg) readnone { 17 %and = and i32 %arg, 1 18 %cmp = icmp ne i32 %and, 0 19 ret i1 %cmp 20} 21 22define i1 @vf2(i8* %this, i32 %arg) readnone { 23 %and = and i32 %arg, 2 24 %cmp = icmp ne i32 %and, 0 25 ret i1 %cmp 26} 27 28define i1 @vf4(i8* %this, i32 %arg) readnone { 29 %and = and i32 %arg, 4 30 %cmp = icmp ne i32 %and, 0 31 ret i1 %cmp 32} 33 34define i1 @vf8(i8* %this, i32 %arg) readnone { 35 %and = and i32 %arg, 8 36 %cmp = icmp ne i32 %and, 0 37 ret i1 %cmp 38} 39 40; CHECK: define i1 @call1 41define i1 @call1(i8* %obj) { 42 %vtableptr = bitcast i8* %obj to [1 x i8*]** 43 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr 44 %vtablei8 = bitcast [1 x i8*]* %vtable to i8* 45 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") 46 call void @llvm.assume(i1 %p) 47 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0 48 %fptr = load i8*, i8** %fptrptr 49 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)* 50 ; CHECK: getelementptr {{.*}} -1 51 ; CHECK: and {{.*}}, 1 52 %result = call i1 %fptr_casted(i8* %obj, i32 5) 53 ret i1 %result 54} 55 56; CHECK: define i1 @call2 57define i1 @call2(i8* %obj) { 58 %vtableptr = bitcast i8* %obj to [1 x i8*]** 59 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr 60 %vtablei8 = bitcast [1 x i8*]* %vtable to i8* 61 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") 62 call void @llvm.assume(i1 %p) 63 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0 64 %fptr = load i8*, i8** %fptrptr 65 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)* 66 ; CHECK: getelementptr {{.*}} -1 67 ; CHECK: and {{.*}}, 2 68 %result = call i1 %fptr_casted(i8* %obj, i32 10) 69 ret i1 %result 70} 71 72declare i1 @llvm.type.test(i8*, metadata) 73declare void @llvm.assume(i1) 74 75; CHECK: [[T8]] = !{i32 8, !"typeid"} 76!0 = !{i32 0, !"typeid"} 77