llvm.org GIT mirror llvm / b2ce483
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320939 91177308-0d34-0410-b5e6-96231b3b80d8 Bjorn Steinbrink 2 years ago
2 changed file(s) with 18 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
626626 CanBeNull = false;
627627 if (const Argument *A = dyn_cast(this)) {
628628 DerefBytes = A->getDereferenceableBytes();
629 if (DerefBytes == 0 && A->hasByValAttr() && A->getType()->isSized()) {
630 DerefBytes = DL.getTypeStoreSize(A->getType());
631 CanBeNull = false;
629 if (DerefBytes == 0 && A->hasByValAttr()) {
630 Type *PT = cast(A->getType())->getElementType();
631 DerefBytes = DL.getTypeStoreSize(PT);
632632 }
633633 if (DerefBytes == 0) {
634634 DerefBytes = A->getDereferenceableOrNullBytes();
2121 ; CHECK-LABEL: 'test'
2222 define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
2323 i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1,
24 i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16)
24 i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16,
25 i8* byval %i8_byval,
26 %struct.A* byval %A_byval)
2527 gc "statepoint-example" {
2628 ; CHECK: The following are dereferenceable:
2729 entry:
109111 ; CHECK: %dparam.align16{{.*}}(aligned)
110112 %load15 = load i8, i8 addrspace(1)* %dparam.align1, align 16
111113 %load16 = load i8, i8 addrspace(1)* %dparam.align16, align 16
114
115 ; Loads from byval arguments
116 ; CHECK: %i8_byval{{.*}}(aligned)
117 %i8_byval_load = load i8, i8* %i8_byval
118
119 ; CHECK-NOT: %byval_cast
120 %byval_cast = bitcast i8* %i8_byval to i32*
121 %bad_byval_load = load i32, i32* %byval_cast
122
123 ; CHECK: %byval_gep{{.*}}(aligned)
124 %byval_gep = getelementptr inbounds %struct.A, %struct.A* %A_byval, i64 0, i32 1, i64 2
125 load i8, i8* %byval_gep
112126
113127 ; Loads from aligned allocas
114128 ; CHECK: %alloca.align1{{.*}}(unaligned)