[llvm] 20f87d8 - [InstCombine] computeKnownBitsMul - use KnownBits::isNonZero() helper.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 6 09:41:02 PST 2020


Author: Simon Pilgrim
Date: 2020-11-06T17:27:13Z
New Revision: 20f87d82ed31fff7f11b893d0fef5111295a6cce

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

LOG: [InstCombine] computeKnownBitsMul - use KnownBits::isNonZero() helper.

Avoid an expensive isKnownNonZero() call - this is a small cleanup before moving the extra NSW functionality from computeKnownBitsMul into KnownBits::computeForMul.

Added: 
    

Modified: 
    llvm/include/llvm/Support/KnownBits.h
    llvm/lib/Analysis/ValueTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/KnownBits.h b/llvm/include/llvm/Support/KnownBits.h
index de1c0cdf9177..40470b6e0f7b 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -97,6 +97,9 @@ struct KnownBits {
   /// Returns true if this value is known to be non-negative.
   bool isNonNegative() const { return Zero.isSignBitSet(); }
 
+  /// Returns true if this value is known to be non-zero.
+  bool isNonZero() const { return One.countPopulation() != 0; }
+
   /// Returns true if this value is known to be positive.
   bool isStrictlyPositive() const { return Zero.isSignBitSet() && !One.isNullValue(); }
 

diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 44cf4f80b59d..db591ce67709 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -436,10 +436,10 @@ static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW,
       // The product of a negative number and a non-negative number is either
       // negative or zero.
       if (!isKnownNonNegative)
-        isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
-                           isKnownNonZero(Op0, Depth, Q)) ||
-                          (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
-                           isKnownNonZero(Op1, Depth, Q));
+        isKnownNegative =
+            (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
+             Known2.isNonZero()) ||
+            (isKnownNegativeOp0 && isKnownNonNegativeOp1 && Known.isNonZero());
     }
   }
 


        


More information about the llvm-commits mailing list