diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 880781742fae0..f6ae9ed99fb3b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -429,6 +429,10 @@ void llvm::computeKnownBitsFromRangeMetadata(const MDNode &Ranges, ConstantInt *Upper = mdconst::extract(Ranges.getOperand(2 * i + 1)); ConstantRange Range(Lower->getValue(), Upper->getValue()); + // BitWidth must equal the Ranges BitWidth for the correct number of high + // bits to be set. + assert(BitWidth == Range.getBitWidth() && + "Known bit width must match range bit width!"); // The first CommonPrefixBits of all values in Range are equal. unsigned CommonPrefixBits = diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 7ce4eebf685e1..07a5788c8e845 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -9176,6 +9176,12 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, "Cannot use an ext load to change the number of vector elements!"); } + assert((!MMO->getRanges() || + (mdconst::extract(MMO->getRanges()->getOperand(0)) + ->getBitWidth() == MemVT.getScalarSizeInBits() && + MemVT.isInteger())) && + "Range metadata and load type must match!"); + bool Indexed = AM != ISD::UNINDEXED; assert((Indexed || Offset.isUndef()) && "Unindexed load with an offset!");