Skip to content

Commit de7a7aa

Browse files
committed
[NFC][ValueTracking]: Remove redundant computeKnownBits call for LoadInst 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
1 parent 5b95bba commit de7a7aa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,14 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
26792679
return isKnownNonZero(I->getOperand(0), Depth, Q) &&
26802680
isGuaranteedNotToBePoison(I->getOperand(0), Q.AC, Q.CxtI, Q.DT,
26812681
Depth);
2682+
case Instruction::Load:
2683+
// A Load tagged with nonnull metadata is never null.
2684+
if (Q.IIQ.getMetadata(cast<LoadInst>(I), LLVMContext::MD_nonnull))
2685+
return true;
2686+
2687+
// No need to fall through to computeKnownBits as range metadata is already
2688+
// handled in isKnownNonZero.
2689+
return false;
26822690
case Instruction::Call:
26832691
if (auto *II = dyn_cast<IntrinsicInst>(I)) {
26842692
switch (II->getIntrinsicID()) {
@@ -2843,11 +2851,6 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
28432851
return true;
28442852
}
28452853

2846-
// A Load tagged with nonnull metadata is never null.
2847-
if (const LoadInst *LI = dyn_cast<LoadInst>(V))
2848-
if (Q.IIQ.getMetadata(LI, LLVMContext::MD_nonnull))
2849-
return true;
2850-
28512854
if (const auto *Call = dyn_cast<CallBase>(V)) {
28522855
if (Call->isReturnNonNull())
28532856
return true;

0 commit comments

Comments
 (0)