51 "ConstantRange with unequal bit widths");
53 "Lower == Upper, but they aren't min or max value!");
73 if (UMax.isMinValue())
79 if (SMax.isMinSignedValue())
85 if (UMax.isMaxValue())
91 if (SMax.isMaxSignedValue())
97 if (UMin.isMaxValue())
103 if (SMin.isMaxSignedValue())
109 if (UMin.isMinValue())
115 if (SMin.isMinSignedValue())
158 RHS = *OnlyMissingElt;
181 unsigned NoWrapKind) {
188 auto SubsetIntersect =
193 assert(BinOp >= Instruction::BinaryOpsBegin &&
194 BinOp < Instruction::BinaryOpsEnd &&
"Binary operators only!");
196 assert((NoWrapKind == OBO::NoSignedWrap ||
197 NoWrapKind == OBO::NoUnsignedWrap ||
198 NoWrapKind == (OBO::NoUnsignedWrap | OBO::NoSignedWrap)) &&
199 "NoWrapKind invalid!");
207 if (
C->isNullValue())
213 if (NoWrapKind & OBO::NoUnsignedWrap)
218 if (NoWrapKind & OBO::NoSignedWrap) {
223 Result = SubsetIntersect(
229 Result = SubsetIntersect(
246 return Lower.
ugt(Upper);
269 return (Upper - Lower).ult(Other.Upper - Other.Lower);
274 assert(MaxSize &&
"MaxSize can't be 0.");
280 return (Upper - Lower).ugt(MaxSize);
312 return Lower.
ule(V) && V.
ult(Upper);
313 return Lower.
ule(V) || V.
ult(Upper);
348 "ConstantRange types don't agree!");
358 if (Lower.
ult(CR.Lower)) {
359 if (Upper.
ule(CR.Lower))
362 if (Upper.
ult(CR.Upper))
367 if (Upper.
ult(CR.Upper))
370 if (Lower.
ult(CR.Upper))
377 if (CR.Lower.
ult(Upper)) {
378 if (CR.Upper.
ult(Upper))
381 if (CR.Upper.
ule(Lower))
388 if (CR.Lower.
ult(Lower)) {
389 if (CR.Upper.
ule(Lower))
397 if (CR.Upper.
ult(Upper)) {
398 if (CR.Lower.
ult(Upper)) {
404 if (CR.Lower.
ult(Lower))
409 if (CR.Upper.
ule(Lower)) {
410 if (CR.Lower.
ult(Lower))
422 "ConstantRange types don't agree!");
430 if (CR.Upper.
ult(Lower) || Upper.
ult(CR.Lower)) {
432 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
438 APInt L = CR.Lower.
ult(Lower) ? CR.Lower : Lower;
439 APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper;
450 if (CR.Upper.
ule(Upper) || CR.Lower.
uge(Lower))
455 if (CR.Lower.
ule(Upper) && Lower.
ule(CR.Upper))
461 if (Upper.
ule(CR.Lower) && CR.Upper.
ule(Lower)) {
462 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
470 if (Upper.
ult(CR.Lower) && Lower.
ult(CR.Upper))
476 "ConstantRange::unionWith missed a case with one range wrapped");
482 if (CR.Lower.
ule(Upper) || Lower.
ule(CR.Upper))
485 APInt L = CR.Lower.
ult(Lower) ? CR.Lower : Lower;
486 APInt U = CR.Upper.
ugt(Upper) ? CR.Upper : Upper;
496 case Instruction::Trunc:
498 case Instruction::SExt:
500 case Instruction::ZExt:
502 case Instruction::BitCast:
504 case Instruction::FPToUI:
505 case Instruction::FPToSI:
510 case Instruction::UIToFP: {
517 case Instruction::SIToFP: {
524 case Instruction::FPTrunc:
525 case Instruction::FPExt:
526 case Instruction::IntToPtr:
527 case Instruction::PtrToInt:
528 case Instruction::AddrSpaceCast:
538 assert(SrcTySize < DstTySize &&
"Not a value extension");
541 APInt LowerExt(DstTySize, 0);
543 LowerExt = Lower.
zext(DstTySize);
555 assert(SrcTySize < DstTySize &&
"Not a value extension");
576 APInt LowerDiv(Lower), UpperDiv(Upper);
594 if (LowerDiv == UpperDiv)
599 if (LowerDiv.getActiveBits() > DstTySize) {
607 if (UpperDivWidth <= DstTySize)
612 if (UpperDivWidth == DstTySize + 1) {
615 if (UpperDiv.
ult(LowerDiv))
625 if (SrcTySize > DstTySize)
627 if (SrcTySize < DstTySize)
634 if (SrcTySize > DstTySize)
636 if (SrcTySize < DstTySize)
643 assert(BinOp >= Instruction::BinaryOpsBegin &&
644 BinOp < Instruction::BinaryOpsEnd &&
"Binary operators only!");
649 case Instruction::Sub:
651 case Instruction::Mul:
653 case Instruction::UDiv:
655 case Instruction::Shl:
657 case Instruction::LShr:
659 case Instruction::And:
661 case Instruction::Or:
665 case Instruction::FAdd:
667 case Instruction::FSub:
669 case Instruction::FMul:
686 if (NewLower == NewUpper)
719 if (NewLower == NewUpper)
753 this_max * Other_max + 1);
775 auto L = {this_min * Other_min, this_min * Other_max,
776 this_max * Other_min, this_max * Other_max};
939 OS <<
"[" << Lower <<
"," << Upper <<
")";
942 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
950 assert(NumRanges >= 1 &&
"Must have at least one range!");
953 auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.
getOperand(0));
954 auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.
getOperand(1));
956 ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
958 for (
unsigned i = 1; i < NumRanges; ++i) {
959 auto *Low = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 0));
960 auto *
High = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 1));
964 CR = CR.unionWith(
ConstantRange(Low->getValue(), High->getValue()));
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool isSizeLargerThan(uint64_t MaxSize) const
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
unsigned getNumOperands() const
Return number of MDNode operands.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const
Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
void setAllBits()
Set every bit to 1.
bool isSingleElement() const
Return true if this set contains exactly one member.
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...
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
bool isNegative() const
Determine sign of this APInt.
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 signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
This file implements a class to represent arbitrary precision integral constant values and operations...
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
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.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
unsigned getActiveBits() const
Compute the number of active bits in the value.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Get a value with upper bits starting at loBit set.
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
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...
void dump() const
Allow printing from a debugger easily.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the minimum value of an extendable operand.
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
APInt trunc(unsigned width) const
Truncate to new width.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
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 getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
const APInt * getSingleMissingElement() const
If this set contains all but a single element, return it, otherwise return null.
APInt sextOrSelf(unsigned width) const
Sign extend or truncate to width.
bool isWrappedSet() const
Return true if this set wraps around the top of the range.
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 sext(unsigned width) const
Sign extend to a new width.
ConstantRange udiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned division of a value in...
ConstantRange(uint32_t BitWidth, bool isFullSet=true)
Initialize a full (the default) or empty set for the specified bit width.
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...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
unsigned getBitWidth() const
Return the number of bits in the APInt.
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...
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
ConstantRange addWithNoSignedWrap(const APInt &Other) const
Return a new range representing the possible values resulting from a known NSW addition of a value in...
bool isMaxValue() const
Determine if this is the largest unsigned value.
ConstantRange sub(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a subtraction of a value in this r...
void print(raw_ostream &OS) const
Print out the bounds to a stream.
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 isEmptySet() const
Return true if this set contains no members.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
const MDOperand & getOperand(unsigned I) const
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...
bool isSignWrappedSet() const
Return true if this set wraps around the INT_MIN of its bitwidth.
APInt getSetSize() const
Return the number of elements in this set.
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
bool isSizeStrictlySmallerThan(const ConstantRange &CR) const
Compare set size of this range with the range CR.
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
Class for arbitrary precision integers.
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.
bool isMinValue() const
Determine if this is the smallest unsigned value.
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...
llvm_unreachable("Unknown RegBank!")
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
bool isAllOnesValue() const
Determine if all bits are set.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
unsigned greater or equal
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...
unsigned countTrailingOnes() const
Count the number of trailing one bits.
const APInt & getUpper() const
Return the upper value for this range.
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 smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
ConstantRange zextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
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.
APInt zext(unsigned width) const
Zero extend to a new width.
bool isNullValue() const
Determine if all bits are clear.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
bool slt(const APInt &RHS) const
Signed less than comparison.