diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-06-25 19:12:55 -0400 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-07-16 13:50:49 -0400 |
commit | 0347039a6e7daa774d016e0a4e0f2568c7913351 (patch) | |
tree | f041a25b867d6c636e4a02b94c4ad75a8e788ba6 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | b16dfbead21a458799a0dab96599eb15f5d9b7ea (diff) | |
download | llvm-0347039a6e7daa774d016e0a4e0f2568c7913351.zip llvm-0347039a6e7daa774d016e0a4e0f2568c7913351.tar.gz llvm-0347039a6e7daa774d016e0a4e0f2568c7913351.tar.bz2 |
ValueTracking: Fix isKnownNonZero for non-0 null pointers for byval
The IR doesn't have a proper concept of invalid pointers, and "null"
constants are just all zeros (though it really needs one).
I think it's not possible to break this for AMDGPU due to the copy
semantics of byval. If you have an original stack object at 0, the
byval copy will be placed above it so I don't think it's really
possible to hit a 0 address.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 43caaa6..306f6a4 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2353,15 +2353,20 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth, return false; // Check for pointer simplifications. - if (V->getType()->isPointerTy()) { + + if (PointerType *PtrTy = dyn_cast<PointerType>(V->getType())) { // Alloca never returns null, malloc might. if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0) return true; - // A byval, inalloca, or nonnull argument is never null. - if (const Argument *A = dyn_cast<Argument>(V)) - if (A->hasPassPointeeByValueAttr() || A->hasNonNullAttr()) + // A byval, inalloca may not be null in a non-default addres space. A + // nonnull argument is assumed never 0. + if (const Argument *A = dyn_cast<Argument>(V)) { + if (((A->hasPassPointeeByValueAttr() && + !NullPointerIsDefined(A->getParent(), PtrTy->getAddressSpace())) || + A->hasNonNullAttr())) return true; + } // A Load tagged with nonnull metadata is never null. if (const LoadInst *LI = dyn_cast<LoadInst>(V)) |