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 @@ -2679,6 +2679,14 @@ return isKnownNonZero(I->getOperand(0), Depth, Q) && isGuaranteedNotToBePoison(I->getOperand(0), Q.AC, Q.CxtI, Q.DT, Depth); + case Instruction::Load: + // A Load tagged with nonnull metadata is never null. + if (Q.IIQ.getMetadata(cast(I), LLVMContext::MD_nonnull)) + return true; + + // No need to fall through to computeKnownBits as range metadata is already + // handled in isKnownNonZero. + return false; case Instruction::Call: if (auto *II = dyn_cast(I)) { switch (II->getIntrinsicID()) { @@ -2843,11 +2851,6 @@ return true; } - // A Load tagged with nonnull metadata is never null. - if (const LoadInst *LI = dyn_cast(V)) - if (Q.IIQ.getMetadata(LI, LLVMContext::MD_nonnull)) - return true; - if (const auto *Call = dyn_cast(V)) { if (Call->isReturnNonNull()) return true;