blob: c24c3b4be68323c2439f34ad435e8c36b3820ea6 [file] [log] [blame]
Peter Collingbournedf49d1b2016-02-09 22:50:34 +00001; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2
3target datalayout = "e-p:64:64"
4target triple = "x86_64-unknown-linux-gnu"
5
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +00006@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
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000010
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000011define i64 @vf1(i8* %this, i128 %arg) readnone {
12 %argtrunc = trunc i128 %arg to i64
13 ret i64 %argtrunc
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000014}
15
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000016define i64 @vf2(i8* %this, i128 %arg) readnone {
17 %argtrunc = trunc i128 %arg to i64
18 ret i64 %argtrunc
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000019}
20
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000021define 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) {
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000033 %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*
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000036 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000037 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
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000040 %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)*
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000056 ; CHECK: call i128 %
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000057 %result = call i128 %fptr_casted(i8* %obj, i64 1)
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000058 ret i128 %result
59}
60
Peter Collingbourne7efd7502016-06-24 21:21:32 +000061declare i1 @llvm.type.test(i8*, metadata)
Peter Collingbournedf49d1b2016-02-09 22:50:34 +000062declare void @llvm.assume(i1)
63
Peter Collingbourne50cbd7c2017-02-15 21:56:51 +000064!0 = !{i32 0, !"typeid1"}
65!1 = !{i32 0, !"typeid2"}