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 -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-single-impl.yaml < %s | FileCheck --check-prefixes=CHECK,SINGLE-IMPL %s 3; RUN: opt -S -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 4; RUN: opt -S -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 5; RUN: opt -S -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 6; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp.yaml < %s | FileCheck --check-prefixes=CHECK,VCP,VCP-X86,VCP64,INDIR %s 7; 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,VCP-X86,VCP32 %s 8; RUN: opt -S -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 9; RUN: opt -S -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 10; RUN: opt -S -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 12target datalayout = "e-p:64:64" 13target triple = "x86_64-unknown-linux-gnu" 14 15; VCP-X86: @__typeid_typeid1_0_1_byte = external hidden global [0 x i8], !absolute_symbol !0 16; VCP-X86: @__typeid_typeid1_0_1_bit = external hidden global [0 x i8], !absolute_symbol !1 17; VCP-X86: @__typeid_typeid2_8_3_byte = external hidden global [0 x i8], !absolute_symbol !0 18; VCP-X86: @__typeid_typeid2_8_3_bit = external hidden global [0 x i8], !absolute_symbol !1 19 20; Test cases where the argument values are known and we can apply virtual 21; constant propagation. 22 23; CHECK: define i32 @call1 24define i32 @call1(i8* %obj) #0 { 25 %vtableptr = bitcast i8* %obj to [3 x i8*]** 26 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 27 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 28 %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1") 29 call void @llvm.assume(i1 %p) 30 %fptrptr = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0 31 %fptr = load i8*, i8** %fptrptr 32 %fptr_casted = bitcast i8* %fptr to i32 (i8*, i32)* 33 ; CHECK: {{.*}} = bitcast {{.*}} to i8* 34 ; VCP: [[VT1:%.*]] = bitcast {{.*}} to i8* 35 ; SINGLE-IMPL: call i32 bitcast (void ()* @singleimpl1 to i32 (i8*, i32)*) 36 %result = call i32 %fptr_casted(i8* %obj, i32 1) 37 ; UNIFORM-RET-VAL: ret i32 42 38 ; VCP-X86: [[GEP1:%.*]] = getelementptr i8, i8* [[VT1]], i32 ptrtoint ([0 x i8]* @__typeid_typeid1_0_1_byte to i32) 39 ; VCP-ARM: [[GEP1:%.*]] = getelementptr i8, i8* [[VT1]], i32 42 40 ; VCP: [[BC1:%.*]] = bitcast i8* [[GEP1]] to i32* 41 ; VCP: [[LOAD1:%.*]] = load i32, i32* [[BC1]] 42 ; VCP: ret i32 [[LOAD1]] 43 ; BRANCH-FUNNEL-NOVCP: [[VT1:%.*]] = bitcast {{.*}} to i8* 44 ; BRANCH-FUNNEL-NOVCP: call i32 bitcast (void ()* @__typeid_typeid1_0_branch_funnel to i32 (i8*, i8*, i32)*)(i8* nest [[VT1]], i8* %obj, i32 1) 45 ret i32 %result 46} 47 48; Test cases where the argument values are unknown, so we cannot apply virtual 49; constant propagation. 50 51; CHECK: define i1 @call2 52define i1 @call2(i8* %obj) #0 { 53 ; BRANCH-FUNNEL: [[VT1:%.*]] = bitcast {{.*}} to i8* 54 %vtableptr = bitcast i8* %obj to [1 x i8*]** 55 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr 56 %vtablei8 = bitcast [1 x i8*]* %vtable to i8* 57 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2") 58 %fptr = extractvalue {i8*, i1} %pair, 0 59 %p = extractvalue {i8*, i1} %pair, 1 60 ; SINGLE-IMPL: br i1 true, 61 br i1 %p, label %cont, label %trap 62 63cont: 64 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)* 65 ; SINGLE-IMPL: call i1 bitcast (void ()* @singleimpl2 to i1 (i8*, i32)*) 66 ; INDIR: call i1 % 67 ; BRANCH-FUNNEL: call i1 bitcast (void ()* @__typeid_typeid2_8_branch_funnel to i1 (i8*, i8*, i32)*)(i8* nest [[VT1]], i8* %obj, i32 undef) 68 %result = call i1 %fptr_casted(i8* %obj, i32 undef) 69 ret i1 %result 70 71trap: 72 call void @llvm.trap() 73 unreachable 74} 75 76; CHECK: define i1 @call3 77define i1 @call3(i8* %obj) #0 { 78 %vtableptr = bitcast i8* %obj to [1 x i8*]** 79 %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr 80 %vtablei8 = bitcast [1 x i8*]* %vtable to i8* 81 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid2") 82 %fptr = extractvalue {i8*, i1} %pair, 0 83 %p = extractvalue {i8*, i1} %pair, 1 84 br i1 %p, label %cont, label %trap 85 86cont: 87 %fptr_casted = bitcast i8* %fptr to i1 (i8*, i32)* 88 %result = call i1 %fptr_casted(i8* %obj, i32 3) 89 ; UNIQUE-RET-VAL0: icmp ne i8* %vtablei8, getelementptr inbounds ([0 x i8], [0 x i8]* @__typeid_typeid2_8_3_unique_member, i32 0, i32 0) 90 ; UNIQUE-RET-VAL1: icmp eq i8* %vtablei8, getelementptr inbounds ([0 x i8], [0 x i8]* @__typeid_typeid2_8_3_unique_member, i32 0, i32 0) 91 ; VCP: [[VT2:%.*]] = bitcast {{.*}} to i8* 92 ; VCP-X86: [[GEP2:%.*]] = getelementptr i8, i8* [[VT2]], i32 ptrtoint ([0 x i8]* @__typeid_typeid2_8_3_byte to i32) 93 ; VCP-ARM: [[GEP2:%.*]] = getelementptr i8, i8* [[VT2]], i32 43 94 ; VCP: [[LOAD2:%.*]] = load i8, i8* [[GEP2]] 95 ; VCP-X86: [[AND2:%.*]] = and i8 [[LOAD2]], ptrtoint ([0 x i8]* @__typeid_typeid2_8_3_bit to i8) 96 ; VCP-ARM: [[AND2:%.*]] = and i8 [[LOAD2]], -128 97 ; VCP: [[ICMP2:%.*]] = icmp ne i8 [[AND2]], 0 98 ; VCP: ret i1 [[ICMP2]] 99 ; BRANCH-FUNNEL-NOVCP: [[VT2:%.*]] = bitcast {{.*}} to i8* 100 ; BRANCH-FUNNEL-NOVCP: call i1 bitcast (void ()* @__typeid_typeid2_8_branch_funnel to i1 (i8*, i8*, i32)*)(i8* nest [[VT2]], i8* %obj, i32 3) 101 ret i1 %result 102 103trap: 104 call void @llvm.trap() 105 unreachable 106} 107 108; SINGLE-IMPL-DAG: declare void @singleimpl1() 109; SINGLE-IMPL-DAG: declare void @singleimpl2() 110 111; VCP32: !0 = !{i32 -1, i32 -1} 112; VCP64: !0 = !{i64 0, i64 4294967296} 113 114; VCP32: !1 = !{i32 0, i32 256} 115; VCP64: !1 = !{i64 0, i64 256} 116 117declare void @llvm.assume(i1) 118declare void @llvm.trap() 119declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata) 120declare i1 @llvm.type.test(i8*, metadata) 121 122attributes #0 = { "target-features"="+retpoline" } 123