diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2454,6 +2454,9 @@ unsigned Depth, const SimplifyQuery &Q) { unsigned BitWidth = getBitWidth(I->getType()->getScalarType(), Q.DL); switch (I->getOpcode()) { + case Instruction::Alloca: + // Alloca never returns null, malloc might. + return I->getType()->getPointerAddressSpace() == 0; case Instruction::GetElementPtr: if (I->getType()->isPointerTy()) return isGEPKnownNonNull(cast(I), Depth, Q); @@ -2688,6 +2691,15 @@ // handled in isKnownNonZero. return false; case Instruction::Call: + case Instruction::Invoke: + if (I->getType()->isPointerTy()) { + const auto *Call = cast(I); + if (Call->isReturnNonNull()) + return true; + if (const auto *RP = getArgumentAliasingToReturnedPointer(Call, true)) + return isKnownNonZero(RP, Depth, Q); + } + if (auto *II = dyn_cast(I)) { switch (II->getIntrinsicID()) { case Intrinsic::sshl_sat: @@ -2838,10 +2850,6 @@ // Check for pointer simplifications. if (PointerType *PtrTy = dyn_cast(V->getType())) { - // Alloca never returns null, malloc might. - if (isa(V) && PtrTy->getAddressSpace() == 0) - return true; - // 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(V)) { @@ -2850,13 +2858,6 @@ A->hasNonNullAttr())) return true; } - - if (const auto *Call = dyn_cast(V)) { - if (Call->isReturnNonNull()) - return true; - if (const auto *RP = getArgumentAliasingToReturnedPointer(Call, true)) - return isKnownNonZero(RP, Depth, Q); - } } if (const auto *I = dyn_cast(V))