1 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s | FileCheck --check-prefixes=CHECK,SINGLE-IMPL %s
2 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-uniform-ret-val.yaml < %s | FileCheck --check-prefixes=CHECK,INDIR,UNIFORM-RET-VAL %s
3 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-unique-ret-val0.yaml < %s | FileCheck --check-prefixes=CHECK,INDIR,UNIQUE-RET-VAL0 %s
4 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-unique-ret-val1.yaml < %s | FileCheck --check-prefixes=CHECK,INDIR,UNIQUE-RET-VAL1 %s
5 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp.yaml < %s | FileCheck --check-prefixes=CHECK,VCP,VCP-X86,VCP64,INDIR %s
6 ; RUN: opt -S -passes=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,VCP-X86,VCP32 %s
7 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp.yaml -mtriple=armv7-unknown-linux -data-layout=e-p:32:32 < %s | FileCheck --check-prefixes=CHECK,VCP,VCP-ARM %s
8 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp-branch-funnel.yaml < %s | FileCheck --check-prefixes=CHECK,VCP,VCP-X86,VCP64,BRANCH-FUNNEL %s
9 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-branch-funnel.yaml < %s | FileCheck --check-prefixes=CHECK,BRANCH-FUNNEL,BRANCH-FUNNEL-NOVCP %s
11 target datalayout = "e-p:64:64"
12 target triple = "x86_64-unknown-linux-gnu"
14 ; VCP-X86: @__typeid_typeid1_0_1_byte = external hidden global [0 x i8], !absolute_symbol !0
15 ; VCP-X86: @__typeid_typeid1_0_1_bit = external hidden global [0 x i8], !absolute_symbol !1
16 ; VCP-X86: @__typeid_typeid2_8_3_byte = external hidden global [0 x i8], !absolute_symbol !0
17 ; VCP-X86: @__typeid_typeid2_8_3_bit = external hidden global [0 x i8], !absolute_symbol !1
19 ; Test cases where the argument values are known and we can apply virtual
20 ; constant propagation.
22 ; CHECK: define i32 @call1
23 define i32 @call1(ptr %obj) #0 {
24 %vtable = load ptr, ptr %obj
25 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid1")
26 call void @llvm.assume(i1 %p)
27 %fptr = load ptr, ptr %vtable
28 ; SINGLE-IMPL: call i32 @singleimpl1
29 %result = call i32 %fptr(ptr %obj, i32 1)
30 ; UNIFORM-RET-VAL: ret i32 42
31 ; VCP-X86: [[GEP1:%.*]] = getelementptr i8, ptr %vtable, i32 ptrtoint (ptr @__typeid_typeid1_0_1_byte to i32)
32 ; VCP-ARM: [[GEP1:%.*]] = getelementptr i8, ptr %vtable, i32 42
33 ; VCP: [[LOAD1:%.*]] = load i32, ptr [[GEP1]]
34 ; VCP: ret i32 [[LOAD1]]
35 ; BRANCH-FUNNEL-NOVCP: call i32 @__typeid_typeid1_0_branch_funnel(ptr nest %vtable, ptr %obj, i32 1)
39 ; Test cases where the argument values are unknown, so we cannot apply virtual
40 ; constant propagation.
42 ; CHECK: define i1 @call2
43 define i1 @call2(ptr %obj) #0 {
44 %vtable = load ptr, ptr %obj
45 %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 8, metadata !"typeid2")
46 %fptr = extractvalue {ptr, i1} %pair, 0
47 %p = extractvalue {ptr, i1} %pair, 1
48 ; SINGLE-IMPL: br i1 true,
49 br i1 %p, label %cont, label %trap
52 ; SINGLE-IMPL: call i1 @singleimpl2
54 ; BRANCH-FUNNEL: call i1 @__typeid_typeid2_8_branch_funnel(ptr nest %vtable, ptr %obj, i32 undef)
55 %result = call i1 %fptr(ptr %obj, i32 undef)
59 call void @llvm.trap()
63 ; CHECK: define i1 @call3
64 define i1 @call3(ptr %obj) #0 {
65 %vtable = load ptr, ptr %obj
66 %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 8, metadata !"typeid2")
67 %fptr = extractvalue {ptr, i1} %pair, 0
68 %p = extractvalue {ptr, i1} %pair, 1
69 br i1 %p, label %cont, label %trap
72 %result = call i1 %fptr(ptr %obj, i32 3)
73 ; UNIQUE-RET-VAL0: icmp ne ptr %vtable, @__typeid_typeid2_8_3_unique_member
74 ; UNIQUE-RET-VAL1: icmp eq ptr %vtable, @__typeid_typeid2_8_3_unique_member
75 ; VCP-X86: [[GEP2:%.*]] = getelementptr i8, ptr %vtable, i32 ptrtoint (ptr @__typeid_typeid2_8_3_byte to i32)
76 ; VCP-ARM: [[GEP2:%.*]] = getelementptr i8, ptr %vtable, i32 43
77 ; VCP: [[LOAD2:%.*]] = load i8, ptr [[GEP2]]
78 ; VCP-X86: [[AND2:%.*]] = and i8 [[LOAD2]], ptrtoint (ptr @__typeid_typeid2_8_3_bit to i8)
79 ; VCP-ARM: [[AND2:%.*]] = and i8 [[LOAD2]], -128
80 ; VCP: [[ICMP2:%.*]] = icmp ne i8 [[AND2]], 0
81 ; VCP: ret i1 [[ICMP2]]
82 ; BRANCH-FUNNEL-NOVCP: call i1 @__typeid_typeid2_8_branch_funnel(ptr nest %vtable, ptr %obj, i32 3)
86 call void @llvm.trap()
90 ; SINGLE-IMPL-DAG: declare void @singleimpl1()
91 ; SINGLE-IMPL-DAG: declare void @singleimpl2()
93 ; VCP32: !0 = !{i32 -1, i32 -1}
94 ; VCP64: !0 = !{i64 0, i64 4294967296}
96 ; VCP32: !1 = !{i32 0, i32 256}
97 ; VCP64: !1 = !{i64 0, i64 256}
99 declare void @llvm.assume(i1)
100 declare void @llvm.trap()
101 declare {ptr, i1} @llvm.type.checked.load(ptr, i32, metadata)
102 declare i1 @llvm.type.test(ptr, metadata)
104 attributes #0 = { "target-features"="+retpoline" }