diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-10-06 13:08:08 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-10-06 13:08:08 +0000 |
commit | c38881a6b7f9c1315c2d87654b9462195e409881 (patch) | |
tree | 70fe5a5e58ae5653e1ddd50999b640abd5e3ba02 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | 032dd9b086c77eb330453063135530cb7321ecbd (diff) | |
download | bcm5719-llvm-c38881a6b7f9c1315c2d87654b9462195e409881.tar.gz bcm5719-llvm-c38881a6b7f9c1315c2d87654b9462195e409881.zip |
[InstCombine] don't assume 'inbounds' for bitcast pointer to GEP transform (PR43501)
https://bugs.llvm.org/show_bug.cgi?id=43501
We can't declare a GEP 'inbounds' in general. But we may salvage that information if
we have known dereferenceable bytes on the source pointer.
Differential Revision: https://reviews.llvm.org/D68244
llvm-svn: 373847
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 74c69808f15..c58e63d08e3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2338,8 +2338,15 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { // If we found a path from the src to dest, create the getelementptr now. if (SrcElTy == DstElTy) { SmallVector<Value *, 8> Idxs(NumZeros + 1, Builder.getInt32(0)); - return GetElementPtrInst::CreateInBounds(SrcPTy->getElementType(), Src, - Idxs); + GetElementPtrInst *GEP = + GetElementPtrInst::Create(SrcPTy->getElementType(), Src, Idxs); + + // 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(); + return GEP; } } |