Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp =================================================================== --- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp +++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp @@ -876,8 +876,9 @@ Constant *UniqueMemberAddr) { for (auto &&Call : CSInfo.CallSites) { IRBuilder<> B(Call.CS.getInstruction()); - Value *Cmp = B.CreateICmp(IsOne ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE, - Call.VTable, UniqueMemberAddr); + Value *Cmp = + B.CreateICmp(IsOne ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_NE, + B.CreateBitCast(Call.VTable, Int8PtrTy), UniqueMemberAddr); Cmp = B.CreateZExt(Cmp, Call.CS->getType()); Call.replaceAndErase("unique-ret-val", FnName, RemarksEnabled, OREGetter, Cmp); @@ -943,7 +944,8 @@ for (auto Call : CSInfo.CallSites) { auto *RetType = cast(Call.CS.getType()); IRBuilder<> B(Call.CS.getInstruction()); - Value *Addr = B.CreateGEP(Int8Ty, Call.VTable, Byte); + Value *Addr = + B.CreateGEP(Int8Ty, B.CreateBitCast(Call.VTable, Int8PtrTy), Byte); if (RetType->getBitWidth() == 1) { Value *Bits = B.CreateLoad(Addr); Value *BitsAndBit = B.CreateAnd(Bits, Bit); @@ -1147,8 +1149,7 @@ Value *Ptr = CI->getArgOperand(0)->stripPointerCasts(); if (SeenPtrs.insert(Ptr).second) { for (DevirtCallSite Call : DevirtCalls) { - CallSlots[{TypeId, Call.Offset}].addCallSite(CI->getArgOperand(0), - Call.CS, nullptr); + CallSlots[{TypeId, Call.Offset}].addCallSite(Ptr, Call.CS, nullptr); } } } Index: llvm/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll @@ -0,0 +1,37 @@ +; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import -wholeprogramdevirt-read-summary=%S/Inputs/import-vcp.yaml < %s | FileCheck %s + +target datalayout = "e-p:64:64" +target triple = "x86_64-unknown-linux-gnu" + +define i32 @call1(i1 %a, i8* %obj) { + %vtableptr = bitcast i8* %obj to [3 x i8*]** + %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + br i1 %a, label %bb1, label %bb2 + +bb1: + ; CHECK: {{.*}} = bitcast {{.*}} to i8* + %vtablei8_1 = bitcast [3 x i8*]* %vtable to i8* + %p1 = call i1 @llvm.type.test(i8* %vtablei8_1, metadata !"typeid1") + call void @llvm.assume(i1 %p1) + %fptrptr1 = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0 + %fptr1 = load i8*, i8** %fptrptr1 + %fptr1_casted = bitcast i8* %fptr1 to i32 (i8*, i32)* + ; CHECK: {{.*}} = bitcast {{.*}} to i8* + %result1 = call i32 %fptr1_casted(i8* %obj, i32 1) + br label %bb2 + + ; CHECK: : +bb2: + %vtablei8_2 = bitcast [3 x i8*]* %vtable to i8* + %p = call i1 @llvm.type.test(i8* %vtablei8_2, metadata !"typeid1") + call void @llvm.assume(i1 %p) + %fptrptr2 = getelementptr [3 x i8*], [3 x i8*]* %vtable, i32 0, i32 0 + %fptr2 = load i8*, i8** %fptrptr2 + %fptr2_casted = bitcast i8* %fptr2 to i32 (i8*, i32)* + ; CHECK: {{.*}} = bitcast {{.*}} to i8* + %result2 = call i32 %fptr2_casted(i8* %obj, i32 1) + ret i32 %result2 +} + +declare void @llvm.assume(i1) +declare i1 @llvm.type.test(i8*, metadata) Index: llvm/test/Transforms/WholeProgramDevirt/import.ll =================================================================== --- llvm/test/Transforms/WholeProgramDevirt/import.ll +++ llvm/test/Transforms/WholeProgramDevirt/import.ll @@ -29,6 +29,7 @@ ; SINGLE-IMPL: call i32 bitcast (void ()* @singleimpl1 to i32 (i8*, i32)*) %result = call i32 %fptr_casted(i8* %obj, i32 1) ; UNIFORM-RET-VAL: ret i32 42 + ; VCP: {{.*}} = bitcast {{.*}} to i8* ; VCP: [[VT1:%.*]] = bitcast {{.*}} to i8* ; VCP: [[GEP1:%.*]] = getelementptr i8, i8* [[VT1]], i32 ptrtoint (i8* @__typeid_typeid1_0_1_byte to i32) ; VCP: [[BC1:%.*]] = bitcast i8* [[GEP1]] to i32* Index: llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll =================================================================== --- llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll +++ llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll @@ -20,6 +20,7 @@ define i1 @call1(i8* %obj) { %vtableptr = bitcast i8* %obj to [1 x i8*]** %vtable = load [1 x i8*]*, [1 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [1 x i8*]* {{.*}} to i8* ; CHECK: [[VT1:%[^ ]*]] = bitcast [1 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [1 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid1") Index: llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll =================================================================== --- llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll +++ llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll @@ -71,6 +71,7 @@ define i1 @call1(i8* %obj) { %vtableptr = bitcast i8* %obj to [3 x i8*]** %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8* ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [3 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") @@ -91,6 +92,7 @@ define i1 @call2(i8* %obj) { %vtableptr = bitcast i8* %obj to [3 x i8*]** %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8* ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [3 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") @@ -111,6 +113,7 @@ define i32 @call3(i8* %obj) { %vtableptr = bitcast i8* %obj to [3 x i8*]** %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8* ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [3 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") Index: llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll =================================================================== --- llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll +++ llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll @@ -66,6 +66,7 @@ define i1 @call1(i8* %obj) { %vtableptr = bitcast i8* %obj to [3 x i8*]** %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8* ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [3 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") @@ -86,6 +87,7 @@ define i1 @call2(i8* %obj) { %vtableptr = bitcast i8* %obj to [3 x i8*]** %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8* ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [3 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid") @@ -106,6 +108,7 @@ define i32 @call3(i8* %obj) { %vtableptr = bitcast i8* %obj to [3 x i8*]** %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr + ; CHECK: {{.*}} = bitcast [3 x i8*]* {{.*}} to i8* ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* %vtablei8 = bitcast [3 x i8*]* %vtable to i8* %p = call i1 @llvm.type.test(i8* %vtablei8, metadata !"typeid")