Skip to content

Commit

Permalink
[ValueTracking] Use APInt::isNegative instead of using operator[BitWi…
Browse files Browse the repository at this point in the history
…dth-1]. NFCI

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298584 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Mar 23, 2017
1 parent fe5b80b commit 31f7be5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,17 +993,17 @@ static void computeKnownBitsFromOperator(const Operator *I, APInt &KnownZero,
unsigned MaxHighZeros = 0;
if (SPF == SPF_SMAX) {
// If both sides are negative, the result is negative.
if (KnownOne[BitWidth - 1] && KnownOne2[BitWidth - 1])
if (KnownOne.isNegative() && KnownOne2.isNegative())
// We can derive a lower bound on the result by taking the max of the
// leading one bits.
MaxHighOnes =
std::max(KnownOne.countLeadingOnes(), KnownOne2.countLeadingOnes());
// If either side is non-negative, the result is non-negative.
else if (KnownZero[BitWidth - 1] || KnownZero2[BitWidth - 1])
else if (KnownZero.isNegative() || KnownZero2.isNegative())
MaxHighZeros = 1;
} else if (SPF == SPF_SMIN) {
// If both sides are non-negative, the result is non-negative.
if (KnownZero[BitWidth - 1] && KnownZero2[BitWidth - 1])
if (KnownZero.isNegative() && KnownZero2.isNegative())
// We can derive an upper bound on the result by taking the max of the
// leading zero bits.
MaxHighZeros = std::max(KnownZero.countLeadingOnes(),
Expand Down Expand Up @@ -1177,12 +1177,12 @@ static void computeKnownBitsFromOperator(const Operator *I, APInt &KnownZero,

// If the first operand is non-negative or has all low bits zero, then
// the upper bits are all zero.
if (KnownZero2[BitWidth-1] || ((KnownZero2 & LowBits) == LowBits))
if (KnownZero2.isNegative() || ((KnownZero2 & LowBits) == LowBits))
KnownZero |= ~LowBits;

// If the first operand is negative and not all low bits are zero, then
// the upper bits are all one.
if (KnownOne2[BitWidth-1] && ((KnownOne2 & LowBits) != 0))
if (KnownOne2.isNegative() && ((KnownOne2 & LowBits) != 0))
KnownOne |= ~LowBits;

assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
Expand Down Expand Up @@ -1626,8 +1626,8 @@ void ComputeSignBit(const Value *V, bool &KnownZero, bool &KnownOne,
APInt ZeroBits(BitWidth, 0);
APInt OneBits(BitWidth, 0);
computeKnownBits(V, ZeroBits, OneBits, Depth, Q);
KnownOne = OneBits[BitWidth - 1];
KnownZero = ZeroBits[BitWidth - 1];
KnownOne = OneBits.isNegative();
KnownZero = ZeroBits.isNegative();
}

/// Return true if the given value is known to have exactly one
Expand Down

0 comments on commit 31f7be5

Please sign in to comment.