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 ; Cutoff value is not explicitly set. Expect 3 remark messages.
12 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s 2>&1 | grep "single-impl" | count 3
13 ; Cutoff value is set to 1. Expect one remark messages.
14 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-cutoff=1 -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s 2>&1 | grep "single-impl" | count 1
15 ; Cutoff value is explicitly set to zero. Expect no remark message.
16 ; RUN: opt -S -passes=wholeprogramdevirt -wholeprogramdevirt-summary-action=import -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-cutoff=0 -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s 2>&1 | FileCheck -implicit-check-not="remark" %s
17 target datalayout = "e-p:64:64"
18 target triple = "x86_64-unknown-linux-gnu"
20 ; VCP-X86: @__typeid_typeid1_0_1_byte = external hidden global [0 x i8], !absolute_symbol !0
21 ; VCP-X86: @__typeid_typeid1_0_1_bit = external hidden global [0 x i8], !absolute_symbol !1
22 ; VCP-X86: @__typeid_typeid2_8_3_byte = external hidden global [0 x i8], !absolute_symbol !0
23 ; VCP-X86: @__typeid_typeid2_8_3_bit = external hidden global [0 x i8], !absolute_symbol !1
25 ; Test cases where the argument values are known and we can apply virtual
26 ; constant propagation.
28 ; CHECK: define i32 @call1
29 define i32 @call1(ptr %obj) #0 {
30 %vtable = load ptr, ptr %obj
31 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid1")
32 call void @llvm.assume(i1 %p)
33 %fptr = load ptr, ptr %vtable
34 ; SINGLE-IMPL: call i32 @singleimpl1
35 %result = call i32 %fptr(ptr %obj, i32 1)
36 ; UNIFORM-RET-VAL: ret i32 42
37 ; VCP-X86: [[GEP1:%.*]] = getelementptr i8, ptr %vtable, i32 ptrtoint (ptr @__typeid_typeid1_0_1_byte to i32)
38 ; VCP-ARM: [[GEP1:%.*]] = getelementptr i8, ptr %vtable, i32 42
39 ; VCP: [[LOAD1:%.*]] = load i32, ptr [[GEP1]]
40 ; VCP: ret i32 [[LOAD1]]
41 ; BRANCH-FUNNEL-NOVCP: call i32 @__typeid_typeid1_0_branch_funnel(ptr nest %vtable, ptr %obj, i32 1)
45 ; Test cases where the argument values are unknown, so we cannot apply virtual
46 ; constant propagation.
48 ; CHECK: define i1 @call2
49 define i1 @call2(ptr %obj) #0 {
50 %vtable = load ptr, ptr %obj
51 %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 8, metadata !"typeid2")
52 %fptr = extractvalue {ptr, i1} %pair, 0
53 %p = extractvalue {ptr, i1} %pair, 1
54 ; SINGLE-IMPL: br i1 true,
55 br i1 %p, label %cont, label %trap
58 ; SINGLE-IMPL: call i1 @singleimpl2
60 ; BRANCH-FUNNEL: call i1 @__typeid_typeid2_8_branch_funnel(ptr nest %vtable, ptr %obj, i32 undef)
61 %result = call i1 %fptr(ptr %obj, i32 undef)
65 call void @llvm.trap()
69 ; CHECK: define i1 @call3
70 define i1 @call3(ptr %obj) #0 {
71 %vtable = load ptr, ptr %obj
72 %pair = call {ptr, i1} @llvm.type.checked.load(ptr %vtable, i32 8, metadata !"typeid2")
73 %fptr = extractvalue {ptr, i1} %pair, 0
74 %p = extractvalue {ptr, i1} %pair, 1
75 br i1 %p, label %cont, label %trap
78 %result = call i1 %fptr(ptr %obj, i32 3)
79 ; UNIQUE-RET-VAL0: icmp ne ptr %vtable, @__typeid_typeid2_8_3_unique_member
80 ; UNIQUE-RET-VAL1: icmp eq ptr %vtable, @__typeid_typeid2_8_3_unique_member
81 ; VCP-X86: [[GEP2:%.*]] = getelementptr i8, ptr %vtable, i32 ptrtoint (ptr @__typeid_typeid2_8_3_byte to i32)
82 ; VCP-ARM: [[GEP2:%.*]] = getelementptr i8, ptr %vtable, i32 43
83 ; VCP: [[LOAD2:%.*]] = load i8, ptr [[GEP2]]
84 ; VCP-X86: [[AND2:%.*]] = and i8 [[LOAD2]], ptrtoint (ptr @__typeid_typeid2_8_3_bit to i8)
85 ; VCP-ARM: [[AND2:%.*]] = and i8 [[LOAD2]], -128
86 ; VCP: [[ICMP2:%.*]] = icmp ne i8 [[AND2]], 0
87 ; VCP: ret i1 [[ICMP2]]
88 ; BRANCH-FUNNEL-NOVCP: call i1 @__typeid_typeid2_8_branch_funnel(ptr nest %vtable, ptr %obj, i32 3)
92 call void @llvm.trap()
96 ; SINGLE-IMPL-DAG: declare void @singleimpl1()
97 ; SINGLE-IMPL-DAG: declare void @singleimpl2()
99 ; VCP32: !0 = !{i32 -1, i32 -1}
100 ; VCP64: !0 = !{i64 0, i64 4294967296}
102 ; VCP32: !1 = !{i32 0, i32 256}
103 ; VCP64: !1 = !{i64 0, i64 256}
105 declare void @llvm.assume(i1)
106 declare void @llvm.trap()
107 declare {ptr, i1} @llvm.type.checked.load(ptr, i32, metadata)
108 declare i1 @llvm.type.test(ptr, metadata)
110 attributes #0 = { "target-features"="+retpoline" }