[llvm] [ValueTracking] Use `ConstantRange::toKnownBits` when computing from Range Metadata; NFC (PR #85574)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 18 07:01:03 PDT 2024
================
@@ -423,24 +423,17 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
unsigned NumRanges = Ranges.getNumOperands() / 2;
assert(NumRanges >= 1);
- Known.Zero.setAllBits();
- Known.One.setAllBits();
+ ConstantRange CR = ConstantRange::getFull(BitWidth);
for (unsigned i = 0; i < NumRanges; ++i) {
ConstantInt *Lower =
mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
ConstantInt *Upper =
mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
ConstantRange Range(Lower->getValue(), Upper->getValue());
-
- // The first CommonPrefixBits of all values in Range are equal.
- unsigned CommonPrefixBits =
- (Range.getUnsignedMax() ^ Range.getUnsignedMin()).countl_zero();
- APInt Mask = APInt::getHighBitsSet(BitWidth, CommonPrefixBits);
- APInt UnsignedMax = Range.getUnsignedMax().zextOrTrunc(BitWidth);
- Known.One &= UnsignedMax & Mask;
- Known.Zero &= ~UnsignedMax & Mask;
+ CR = CR.intersectWith(Range.zextOrTrunc(BitWidth));
----------------
nikic wrote:
This should be unionWith (see https://llvm.org/docs/LangRef.html#range-metadata). (And initialize to empty above.)
https://github.com/llvm/llvm-project/pull/85574
More information about the llvm-commits
mailing list