Skip to content

Commit

Permalink
[InstCombine] computeKnownBitsMul - use KnownBits::isNonZero() helper.
Browse files Browse the repository at this point in the history
Avoid an expensive isKnownNonZero() call - this is a small cleanup before moving the extra NSW functionality from computeKnownBitsMul into KnownBits::computeForMul.
  • Loading branch information
RKSimon committed Nov 6, 2020
1 parent b215adf commit 20f87d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions llvm/include/llvm/Support/KnownBits.h
Expand Up @@ -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(); }

Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Analysis/ValueTracking.cpp
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 20f87d8

Please sign in to comment.