[llvm] r311491 - WholeProgramDevirt: Create bitcast to i8* at each virtual call site.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 22 14:41:20 PDT 2017
Author: pcc
Date: Tue Aug 22 14:41:19 2017
New Revision: 311491
URL: http://llvm.org/viewvc/llvm-project?rev=311491&view=rev
Log:
WholeProgramDevirt: Create bitcast to i8* at each virtual call site.
We can't reuse the llvm.assume instruction's bitcast because it may not
dominate every user of the vtable pointer.
Differential Revision: https://reviews.llvm.org/D36994
Added:
llvm/trunk/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll
Modified:
llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll
llvm/trunk/test/Transforms/WholeProgramDevirt/unique-retval.ll
llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
Modified: llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp?rev=311491&r1=311490&r2=311491&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/WholeProgramDevirt.cpp Tue Aug 22 14:41:19 2017
@@ -876,8 +876,9 @@ void DevirtModule::applyUniqueRetValOpt(
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 @@ void DevirtModule::applyVirtualConstProp
for (auto Call : CSInfo.CallSites) {
auto *RetType = cast<IntegerType>(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 @@ void DevirtModule::scanTypeTestUsers(Fun
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);
}
}
}
Added: llvm/trunk/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll?rev=311491&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll (added)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/import-no-dominating-assume.ll Tue Aug 22 14:41:19 2017
@@ -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)
Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll?rev=311491&r1=311490&r2=311491&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/import.ll Tue Aug 22 14:41:19 2017
@@ -29,6 +29,7 @@ define i32 @call1(i8* %obj) {
; 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*
Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/unique-retval.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/unique-retval.ll?rev=311491&r1=311490&r2=311491&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/unique-retval.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/unique-retval.ll Tue Aug 22 14:41:19 2017
@@ -20,6 +20,7 @@ define i1 @vf1(i8* %this) readnone {
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")
Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll?rev=311491&r1=311490&r2=311491&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll Tue Aug 22 14:41:19 2017
@@ -71,6 +71,7 @@ define i32 @vf4i32(i8* %this) readnone {
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 @call1(i8* %obj) {
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 i1 @call2(i8* %obj) {
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")
Modified: llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll?rev=311491&r1=311490&r2=311491&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll (original)
+++ llvm/trunk/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll Tue Aug 22 14:41:19 2017
@@ -66,6 +66,7 @@ define i32 @vf4i32(i8* %this) readnone {
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 @call1(i8* %obj) {
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 i1 @call2(i8* %obj) {
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")
More information about the llvm-commits
mailing list