25 #include "llvm/Config/llvm-config.h" 52 "ConstantRange with unequal bit widths");
54 "Lower == Upper, but they aren't min or max value!");
74 if (UMax.isMinValue())
80 if (SMax.isMinSignedValue())
86 if (UMax.isMaxValue())
92 if (SMax.isMaxSignedValue())
98 if (UMin.isMaxValue())
104 if (SMin.isMaxSignedValue())
110 if (UMin.isMinValue())
116 if (SMin.isMinSignedValue())
159 RHS = *OnlyMissingElt;
182 unsigned NoWrapKind) {
189 auto SubsetIntersect =
196 assert((NoWrapKind == OBO::NoSignedWrap ||
197 NoWrapKind == OBO::NoUnsignedWrap ||
198 NoWrapKind == (OBO::NoUnsignedWrap | OBO::NoSignedWrap)) &&
199 "NoWrapKind invalid!");
211 if (
C->isNullValue())
214 if (NoWrapKind & OBO::NoUnsignedWrap)
218 if (NoWrapKind & OBO::NoSignedWrap) {
222 Result = SubsetIntersect(
227 Result = SubsetIntersect(
234 case Instruction::Sub:
236 if (
C->isNullValue())
239 if (NoWrapKind & OBO::NoUnsignedWrap)
243 if (NoWrapKind & OBO::NoSignedWrap) {
247 Result = SubsetIntersect(
252 Result = SubsetIntersect(
258 case Instruction::Mul: {
259 if (NoWrapKind == (OBO::NoSignedWrap | OBO::NoUnsignedWrap)) {
260 return SubsetIntersect(
266 const bool Unsigned = NoWrapKind == OBO::NoUnsignedWrap;
267 const auto makeSingleValueRegion = [
Unsigned,
271 if (V == 0 || V.isOneValue())
274 APInt MinValue, MaxValue;
283 if (!Unsigned && V.isAllOnesValue())
287 if (!Unsigned && V.isNegative()) {
290 }
else if (Unsigned) {
313 return SubsetIntersect(makeSingleValueRegion(Other.
getSignedMin()),
328 return Lower.ugt(Upper);
351 return (Upper -
Lower).ult(Other.Upper - Other.Lower);
356 assert(MaxSize &&
"MaxSize can't be 0.");
362 return (Upper -
Lower).ugt(MaxSize);
394 return Lower.ule(V) && V.
ult(Upper);
395 return Lower.ule(V) || V.
ult(Upper);
430 "ConstantRange types don't agree!");
440 if (
Lower.ult(CR.Lower)) {
441 if (Upper.
ule(CR.Lower))
444 if (Upper.
ult(CR.Upper))
449 if (Upper.
ult(CR.Upper))
452 if (
Lower.ult(CR.Upper))
459 if (CR.Lower.
ult(Upper)) {
460 if (CR.Upper.
ult(Upper))
479 if (CR.Upper.
ult(Upper)) {
480 if (CR.Lower.
ult(Upper)) {
504 "ConstantRange types don't agree!");
514 APInt d1 = CR.Lower - Upper, d2 =
Lower - CR.Upper;
521 APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper;
537 if (CR.Lower.
ule(Upper) &&
Lower.ule(CR.Upper))
544 APInt d1 = CR.Lower - Upper, d2 =
Lower - CR.Upper;
552 if (Upper.
ult(CR.Lower) &&
Lower.ult(CR.Upper))
558 "ConstantRange::unionWith missed a case with one range wrapped");
564 if (CR.Lower.
ule(Upper) ||
Lower.ule(CR.Upper))
568 APInt U = CR.Upper.
ugt(Upper) ? CR.Upper : Upper;
578 case Instruction::Trunc:
580 case Instruction::SExt:
582 case Instruction::ZExt:
584 case Instruction::BitCast:
586 case Instruction::FPToUI:
587 case Instruction::FPToSI:
592 case Instruction::UIToFP: {
599 case Instruction::SIToFP: {
606 case Instruction::FPTrunc:
607 case Instruction::FPExt:
608 case Instruction::IntToPtr:
609 case Instruction::PtrToInt:
610 case Instruction::AddrSpaceCast:
620 assert(SrcTySize < DstTySize &&
"Not a value extension");
623 APInt LowerExt(DstTySize, 0);
625 LowerExt =
Lower.zext(DstTySize);
637 assert(SrcTySize < DstTySize &&
"Not a value extension");
676 if (LowerDiv == UpperDiv)
681 if (LowerDiv.getActiveBits() > DstTySize) {
689 if (UpperDivWidth <= DstTySize)
694 if (UpperDivWidth == DstTySize + 1) {
697 if (UpperDiv.
ult(LowerDiv))
707 if (SrcTySize > DstTySize)
709 if (SrcTySize < DstTySize)
716 if (SrcTySize > DstTySize)
718 if (SrcTySize < DstTySize)
730 case Instruction::Sub:
732 case Instruction::Mul:
734 case Instruction::UDiv:
736 case Instruction::Shl:
738 case Instruction::LShr:
740 case Instruction::AShr:
742 case Instruction::And:
744 case Instruction::Or:
748 case Instruction::FAdd:
750 case Instruction::FSub:
752 case Instruction::FMul:
769 if (NewLower == NewUpper)
802 if (NewLower == NewUpper)
836 this_max * Other_max + 1);
858 auto L = {this_min * Other_min, this_min * Other_max,
859 this_max * Other_min, this_max * Other_max};
1076 OS <<
"[" <<
Lower <<
"," << Upper <<
")";
1079 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 1087 assert(NumRanges >= 1 &&
"Must have at least one range!");
1090 auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.
getOperand(0));
1091 auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.
getOperand(1));
1093 ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
1095 for (
unsigned i = 1; i < NumRanges; ++i) {
1096 auto *Low = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 0));
1097 auto *
High = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 1));
1101 CR = CR.unionWith(
ConstantRange(Low->getValue(), High->getValue()));
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
APInt sext(unsigned width) const
Sign extend to a new width.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A unsign-divided by B, rounded by the given rounding mode.
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
This class represents lattice values for constants.
const APInt & getUpper() const
Return the upper value for this range.
ConstantRange addWithNoSignedWrap(const APInt &Other) const
Return a new range representing the possible values resulting from a known NSW addition of a value in...
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
APInt zext(unsigned width) const
Zero extend to a new width.
bool slt(const APInt &RHS) const
Signed less than comparison.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
bool isSizeLargerThan(uint64_t MaxSize) const
ConstantRange lshr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a logical right shift of a value i...
ConstantRange truncate(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly smaller than the current typ...
ConstantRange sub(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a subtraction of a value in this r...
APInt trunc(unsigned width) const
Truncate to new width.
void setAllBits()
Set every bit to 1.
ConstantRange ashr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a arithmetic right shift of a valu...
ConstantRange udiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned division of a value in...
const MDOperand & getOperand(unsigned I) const
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A sign-divided by B, rounded by the given rounding mode.
void print(raw_ostream &OS) const
Print out the bounds to a stream.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isWrappedSet() const
Return true if this set wraps around the top of the range.
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
ConstantRange zextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
This file implements a class to represent arbitrary precision integral constant values and operations...
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
unsigned getActiveBits() const
Compute the number of active bits in the value.
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the maximum value of an extendable operand.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Get a value with upper bits starting at loBit set.
APInt getSetSize() const
Return the number of elements in this set.
void dump() const
Allow printing from a debugger easily.
APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
ConstantRange castOp(Instruction::CastOps CastOp, uint32_t BitWidth) const
Return a new range representing the possible values resulting from an application of the specified ca...
The operation itself must be expressed in terms of simpler actions on this target.
bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const
Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
static ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the largest range such that all values in the returned range satisfy the given predicate with...
bool isSizeStrictlySmallerThan(const ConstantRange &CR) const
Compare set size of this range with the range CR.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
bool isNegative() const
Determine sign of this APInt.
bool isAllOnesValue() const
Determine if all bits are set.
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the minimum value of an extendable operand.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
bool isSignWrappedSet() const
Return true if this set wraps around the INT_MIN of its bitwidth.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
ConstantRange(uint32_t BitWidth, bool isFullSet=true)
Initialize a full (the default) or empty set for the specified bit width.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl...
ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
bool isEmptySet() const
Return true if this set contains no members.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
This class represents a range of values.
ConstantRange smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
ConstantRange binaryOr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a binary-or of a value in this ran...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
const APInt * getSingleMissingElement() const
If this set contains all but a single element, return it, otherwise return null.
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
ConstantRange zeroExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
unsigned greater or equal
const APInt & getLower() const
Return the lower value for this range.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool isSingleElement() const
Return true if this set contains exactly one member.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
static ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)
Return the largest range containing all X such that "X BinOpC Y" is guaranteed not to wrap (overflow)...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
This class implements an extremely fast bulk output stream that can only output to a stream...
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
ConstantRange shl(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a left shift of a value in this ra...
static APInt getNullValue(unsigned numBits)
Get the '0' value.
unsigned getNumOperands() const
Return number of MDNode operands.
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
ConstantRange binaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other) const
Return a new range representing the possible values resulting from an application of the specified bi...
APInt sextOrSelf(unsigned width) const
Sign extend or truncate to width.
bool isNullValue() const
Determine if all bits are clear.
ConstantRange binaryAnd(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a binary-and of a value in this ra...