diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-10-13 17:19:08 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-10-13 17:19:08 +0000 |
commit | f90728c3227d86794819e945ab79f46a6933f95a (patch) | |
tree | 24c988be10e91b413d3f0e952c655fe8386f2e55 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | 9d80a722d7fb1ff9871677e12611af56cb96cf7a (diff) | |
download | bcm5719-llvm-f90728c3227d86794819e945ab79f46a6933f95a.tar.gz bcm5719-llvm-f90728c3227d86794819e945ab79f46a6933f95a.zip |
[InstCombine] don't assume 'inbounds' for bitcast deref or null pointer in non-default address space
Follow-up to D68244 to account for a corner case discussed in:
https://bugs.llvm.org/show_bug.cgi?id=43501
Add one more restriction: if the pointer is deref-or-null and in a non-default
(non-zero) address space, we can't assume inbounds.
Differential Revision: https://reviews.llvm.org/D68706
llvm-svn: 374728
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index c58e63d08e3..65aaef28d87 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2344,8 +2344,16 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { // 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). + // The reason is that 'null' is not treated differently in these address + // spaces, and we consequently ignore the 'gep inbounds' special case + // for 'null' which allows 'inbounds' on 'null' if the indices are + // zeros. + if (SrcPTy->getAddressSpace() == 0 || !CanBeNull) + GEP->setIsInBounds(); + } return GEP; } } |