1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
3 target datalayout = "e-p:64:64"
4 target triple = "x86_64-unknown-linux-gnu"
6 @vt1 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf0 to i8*)], !type !0
7 @vt2 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf0 to i8*)], !type !0, !type !1
8 @vt3 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf1 to i8*)], !type !0, !type !1
9 @vt4 = constant [1 x i8*] [i8* bitcast (i1 (i8*)* @vf1 to i8*)], !type !1
11 define i1 @vf0(i8* %this) readnone {
15 define i1 @vf1(i8* %this) readnone {
19 ; CHECK: define i1 @call1
20 define i1 @call1(i8* %obj) {
21 %vtableptr = bitcast i8* %obj to [1 x i8*]**
22 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
23 ; CHECK: {{.*}} = bitcast [1 x i8*]* {{.*}} to i8*
24 ; CHECK: [[VT1:%[^ ]*]] = bitcast [1 x i8*]* {{.*}} to i8*
25 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
26 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
27 call void @llvm.assume(i1 %p)
28 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
29 %fptr = load i8*, i8** %fptrptr
30 %fptr_casted = bitcast i8* %fptr to i1 (i8*)*
31 ; CHECK: [[RES1:%[^ ]*]] = icmp eq i8* [[VT1]], bitcast ([1 x i8*]* @vt3 to i8*)
32 %result = call i1 %fptr_casted(i8* %obj)
33 ; CHECK: ret i1 [[RES1]]
37 ; CHECK: define i32 @call2
38 define i32 @call2(i8* %obj) {
39 %vtableptr = bitcast i8* %obj to [1 x i8*]**
40 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
41 ; CHECK: [[VT2:%[^ ]*]] = bitcast [1 x i8*]* {{.*}} to i8*
42 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
43 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid2")
44 call void @llvm.assume(i1 %p)
45 %fptrptr = getelementptr [1 x i8*], [1 x i8*]* %vtable, i32 0, i32 0
46 %fptr = load i8*, i8** %fptrptr
47 ; Intentional type mismatch to test zero extend.
48 %fptr_casted = bitcast i8* %fptr to i32 (i8*)*
49 ; CHECK: [[RES2:%[^ ]*]] = icmp ne i8* [[VT1]], bitcast ([1 x i8*]* @vt2 to i8*)
50 %result = call i32 %fptr_casted(i8* %obj)
51 ; CHECK: [[ZEXT2:%[^ ]*]] = zext i1 [[RES2]] to i32
52 ; CHECK: ret i32 [[ZEXT2:%[^ ]*]]
56 declare i1 @llvm.type.test(i8*, metadata)
57 declare void @llvm.assume(i1)
59 !0 = !{i32 0, !"typeid1"}
60 !1 = !{i32 0, !"typeid2"}