1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

Properly handle byval arguments in getPointerDereferenceableBytes()

Summary:
For byval arguments, the number of dereferenceable bytes is equal to
the size of the pointee, not the pointer.

Reviewers: hfinkel, rnk

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D41305

llvm-svn: 320939
This commit is contained in:
Bjorn Steinbrink 2017-12-17 02:37:42 +00:00
parent a3689b6e50
commit e650a02573
2 changed files with 18 additions and 4 deletions

View File

@ -627,9 +627,9 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
CanBeNull = false; CanBeNull = false;
if (const Argument *A = dyn_cast<Argument>(this)) { if (const Argument *A = dyn_cast<Argument>(this)) {
DerefBytes = A->getDereferenceableBytes(); DerefBytes = A->getDereferenceableBytes();
if (DerefBytes == 0 && A->hasByValAttr() && A->getType()->isSized()) { if (DerefBytes == 0 && A->hasByValAttr()) {
DerefBytes = DL.getTypeStoreSize(A->getType()); Type *PT = cast<PointerType>(A->getType())->getElementType();
CanBeNull = false; DerefBytes = DL.getTypeStoreSize(PT);
} }
if (DerefBytes == 0) { if (DerefBytes == 0) {
DerefBytes = A->getDereferenceableOrNullBytes(); DerefBytes = A->getDereferenceableOrNullBytes();

View File

@ -22,7 +22,9 @@ declare i32* @foo()
; CHECK-LABEL: 'test' ; CHECK-LABEL: 'test'
define void @test(i32 addrspace(1)* dereferenceable(8) %dparam, define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1, i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1,
i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16) i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16,
i8* byval %i8_byval,
%struct.A* byval %A_byval)
gc "statepoint-example" { gc "statepoint-example" {
; CHECK: The following are dereferenceable: ; CHECK: The following are dereferenceable:
entry: entry:
@ -111,6 +113,18 @@ entry:
%load15 = load i8, i8 addrspace(1)* %dparam.align1, align 16 %load15 = load i8, i8 addrspace(1)* %dparam.align1, align 16
%load16 = load i8, i8 addrspace(1)* %dparam.align16, align 16 %load16 = load i8, i8 addrspace(1)* %dparam.align16, align 16
; Loads from byval arguments
; CHECK: %i8_byval{{.*}}(aligned)
%i8_byval_load = load i8, i8* %i8_byval
; CHECK-NOT: %byval_cast
%byval_cast = bitcast i8* %i8_byval to i32*
%bad_byval_load = load i32, i32* %byval_cast
; CHECK: %byval_gep{{.*}}(aligned)
%byval_gep = getelementptr inbounds %struct.A, %struct.A* %A_byval, i64 0, i32 1, i64 2
load i8, i8* %byval_gep
; Loads from aligned allocas ; Loads from aligned allocas
; CHECK: %alloca.align1{{.*}}(unaligned) ; CHECK: %alloca.align1{{.*}}(unaligned)
; CHECK: %alloca.align16{{.*}}(aligned) ; CHECK: %alloca.align16{{.*}}(aligned)