1 ; RUN: opt -S -passes=wholeprogramdevirt %s | FileCheck %s
3 ; Test that we correctly expand the llvm.type.checked.load.relative intrinsic in
4 ; cases where we cannot devirtualize.
6 target datalayout = "e-p:64:64"
7 target triple = "x86_64-unknown-linux-gnu"
9 @vt1 = constant { [2 x i32] } { [2 x i32] [
10 i32 trunc (i64 sub (i64 ptrtoint (ptr @vf1 to i64), i64 ptrtoint (ptr @vt1 to i64)) to i32),
11 i32 trunc (i64 sub (i64 ptrtoint (ptr @vf2 to i64), i64 ptrtoint (ptr @vt1 to i64)) to i32)
12 ]}, align 8, !type !0, !type !1
14 !0 = !{i64 0, !"vfunc1.type"}
15 !1 = !{i64 4, !"vfunc2.type"}
18 define void @vf1(ptr %this) {
22 define void @vf2(ptr %this) {
26 ; CHECK: define void @call
27 ; CHECK: [[TT:%.*]] = call i1 @llvm.type.test(ptr [[VT:%.*]], metadata !"vfunc1.type")
30 ; Relative pointer computation at the address of the i32 value to the i32 value
31 ; to get to the pointer value.
33 ; CHECK: [[T0:%.*]] = getelementptr i8, ptr [[VT]], i32 0
34 ; CHECK: [[T1:%.*]] = load i32, ptr [[T0]]
35 ; CHECK: [[T2:%.*]] = sext i32 [[T1]] to i64
36 ; CHECK: [[T3:%.*]] = ptrtoint ptr [[T0]] to i64
37 ; CHECK: [[T4:%.*]] = add i64 [[T3]], [[T2]]
38 ; CHECK: [[F:%.*]] = inttoptr i64 [[T4]] to ptr
39 ; CHECK: call void [[F]](ptr
41 define void @call(ptr %obj) {
42 %vtable = load ptr, ptr %obj
43 %pair = call {ptr, i1} @llvm.type.checked.load.relative(ptr %vtable, i32 0, metadata !"vfunc1.type")
44 %p = extractvalue {ptr, i1} %pair, 1
45 br i1 %p, label %cont, label %trap
48 %fptr = extractvalue {ptr, i1} %pair, 0
49 call void %fptr(ptr %obj)
53 call void @llvm.trap()
57 declare {ptr, i1} @llvm.type.checked.load.relative(ptr, i32, metadata)
58 declare void @llvm.trap()