• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2
3target datalayout = "e-p:64:64"
4target triple = "x86_64-unknown-linux-gnu"
5
6@vt1 = constant [1 x i8*] [i8* bitcast (i64 (i8*, i128)* @vf1 to i8*)], !type !0
7@vt2 = constant [1 x i8*] [i8* bitcast (i64 (i8*, i128)* @vf2 to i8*)], !type !0
8@vt3 = constant [1 x i8*] [i8* bitcast (i128 (i8*, i64)* @vf3 to i8*)], !type !1
9@vt4 = constant [1 x i8*] [i8* bitcast (i128 (i8*, i64)* @vf4 to i8*)], !type !1
10
11define i64 @vf1(i8* %this, i128 %arg) readnone {
12  %argtrunc = trunc i128 %arg to i64
13  ret i64 %argtrunc
14}
15
16define i64 @vf2(i8* %this, i128 %arg) readnone {
17  %argtrunc = trunc i128 %arg to i64
18  ret i64 %argtrunc
19}
20
21define i128 @vf3(i8* %this, i64 %arg) readnone {
22  %argzext = zext i64 %arg to i128
23  ret i128 %argzext
24}
25
26define i128 @vf4(i8* %this, i64 %arg) readnone {
27  %argzext = zext i64 %arg to i128
28  ret i128 %argzext
29}
30
31; CHECK: define i64 @call1
32define i64 @call1(i8* %obj) {
33  %vtableptr = bitcast i8* %obj to [1 x i8*]**
34  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
35  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
36  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
37  call void @llvm.assume(i1 %p)
38  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
39  %fptr = load i8*, i8** %fptrptr
40  %fptr_casted = bitcast i8* %fptr to i64 (i8*, i128)*
41  ; CHECK: call i64 %
42  %result = call i64 %fptr_casted(i8* %obj, i128 1)
43  ret i64 %result
44}
45
46; CHECK: define i128 @call2
47define i128 @call2(i8* %obj) {
48  %vtableptr = bitcast i8* %obj to [1 x i8*]**
49  %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
50  %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
51  %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid2")
52  call void @llvm.assume(i1 %p)
53  %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
54  %fptr = load i8*, i8** %fptrptr
55  %fptr_casted = bitcast i8* %fptr to i128 (i8*, i64)*
56  ; CHECK: call i128 %
57  %result = call i128 %fptr_casted(i8* %obj, i64 1)
58  ret i128 %result
59}
60
61declare i1 @llvm.type.test(i8*, metadata)
62declare void @llvm.assume(i1)
63
64!0 = !{i32 0, !"typeid1"}
65!1 = !{i32 0, !"typeid2"}
66