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