1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2 ; RUN: opt -S -passes=wholeprogramdevirt %s | FileCheck %s
4 target datalayout = "e-p:64:64"
5 target triple = "x86_64-unknown-linux-gnu"
7 ; 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]+]]
8 ; 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]]
9 ; 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]]
10 ; 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]]
12 @vt1 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf1 to i8*)], !type !0
13 @vt2 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf2 to i8*)], !type !0
14 @vt4 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf4 to i8*)], !type !0
15 @vt8 = constant [1 x i8*] [i8* bitcast (i1 (i8*, i32)* @vf8 to i8*)], !type !0
17 define i1 @vf1(i8* %this, i32 %arg) readnone {
18 %and = and i32 %arg, 1
19 %cmp = icmp ne i32 %and, 0
23 define i1 @vf2(i8* %this, i32 %arg) readnone {
24 %and = and i32 %arg, 2
25 %cmp = icmp ne i32 %and, 0
29 define i1 @vf4(i8* %this, i32 %arg) readnone {
30 %and = and i32 %arg, 4
31 %cmp = icmp ne i32 %and, 0
35 define i1 @vf8(i8* %this, i32 %arg) readnone {
36 %and = and i32 %arg, 8
37 %cmp = icmp ne i32 %and, 0
41 ; CHECK: define i1 @call1
42 define i1 @call1(i8* %obj) {
43 %vtableptr = bitcast i8* %obj to [1 x i8*]**
44 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
45 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
46 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
47 call void @llvm.assume(i1 %p)
48 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
49 %fptr = load i8*, i8** %fptrptr
50 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
51 ; CHECK: getelementptr {{.*}} -1
52 ; CHECK: and {{.*}}, 1
53 %result = call i1 %fptr_casted(i8* %obj, i32 5)
57 ; CHECK: define i1 @call2
58 define i1 @call2(i8* %obj) {
59 %vtableptr = bitcast i8* %obj to [1 x i8*]**
60 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
61 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
62 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")
63 call void @llvm.assume(i1 %p)
64 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
65 %fptr = load i8*, i8** %fptrptr
66 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
67 ; CHECK: getelementptr {{.*}} -1
68 ; CHECK: and {{.*}}, 2
69 %result = call i1 %fptr_casted(i8* %obj, i32 10)
73 declare i1 @llvm.type.test(i8*, metadata)
74 declare void @llvm.assume(i1)
76 ; CHECK: [[T8]] = !{i32 8, !"typeid"}
77 !0 = !{i32 0, !"typeid"}