blob: 7f34b04ce1193658ad5d3631cafeec7c9f124db4 [file] [log] [blame]
Peter Collingbourne6d284fa2017-03-09 00:21:25 +00001; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s | FileCheck --check-prefixes=CHECK,SINGLE-IMPL %s
Peter Collingbourne0152c812017-03-09 01:11:15 +00002; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-uniform-ret-val.yaml < %s | FileCheck --check-prefixes=CHECK,UNIFORM-RET-VAL %s
Peter Collingbourne59675ba2017-03-10 20:09:11 +00003; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-unique-ret-val0.yaml < %s | FileCheck --check-prefixes=CHECK,UNIQUE-RET-VAL0 %s
4; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-unique-ret-val1.yaml < %s | FileCheck --check-prefixes=CHECK,UNIQUE-RET-VAL1 %s
Peter Collingbourne14dcf022017-03-10 20:13:58 +00005; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp.yaml < %s | FileCheck --check-prefixes=CHECK,VCP,VCP64 %s
6; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp.yaml -mtriple=i686-unknown-linux -data-layout=e-p:32:32 < %s | FileCheck --check-prefixes=CHECK,VCP,VCP32 %s
Peter Collingbourne6d284fa2017-03-09 00:21:25 +00007
8target datalayout = "e-p:64:64"
9target triple = "x86_64-unknown-linux-gnu"
10
Peter Collingbourne14dcf022017-03-10 20:13:58 +000011; VCP: @__typeid_typeid1_0_1_byte = external hidden global i8, !absolute_symbol !0
12; VCP: @__typeid_typeid1_0_1_bit = external hidden global i8, !absolute_symbol !1
13; VCP: @__typeid_typeid2_8_3_byte = external hidden global i8, !absolute_symbol !0
14; VCP: @__typeid_typeid2_8_3_bit = external hidden global i8, !absolute_symbol !1
15
Peter Collingbourne0152c812017-03-09 01:11:15 +000016; Test cases where the argument values are known and we can apply virtual
17; constant propagation.
18
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000019; CHECK: define i32 @call1
20define i32 @call1(i8* %obj) {
21 %vtableptr = bitcast i8* %obj to [3 x i8*]**
22 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
23 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
24 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
25 call void @llvm.assume(i1 %p)
26 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0
27 %fptr = load i8*, i8** %fptrptr
28 %fptr_casted = bitcast i8* %fptr to i32 (i8*, i32)*
29 ; SINGLE-IMPL: call i32 bitcast (void ()* @singleimpl1 to i32 (i8*, i32)*)
30 %result = call i32 %fptr_casted(i8* %obj, i32 1)
Peter Collingbourne0152c812017-03-09 01:11:15 +000031 ; UNIFORM-RET-VAL: ret i32 42
Peter Collingbourne14dcf022017-03-10 20:13:58 +000032 ; VCP: [[VT1:%.*]] = bitcast {{.*}} to i8*
33 ; VCP: [[GEP1:%.*]] = getelementptr i8, i8* [[VT1]], i32 ptrtoint (i8* @__typeid_typeid1_0_1_byte to i32)
34 ; VCP: [[BC1:%.*]] = bitcast i8* [[GEP1]] to i32*
35 ; VCP: [[LOAD1:%.*]] = load i32, i32* [[BC1]]
36 ; VCP: ret i32 [[LOAD1]]
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000037 ret i32 %result
38}
39
Peter Collingbourne0152c812017-03-09 01:11:15 +000040; Test cases where the argument values are unknown, so we cannot apply virtual
41; constant propagation.
42
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000043; CHECK: define i1 @call2
44define i1 @call2(i8* %obj) {
45 %vtableptr = bitcast i8* %obj to [1 x i8*]**
46 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
47 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
48 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2")
49 %fptr = extractvalue {i8*, i1} %pair, 0
50 %p = extractvalue {i8*, i1} %pair, 1
51 ; SINGLE-IMPL: br i1 true,
52 br i1 %p, label %cont, label %trap
53
54cont:
55 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
56 ; SINGLE-IMPL: call i1 bitcast (void ()* @singleimpl2 to i1 (i8*, i32)*)
Peter Collingbourne0152c812017-03-09 01:11:15 +000057 ; UNIFORM-RET-VAL: call i1 %
Peter Collingbourne59675ba2017-03-10 20:09:11 +000058 ; UNIQUE-RET-VAL0: call i1 %
59 ; UNIQUE-RET-VAL1: call i1 %
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000060 %result = call i1 %fptr_casted(i8* %obj, i32 undef)
61 ret i1 %result
62
63trap:
64 call void @llvm.trap()
65 unreachable
66}
67
Peter Collingbourne59675ba2017-03-10 20:09:11 +000068; CHECK: define i1 @call3
69define i1 @call3(i8* %obj) {
70 %vtableptr = bitcast i8* %obj to [1 x i8*]**
71 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
72 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
73 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2")
74 %fptr = extractvalue {i8*, i1} %pair, 0
75 %p = extractvalue {i8*, i1} %pair, 1
76 br i1 %p, label %cont, label %trap
77
78cont:
79 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
80 %result = call i1 %fptr_casted(i8* %obj, i32 3)
81 ; UNIQUE-RET-VAL0: icmp ne i8* %vtablei8, @__typeid_typeid2_8_3_unique_member
82 ; UNIQUE-RET-VAL1: icmp eq i8* %vtablei8, @__typeid_typeid2_8_3_unique_member
Peter Collingbourne14dcf022017-03-10 20:13:58 +000083 ; VCP: [[VT2:%.*]] = bitcast {{.*}} to i8*
84 ; VCP: [[GEP2:%.*]] = getelementptr i8, i8* [[VT2]], i32 ptrtoint (i8* @__typeid_typeid2_8_3_byte to i32)
85 ; VCP: [[LOAD2:%.*]] = load i8, i8* [[GEP2]]
86 ; VCP: [[AND2:%.*]] = and i8 [[LOAD2]], ptrtoint (i8* @__typeid_typeid2_8_3_bit to i8)
87 ; VCP: [[ICMP2:%.*]] = icmp ne i8 [[AND2]], 0
88 ; VCP: ret i1 [[ICMP2]]
Peter Collingbourne59675ba2017-03-10 20:09:11 +000089 ret i1 %result
90
91trap:
92 call void @llvm.trap()
93 unreachable
94}
95
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000096; SINGLE-IMPL-DAG: declare void @singleimpl1()
97; SINGLE-IMPL-DAG: declare void @singleimpl2()
98
Peter Collingbourne14dcf022017-03-10 20:13:58 +000099; VCP32: !0 = !{i32 -1, i32 -1}
100; VCP64: !0 = !{i64 0, i64 4294967296}
101
102; VCP32: !1 = !{i32 0, i32 256}
103; VCP64: !1 = !{i64 0, i64 256}
104
Peter Collingbourne6d284fa2017-03-09 00:21:25 +0000105declare void @llvm.assume(i1)
106declare void @llvm.trap()
107declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
108declare i1 @llvm.type.test(i8*, metadata)