• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2; RUN: opt -S -passes=wholeprogramdevirt %s | FileCheck %s
3
4target datalayout = "e-p:64:64"
5target triple = "x86_64-unknown-linux-gnu"
6
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]]
11
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
16
17define i1 @vf1(i8* %this, i32 %arg) readnone {
18  %and = and i32 %arg, 1
19  %cmp = icmp ne i32 %and, 0
20  ret i1 %cmp
21}
22
23define i1 @vf2(i8* %this, i32 %arg) readnone {
24  %and = and i32 %arg, 2
25  %cmp = icmp ne i32 %and, 0
26  ret i1 %cmp
27}
28
29define i1 @vf4(i8* %this, i32 %arg) readnone {
30  %and = and i32 %arg, 4
31  %cmp = icmp ne i32 %and, 0
32  ret i1 %cmp
33}
34
35define i1 @vf8(i8* %this, i32 %arg) readnone {
36  %and = and i32 %arg, 8
37  %cmp = icmp ne i32 %and, 0
38  ret i1 %cmp
39}
40
41; CHECK: define i1 @call1
42define 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)
54  ret i1 %result
55}
56
57; CHECK: define i1 @call2
58define 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)
70  ret i1 %result
71}
72
73declare i1 @llvm.type.test(i8*, metadata)
74declare void @llvm.assume(i1)
75
76; CHECK: [[T8]] = !{i32 8, !"typeid"}
77!0 = !{i32 0, !"typeid"}
78