Skip to content

Commit

Permalink
[ValueTracking] Convert computeKnownBitsFromRangeMetadata to use Know…
Browse files Browse the repository at this point in the history
…nBits struct.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301626 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Apr 28, 2017
1 parent 6faf1a3 commit 955683a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/llvm/Analysis/ValueTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ template <typename T> class ArrayRef;
/// \p KnownZero the set of bits that are known to be zero
/// \p KnownOne the set of bits that are known to be one
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
APInt &KnownZero, APInt &KnownOne);
KnownBits &Known);
/// Return true if LHS and RHS have no common bits set.
bool haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
const DataLayout &DL,
Expand Down
17 changes: 8 additions & 9 deletions lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,13 @@ static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW,
}

void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
APInt &KnownZero,
APInt &KnownOne) {
unsigned BitWidth = KnownZero.getBitWidth();
KnownBits &Known) {
unsigned BitWidth = Known.getBitWidth();
unsigned NumRanges = Ranges.getNumOperands() / 2;
assert(NumRanges >= 1);

KnownZero.setAllBits();
KnownOne.setAllBits();
Known.Zero.setAllBits();
Known.One.setAllBits();

for (unsigned i = 0; i < NumRanges; ++i) {
ConstantInt *Lower =
Expand All @@ -388,8 +387,8 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
(Range.getUnsignedMax() ^ Range.getUnsignedMin()).countLeadingZeros();

APInt Mask = APInt::getHighBitsSet(BitWidth, CommonPrefixBits);
KnownOne &= Range.getUnsignedMax() & Mask;
KnownZero &= ~Range.getUnsignedMax() & Mask;
Known.One &= Range.getUnsignedMax() & Mask;
Known.Zero &= ~Range.getUnsignedMax() & Mask;
}
}

Expand Down Expand Up @@ -902,7 +901,7 @@ static void computeKnownBitsFromOperator(const Operator *I, KnownBits &Known,
default: break;
case Instruction::Load:
if (MDNode *MD = cast<LoadInst>(I)->getMetadata(LLVMContext::MD_range))
computeKnownBitsFromRangeMetadata(*MD, Known.Zero, Known.One);
computeKnownBitsFromRangeMetadata(*MD, Known);
break;
case Instruction::And: {
// If either the LHS or the RHS are Zero, the result is zero.
Expand Down Expand Up @@ -1384,7 +1383,7 @@ static void computeKnownBitsFromOperator(const Operator *I, KnownBits &Known,
// and then intersect with known bits based on other properties of the
// function.
if (MDNode *MD = cast<Instruction>(I)->getMetadata(LLVMContext::MD_range))
computeKnownBitsFromRangeMetadata(*MD, Known.Zero, Known.One);
computeKnownBitsFromRangeMetadata(*MD, Known);
if (const Value *RV = ImmutableCallSite(I).getReturnedArgOperand()) {
computeKnownBits(RV, Known2, Depth + 1, Q);
Known.Zero |= Known2.Zero;
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, KnownBits &Known,
Known.Zero.setBitsFrom(MemBits);
} else if (const MDNode *Ranges = LD->getRanges()) {
if (LD->getExtensionType() == ISD::NON_EXTLOAD)
computeKnownBitsFromRangeMetadata(*Ranges, Known.Zero, Known.One);
computeKnownBitsFromRangeMetadata(*Ranges, Known);
}
break;
}
Expand Down

0 comments on commit 955683a

Please sign in to comment.