1 ; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
3 ; Test that we correctly expand the llvm.type.checked.load intrinsic in cases
4 ; where we cannot devirtualize.
6 target datalayout = "e-p:64:64"
7 target triple = "x86_64-unknown-linux-gnu"
9 @vt1 = constant [1 x i8*] [i8* bitcast (void (i8*)* @vf1 to i8*)], !type !0
10 @vt2 = constant [1 x i8*] [i8* bitcast (void (i8*)* @vf2 to i8*)], !type !0
12 define void @vf1(i8* %this) {
16 define void @vf2(i8* %this) {
20 ; CHECK: define void @call
21 define void @call(i8* %obj) {
22 %vtableptr = bitcast i8* %obj to [1 x i8*]**
23 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
24 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
25 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 0, metadata !"typeid")
26 %p = extractvalue {i8*, i1} %pair, 1
27 ; CHECK: [[TT:%[^ ]*]] = call i1 @llvm.type.test(i8* [[VT:%[^,]*]], metadata !"typeid")
28 ; CHECK: br i1 [[TT]],
29 br i1 %p, label %cont, label %trap
32 ; CHECK: [[GEP:%[^ ]*]] = getelementptr i8, i8* [[VT]], i32 0
33 ; CHECK: [[BC:%[^ ]*]] = bitcast i8* [[GEP]] to i8**
34 ; CHECK: [[LOAD:%[^ ]*]] = load i8*, i8** [[BC]]
35 ; CHECK: [[FPC:%[^ ]*]] = bitcast i8* [[LOAD]] to void (i8*)*
36 ; CHECK: call void [[FPC]]
37 %fptr = extractvalue {i8*, i1} %pair, 0
38 %fptr_casted = bitcast i8* %fptr to void (i8*)*
39 call void %fptr_casted(i8* %obj)
43 call void @llvm.trap()
47 ; CHECK: define { i8*, i1 } @ret
48 define {i8*, i1} @ret(i8* %vtablei8) {
49 ; CHECK: [[GEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2:%[^,]*]], i32 1
50 ; CHECK: [[BC2:%[^ ]*]] = bitcast i8* [[GEP2]] to i8**
51 ; CHECK: [[LOAD2:%[^ ]*]] = load i8*, i8** [[BC2]]
52 ; CHECK: [[TT2:%[^ ]*]] = call i1 @llvm.type.test(i8* [[VT2]], metadata !"typeid")
53 ; CHECK: [[I1:%[^ ]*]] = insertvalue { i8*, i1 } undef, i8* [[LOAD2]], 0
54 ; CHECK: [[I2:%[^ ]*]] = insertvalue { i8*, i1 } %5, i1 [[TT2]], 1
55 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 1, metadata !"typeid")
56 ; CHECK: ret { i8*, i1 } [[I2]]
60 declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
61 declare void @llvm.trap()
63 !0 = !{i32 0, !"typeid"}