Skip to content

Commit

Permalink
[NFC][ValueTracking]: Remove redundant computeKnownBits call for Load…
Browse files Browse the repository at this point in the history
…Inst in isKnownNonZero

For load instructions, computeKnownBits only checks the range metadata.
This check is already present in isKnownNonZero, so there is no need to
fall through to computeKnownBits.

This change gives a speed improvement of 0.12-0.18%:
https://llvm-compile-time-tracker.com/compare.php?from=3c6ed559e5274307995586c1499a2c8e4e0276a0&to=78b462d8c4ae079638b728c6446da5999c4ee9f8&stat=instructions:u

Differential Revision: https://reviews.llvm.org/D155958
  • Loading branch information
dc03 committed Jul 24, 2023
1 parent 5b95bba commit de7a7aa
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,14 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
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<LoadInst>(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<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
Expand Down Expand Up @@ -2843,11 +2851,6 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
return true;
}

// A Load tagged with nonnull metadata is never null.
if (const LoadInst *LI = dyn_cast<LoadInst>(V))
if (Q.IIQ.getMetadata(LI, LLVMContext::MD_nonnull))
return true;

if (const auto *Call = dyn_cast<CallBase>(V)) {
if (Call->isReturnNonNull())
return true;
Expand Down

0 comments on commit de7a7aa

Please sign in to comment.