[PATCH] D41305: Properly handle byval arguments in getPointerDereferenceableBytes()
Björn Steinbrink via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 12:07:31 PST 2017
dotdash created this revision.
dotdash added reviewers: hfinkel, rnk.
For byval arguments, the number of dereferenceable bytes is equal to
the size of the pointee, not the pointer.
https://reviews.llvm.org/D41305
Files:
lib/IR/Value.cpp
test/Analysis/ValueTracking/memory-dereferenceable.ll
Index: test/Analysis/ValueTracking/memory-dereferenceable.ll
===================================================================
--- test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -22,7 +22,9 @@
; CHECK-LABEL: 'test'
define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
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" {
; CHECK: The following are dereferenceable:
entry:
@@ -94,6 +96,18 @@
%load15 = load i8, i8 addrspace(1)* %dparam.align1, 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
; CHECK: %alloca.align1{{.*}}(unaligned)
; CHECK: %alloca.align16{{.*}}(aligned)
Index: lib/IR/Value.cpp
===================================================================
--- lib/IR/Value.cpp
+++ lib/IR/Value.cpp
@@ -627,9 +627,12 @@
CanBeNull = false;
if (const Argument *A = dyn_cast<Argument>(this)) {
DerefBytes = A->getDereferenceableBytes();
- if (DerefBytes == 0 && A->hasByValAttr() && A->getType()->isSized()) {
- DerefBytes = DL.getTypeStoreSize(A->getType());
- CanBeNull = false;
+ if (DerefBytes == 0 && A->hasByValAttr()) {
+ Type *PT = cast<PointerType>(A->getType())->getElementType();
+ if (PT->isSized()) {
+ DerefBytes = DL.getTypeStoreSize(PT);
+ CanBeNull = false;
+ }
}
if (DerefBytes == 0) {
DerefBytes = A->getDereferenceableOrNullBytes();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41305.127174.patch
Type: text/x-patch
Size: 2197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/1c1c5f24/attachment.bin>
More information about the llvm-commits
mailing list