blob: 6057c68410c745c621f246218b039031ac69d194 [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 Collingbourne6d284fa2017-03-09 00:21:25 +00005
6target datalayout = "e-p:64:64"
7target triple = "x86_64-unknown-linux-gnu"
8
Peter Collingbourne0152c812017-03-09 01:11:15 +00009; Test cases where the argument values are known and we can apply virtual
10; constant propagation.
11
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000012; CHECK: define i32 @call1
13define i32 @call1(i8* %obj) {
14 %vtableptr = bitcast i8* %obj to [3 x i8*]**
15 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
16 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
17 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
18 call void @llvm.assume(i1 %p)
19 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0
20 %fptr = load i8*, i8** %fptrptr
21 %fptr_casted = bitcast i8* %fptr to i32 (i8*, i32)*
22 ; SINGLE-IMPL: call i32 bitcast (void ()* @singleimpl1 to i32 (i8*, i32)*)
23 %result = call i32 %fptr_casted(i8* %obj, i32 1)
Peter Collingbourne0152c812017-03-09 01:11:15 +000024 ; UNIFORM-RET-VAL: ret i32 42
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000025 ret i32 %result
26}
27
Peter Collingbourne0152c812017-03-09 01:11:15 +000028; Test cases where the argument values are unknown, so we cannot apply virtual
29; constant propagation.
30
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000031; CHECK: define i1 @call2
32define i1 @call2(i8* %obj) {
33 %vtableptr = bitcast i8* %obj to [1 x i8*]**
34 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
35 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
36 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2")
37 %fptr = extractvalue {i8*, i1} %pair, 0
38 %p = extractvalue {i8*, i1} %pair, 1
39 ; SINGLE-IMPL: br i1 true,
40 br i1 %p, label %cont, label %trap
41
42cont:
43 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
44 ; SINGLE-IMPL: call i1 bitcast (void ()* @singleimpl2 to i1 (i8*, i32)*)
Peter Collingbourne0152c812017-03-09 01:11:15 +000045 ; UNIFORM-RET-VAL: call i1 %
Peter Collingbourne59675ba2017-03-10 20:09:11 +000046 ; UNIQUE-RET-VAL0: call i1 %
47 ; UNIQUE-RET-VAL1: call i1 %
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000048 %result = call i1 %fptr_casted(i8* %obj, i32 undef)
49 ret i1 %result
50
51trap:
52 call void @llvm.trap()
53 unreachable
54}
55
Peter Collingbourne59675ba2017-03-10 20:09:11 +000056; CHECK: define i1 @call3
57define i1 @call3(i8* %obj) {
58 %vtableptr = bitcast i8* %obj to [1 x i8*]**
59 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
60 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
61 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2")
62 %fptr = extractvalue {i8*, i1} %pair, 0
63 %p = extractvalue {i8*, i1} %pair, 1
64 br i1 %p, label %cont, label %trap
65
66cont:
67 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
68 %result = call i1 %fptr_casted(i8* %obj, i32 3)
69 ; UNIQUE-RET-VAL0: icmp ne i8* %vtablei8, @__typeid_typeid2_8_3_unique_member
70 ; UNIQUE-RET-VAL1: icmp eq i8* %vtablei8, @__typeid_typeid2_8_3_unique_member
71 ret i1 %result
72
73trap:
74 call void @llvm.trap()
75 unreachable
76}
77
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000078; SINGLE-IMPL-DAG: declare void @singleimpl1()
79; SINGLE-IMPL-DAG: declare void @singleimpl2()
80
81declare void @llvm.assume(i1)
82declare void @llvm.trap()
83declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
84declare i1 @llvm.type.test(i8*, metadata)