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