[llvm] c5aacb0 - [ValueTracking] Add fast path to avoid second recursive call in `isKnownPositive`; NFC

Noah Goldstein via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 11:28:22 PST 2024


Author: Noah Goldstein
Date: 2024-03-06T13:28:04-06:00
New Revision: c5aacb0dbcb19b154441852763785f0356e5218b

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

LOG: [ValueTracking] Add fast path to avoid second recursive call in `isKnownPositive`; NFC

Just a simple compile time improvement. This function isn't used much,
however, so its not particularly impactful.

Closes #83638

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 53c6326b8ec264..52ae9f034e5d34 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -294,9 +294,11 @@ bool llvm::isKnownPositive(const Value *V, const SimplifyQuery &SQ,
   if (auto *CI = dyn_cast<ConstantInt>(V))
     return CI->getValue().isStrictlyPositive();
 
-  // TODO: We'd doing two recursive queries here.  We should factor this such
-  // that only a single query is needed.
-  return isKnownNonNegative(V, SQ, Depth) && ::isKnownNonZero(V, Depth, SQ);
+  // If `isKnownNonNegative` ever becomes more sophisticated, make sure to keep
+  // this updated.
+  KnownBits Known = computeKnownBits(V, Depth, SQ);
+  return Known.isNonNegative() &&
+         (Known.isNonZero() || ::isKnownNonZero(V, Depth, SQ));
 }
 
 bool llvm::isKnownNegative(const Value *V, const SimplifyQuery &SQ,


        


More information about the llvm-commits mailing list