[llvm] [ValueTracking] Use `ConstantRange::toKnownBits` when computing from Range Metadata; NFC (PR #85574)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 17 10:25:26 PDT 2024
================
@@ -419,27 +419,16 @@ static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW,
void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges,
KnownBits &Known) {
- unsigned BitWidth = Known.getBitWidth();
unsigned NumRanges = Ranges.getNumOperands() / 2;
assert(NumRanges >= 1);
- Known.Zero.setAllBits();
- Known.One.setAllBits();
-
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;
+ Known = Known.unionWith(Range.toKnownBits());
----------------
goldsteinn wrote:
I think the precise logic would be an intersecting CR over all the ranges then union KnownBits with that final CR.
Ill update.
https://github.com/llvm/llvm-project/pull/85574
More information about the llvm-commits
mailing list