1 ; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %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 ptr] [ptr @vf1], !type !0
10 @vt2 = constant [1 x ptr] [ptr @vf2], !type !0
12 define void @vf1(ptr %this) {
16 define void @vf2(ptr %this) {
20 ; CHECK: define void @call
21 define void @call(ptr %obj) {
22 %vtable = load ptr, ptr %obj
23 %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 0, metadata !"typeid")
24 %p = extractvalue {ptr, i1} %pair, 1
25 ; CHECK: [[TT:%[^ ]*]] = call i1 @llvm.type.test(ptr [[VT:%[^,]*]], metadata !"typeid")
26 ; CHECK: br i1 [[TT]],
27 br i1 %p, label %cont, label %trap
30 ; CHECK: [[GEP:%[^ ]*]] = getelementptr i8, ptr [[VT]], i32 0
31 ; CHECK: [[LOAD:%[^ ]*]] = load ptr, ptr [[GEP]]
32 ; CHECK: call void [[LOAD]]
33 %fptr = extractvalue {ptr, i1} %pair, 0
34 call void %fptr(ptr %obj)
38 call void @llvm.trap()
42 ; CHECK: define { ptr, i1 } @ret
43 define {ptr, i1} @ret(ptr %vtablei8) {
44 ; CHECK: [[GEP2:%[^ ]*]] = getelementptr i8, ptr [[VT2:%[^,]*]], i32 1
45 ; CHECK: [[LOAD2:%[^ ]*]] = load ptr, ptr [[GEP2]]
46 ; CHECK: [[TT2:%[^ ]*]] = call i1 @llvm.type.test(ptr %vtablei8, metadata !"typeid")
47 ; CHECK: [[I1:%[^ ]*]] = insertvalue { ptr, i1 } poison, ptr [[LOAD2]], 0
48 ; CHECK: [[I2:%[^ ]*]] = insertvalue { ptr, i1 } [[I1]], i1 [[TT2]], 1
49 %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtablei8, i32 1, metadata !"typeid")
50 ; CHECK: ret { ptr, i1 } [[I2]]
54 declare {ptr, i1} @llvm.type.checked.load(ptr, i32, metadata)
55 declare void @llvm.trap()
57 !0 = !{i32 0, !"typeid"}