• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -wholeprogramdevirt %s | FileCheck %s
2
3; Test that we correctly expand the llvm.type.checked.load intrinsic in cases
4; where we cannot devirtualize.
5
6target datalayout = "e-p:64:64"
7target triple = "x86_64-unknown-linux-gnu"
8
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
11
12define void @vf1(i8* %this) {
13  ret void
14}
15
16define void @vf2(i8* %this) {
17  ret void
18}
19
20; CHECK: define void @call
21define 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
30
31cont:
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)
40  ret void
41
42trap:
43  call void @llvm.trap()
44  unreachable
45}
46
47; CHECK: define { i8*, i1 } @ret
48define {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]]
57  ret {i8*, i1} %pair
58}
59
60declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
61declare void @llvm.trap()
62
63!0 = !{i32 0, !"typeid"}
64