[PATCH] D68706: [InstCombine] don't assume 'inbounds' for bitcast deref or null pointer in non-default address space
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 11:26:43 PDT 2019
spatel updated this revision to Diff 224108.
spatel added a comment.
Patch updated:
No diffs in this patch itself, but rebased after adding test at rL374190 <https://reviews.llvm.org/rL374190>.
I don't have much experience with addrspaces or inbounds, so let me know if I should change anything else.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68706/new/
https://reviews.llvm.org/D68706
Files:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/load-bitcast-vec.ll
Index: llvm/test/Transforms/InstCombine/load-bitcast-vec.ll
===================================================================
--- llvm/test/Transforms/InstCombine/load-bitcast-vec.ll
+++ llvm/test/Transforms/InstCombine/load-bitcast-vec.ll
@@ -100,11 +100,11 @@
ret float %r
}
-; TODO: Is a null pointer inbounds in any address space?
+; A null pointer can't be assumed inbounds in a non-default address space.
define float @matching_scalar_smallest_deref_or_null_addrspace(<4 x float> addrspace(4)* dereferenceable_or_null(1) %p) {
; CHECK-LABEL: @matching_scalar_smallest_deref_or_null_addrspace(
-; CHECK-NEXT: [[BC:%.*]] = getelementptr inbounds <4 x float>, <4 x float> addrspace(4)* [[P:%.*]], i64 0, i64 0
+; CHECK-NEXT: [[BC:%.*]] = getelementptr <4 x float>, <4 x float> addrspace(4)* [[P:%.*]], i64 0, i64 0
; CHECK-NEXT: [[R:%.*]] = load float, float addrspace(4)* [[BC]], align 16
; CHECK-NEXT: ret float [[R]]
;
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2344,8 +2344,12 @@
// If the source pointer is dereferenceable, then assume it points to an
// allocated object and apply "inbounds" to the GEP.
bool CanBeNull;
- if (Src->getPointerDereferenceableBytes(DL, CanBeNull))
- GEP->setIsInBounds();
+ if (Src->getPointerDereferenceableBytes(DL, CanBeNull)) {
+ // In a non-default address space (not 0), a null pointer can not be
+ // assumed inbounds, so ignore that case (dereferenceable_or_null).
+ if (SrcPTy->getAddressSpace() == 0 || !CanBeNull)
+ GEP->setIsInBounds();
+ }
return GEP;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68706.224108.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191009/96497380/attachment.bin>
More information about the llvm-commits
mailing list