[llvm] de7a7aa - [NFC][ValueTracking]: Remove redundant computeKnownBits call for LoadInst in isKnownNonZero

Dhruv Chawla via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 03:00:59 PDT 2023


Author: Dhruv Chawla
Date: 2023-07-24T15:29:46+05:30
New Revision: de7a7aa1106d23df71bb535649085db552d38de5

URL: https://github.com/llvm/llvm-project/commit/de7a7aa1106d23df71bb535649085db552d38de5
DIFF: https://github.com/llvm/llvm-project/commit/de7a7aa1106d23df71bb535649085db552d38de5.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e6ba9100a252a8..5d526858e00e0c 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -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()) {
@@ -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;


        


More information about the llvm-commits mailing list