blob: b54eeb7314af545feabcaef01184f254312514d9 [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 Collingbourne6d284fa2017-03-09 00:21:25 +00003
4target datalayout = "e-p:64:64"
5target triple = "x86_64-unknown-linux-gnu"
6
Peter Collingbourne0152c812017-03-09 01:11:15 +00007; Test cases where the argument values are known and we can apply virtual
8; constant propagation.
9
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000010; CHECK: define i32 @call1
11define i32 @call1(i8* %obj) {
12 %vtableptr = bitcast i8* %obj to [3 x i8*]**
13 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr
14 %vtablei8 = bitcast [3 x i8*]* %vtable to i8*
15 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1")
16 call void @llvm.assume(i1 %p)
17 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0
18 %fptr = load i8*, i8** %fptrptr
19 %fptr_casted = bitcast i8* %fptr to i32 (i8*, i32)*
20 ; SINGLE-IMPL: call i32 bitcast (void ()* @singleimpl1 to i32 (i8*, i32)*)
21 %result = call i32 %fptr_casted(i8* %obj, i32 1)
Peter Collingbourne0152c812017-03-09 01:11:15 +000022 ; UNIFORM-RET-VAL: ret i32 42
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000023 ret i32 %result
24}
25
Peter Collingbourne0152c812017-03-09 01:11:15 +000026; Test cases where the argument values are unknown, so we cannot apply virtual
27; constant propagation.
28
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000029; CHECK: define i1 @call2
30define i1 @call2(i8* %obj) {
31 %vtableptr = bitcast i8* %obj to [1 x i8*]**
32 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr
33 %vtablei8 = bitcast [1 x i8*]* %vtable to i8*
34 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2")
35 %fptr = extractvalue {i8*, i1} %pair, 0
36 %p = extractvalue {i8*, i1} %pair, 1
37 ; SINGLE-IMPL: br i1 true,
38 br i1 %p, label %cont, label %trap
39
40cont:
41 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)*
42 ; SINGLE-IMPL: call i1 bitcast (void ()* @singleimpl2 to i1 (i8*, i32)*)
Peter Collingbourne0152c812017-03-09 01:11:15 +000043 ; UNIFORM-RET-VAL: call i1 %
Peter Collingbourne6d284fa2017-03-09 00:21:25 +000044 %result = call i1 %fptr_casted(i8* %obj, i32 undef)
45 ret i1 %result
46
47trap:
48 call void @llvm.trap()
49 unreachable
50}
51
52; SINGLE-IMPL-DAG: declare void @singleimpl1()
53; SINGLE-IMPL-DAG: declare void @singleimpl2()
54
55declare void @llvm.assume(i1)
56declare void @llvm.trap()
57declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata)
58declare i1 @llvm.type.test(i8*, metadata)