mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 21:00:29 +00:00
PR17925 bugfix.
Short description. This issue is about case of treating pointers as integers. We treat pointers as different if they references different address space. At the same time, we treat pointers equal to integers (with machine address width). It was a point of false-positive. Consider next case on 32bit machine: void foo0(i32 addrespace(1)* %p) void foo1(i32 addrespace(2)* %p) void foo2(i32 %p) foo0 != foo1, while foo1 == foo2 and foo0 == foo2. As you can see it breaks transitivity. That means that result depends on order of how functions are presented in module. Next order causes merging of foo0 and foo1: foo2, foo0, foo1 First foo0 will be merged with foo2, foo0 will be erased. Second foo1 will be merged with foo2. Depending on order, things could be merged we don't expect to. The fix: Forbid to treat any pointer as integer, except for those, who belong to address space 0. llvm-svn: 195769
This commit is contained in:
parent
a7f0ef25ed
commit
83455f2b60
@ -210,19 +210,20 @@ private:
|
||||
// Any two pointers in the same address space are equivalent, intptr_t and
|
||||
// pointers are equivalent. Otherwise, standard type equivalence rules apply.
|
||||
bool FunctionComparator::isEquivalentType(Type *Ty1, Type *Ty2) const {
|
||||
|
||||
PointerType *PTy1 = dyn_cast<PointerType>(Ty1);
|
||||
PointerType *PTy2 = dyn_cast<PointerType>(Ty2);
|
||||
|
||||
if (TD) {
|
||||
if (PTy1 && PTy1->getAddressSpace() == 0) Ty1 = TD->getIntPtrType(Ty1);
|
||||
if (PTy2 && PTy2->getAddressSpace() == 0) Ty2 = TD->getIntPtrType(Ty2);
|
||||
}
|
||||
|
||||
if (Ty1 == Ty2)
|
||||
return true;
|
||||
if (Ty1->getTypeID() != Ty2->getTypeID()) {
|
||||
if (TD) {
|
||||
|
||||
if (isa<PointerType>(Ty1) && Ty2 == TD->getIntPtrType(Ty1))
|
||||
return true;
|
||||
|
||||
if (isa<PointerType>(Ty2) && Ty1 == TD->getIntPtrType(Ty2))
|
||||
return true;
|
||||
}
|
||||
if (Ty1->getTypeID() != Ty2->getTypeID())
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (Ty1->getTypeID()) {
|
||||
default:
|
||||
@ -244,8 +245,7 @@ bool FunctionComparator::isEquivalentType(Type *Ty1, Type *Ty2) const {
|
||||
return true;
|
||||
|
||||
case Type::PointerTyID: {
|
||||
PointerType *PTy1 = cast<PointerType>(Ty1);
|
||||
PointerType *PTy2 = cast<PointerType>(Ty2);
|
||||
assert(PTy1 && PTy2 && "Both types must be pointers here.");
|
||||
return PTy1->getAddressSpace() == PTy2->getAddressSpace();
|
||||
}
|
||||
|
||||
|
@ -1,29 +0,0 @@
|
||||
; RUN: opt -mergefunc -S < %s | FileCheck %s
|
||||
target datalayout = "e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-n8:16:32-S128"
|
||||
|
||||
%.qux.2496 = type { i16, %.qux.2497 }
|
||||
%.qux.2497 = type { i8, i16 }
|
||||
%.qux.2585 = type { i16, i16, i8 addrspace(1)* }
|
||||
|
||||
@g2 = external addrspace(1) constant [9 x i8], align 1
|
||||
@g3 = internal hidden addrspace(1) constant [1 x i8*] [i8* bitcast (i8 addrspace(1)* (%.qux.2585 addrspace(1)*)* @func35 to i8*)]
|
||||
|
||||
|
||||
define internal hidden i16 @func10(%.qux.2496 addrspace(1)* nocapture %this) align 2 {
|
||||
bb:
|
||||
%tmp = getelementptr inbounds %.qux.2496 addrspace(1)* %this, i32 0, i32 1, i32 1
|
||||
%tmp1 = load i16 addrspace(1)* %tmp, align 4
|
||||
ret i16 %tmp1
|
||||
}
|
||||
|
||||
; Checks that this can be merged with an address space differently sized than 0
|
||||
define internal hidden i8 addrspace(1)* @func35(%.qux.2585 addrspace(1)* nocapture %this) align 2 {
|
||||
bb:
|
||||
; CHECK-LABEL: @func35(
|
||||
; CHECK: %[[V2:.+]] = bitcast %.qux.2585 addrspace(1)* %{{.*}} to %.qux.2496 addrspace(1)*
|
||||
; CHECK: %[[V3:.+]] = tail call i16 @func10(%.qux.2496 addrspace(1)* %[[V2]])
|
||||
; CHECK: %{{.*}} = inttoptr i16 %[[V3]] to i8 addrspace(1)*
|
||||
%tmp = getelementptr inbounds %.qux.2585 addrspace(1)* %this, i32 0, i32 2
|
||||
%tmp1 = load i8 addrspace(1)* addrspace(1)* %tmp, align 4
|
||||
ret i8 addrspace(1)* %tmp1
|
||||
}
|
21
test/Transforms/MergeFunc/ptr-int-transitivity-1.ll
Normal file
21
test/Transforms/MergeFunc/ptr-int-transitivity-1.ll
Normal file
@ -0,0 +1,21 @@
|
||||
; RUN: opt -S -mergefunc < %s | not grep "functions merged"
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
|
||||
declare void @stuff()
|
||||
|
||||
define void @f0(i64 %p0) {
|
||||
entry:
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @f2(i64 addrspace(1)* %p0) {
|
||||
entry:
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
ret void
|
||||
}
|
||||
|
25
test/Transforms/MergeFunc/ptr-int-transitivity-2.ll
Normal file
25
test/Transforms/MergeFunc/ptr-int-transitivity-2.ll
Normal file
@ -0,0 +1,25 @@
|
||||
; RUN: opt -S -mergefunc < %s | FileCheck %s
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
|
||||
declare void @stuff()
|
||||
|
||||
define void @f0(i64 %p0) {
|
||||
entry:
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
ret void
|
||||
}
|
||||
|
||||
; CHECK-LABEL: @f0
|
||||
; CHECK: %2 = ptrtoint i64* %0 to i64
|
||||
; CHECK: tail call void @f0(i64 %2)
|
||||
; CHECK: ret void
|
||||
define void @f1(i64 addrspace(0)* %p0) {
|
||||
entry:
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
ret void
|
||||
}
|
||||
|
21
test/Transforms/MergeFunc/ptr-int-transitivity-3.ll
Normal file
21
test/Transforms/MergeFunc/ptr-int-transitivity-3.ll
Normal file
@ -0,0 +1,21 @@
|
||||
; RUN: opt -S -mergefunc < %s | not grep "functions merged"
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
|
||||
declare void @stuff()
|
||||
|
||||
define void @f0(i64 addrspace(0)* %p0) {
|
||||
entry:
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @f2(i64 addrspace(1)* %p0) {
|
||||
entry:
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
call void @stuff()
|
||||
ret void
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user