1 ; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %s | FileCheck %s
3 target datalayout = "e-p:64:64"
4 target triple = "x86_64-unknown-linux-gnu"
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]]
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
16 define i1 @vf1(i8* %this, i32 %arg) readnone {
17 %and = and i32 %arg, 1
18 %cmp = icmp ne i32 %and, 0
22 define i1 @vf2(i8* %this, i32 %arg) readnone {
23 %and = and i32 %arg, 2
24 %cmp = icmp ne i32 %and, 0
28 define i1 @vf4(i8* %this, i32 %arg) readnone {
29 %and = and i32 %arg, 4
30 %cmp = icmp ne i32 %and, 0
34 define i1 @vf8(i8* %this, i32 %arg) readnone {
35 %and = and i32 %arg, 8
36 %cmp = icmp ne i32 %and, 0
40 ; CHECK: define i1 @call1
41 define 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)
56 ; CHECK: define i1 @call2
57 define 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)
72 declare i1 @llvm.type.test(i8*, metadata)
73 declare void @llvm.assume(i1)
75 ; CHECK: [[T8]] = !{i32 8, !"typeid"}
76 !0 = !{i32 0, !"typeid"}