[PATCH] D41355: Treat sret arguments as being dereferenceable in getPointerDereferenceableBytes()
Björn Steinbrink via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 18 08:24:23 PST 2017
dotdash created this revision.
dotdash added reviewers: rnk, hfinkel, efriedma.
https://reviews.llvm.org/D41355
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
@@ -20,7 +20,8 @@
@globalptr.align16 = external global i8, align 16
; CHECK-LABEL: 'test'
-define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
+define void @test(%struct.A* sret %result,
+ 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* byval %i8_byval,
@@ -53,6 +54,15 @@
%baa_cast = bitcast i8* %big_array_alloca to i32*
%baa_load = load i32, i32* %baa_cast
+ ; Loads from sret arguments
+; CHECK: %sret_gep{{.*}}(aligned)
+ %sret_gep = getelementptr inbounds %struct.A, %struct.A* %result, i64 0, i32 1, i64 2
+ load i8, i8* %sret_gep
+
+; CHECK-NOT: %sret_gep_outside
+ %sret_gep_outside = getelementptr %struct.A, %struct.A* %result, i64 0, i32 1, i64 7
+ load i8, i8* %sret_gep_outside
+
; CHECK: %dparam{{.*}}(aligned)
%load3 = load i32, i32 addrspace(1)* %dparam
Index: lib/IR/Value.cpp
===================================================================
--- lib/IR/Value.cpp
+++ lib/IR/Value.cpp
@@ -627,9 +627,10 @@
CanBeNull = false;
if (const Argument *A = dyn_cast<Argument>(this)) {
DerefBytes = A->getDereferenceableBytes();
- if (DerefBytes == 0 && A->hasByValAttr()) {
+ if (DerefBytes == 0 && (A->hasByValAttr() || A->hasStructRetAttr())) {
Type *PT = cast<PointerType>(A->getType())->getElementType();
- DerefBytes = DL.getTypeStoreSize(PT);
+ if (PT->isSized())
+ DerefBytes = DL.getTypeStoreSize(PT);
}
if (DerefBytes == 0) {
DerefBytes = A->getDereferenceableOrNullBytes();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41355.127368.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171218/7ca3c784/attachment-0001.bin>
More information about the llvm-commits
mailing list