49 "ConstantRange with unequal bit widths");
51 "Lower == Upper, but they aren't min or max value!");
71 if (UMax.isMinValue())
77 if (SMax.isMinSignedValue())
83 if (UMax.isMaxValue())
89 if (SMax.isMaxSignedValue())
95 if (UMin.isMaxValue())
101 if (SMin.isMaxSignedValue())
107 if (UMin.isMinValue())
113 if (SMin.isMinSignedValue())
156 RHS = *OnlyMissingElt;
179 unsigned NoWrapKind) {
186 auto SubsetIntersect =
191 assert(BinOp >= Instruction::BinaryOpsBegin &&
192 BinOp < Instruction::BinaryOpsEnd &&
"Binary operators only!");
194 assert((NoWrapKind == OBO::NoSignedWrap ||
195 NoWrapKind == OBO::NoUnsignedWrap ||
196 NoWrapKind == (OBO::NoUnsignedWrap | OBO::NoSignedWrap)) &&
197 "NoWrapKind invalid!");
211 if (NoWrapKind & OBO::NoUnsignedWrap)
216 if (NoWrapKind & OBO::NoSignedWrap) {
221 Result = SubsetIntersect(
227 Result = SubsetIntersect(
251 return Lower.
ugt(Upper);
332 return Lower.
ule(V) && V.
ult(Upper);
333 return Lower.
ule(V) || V.
ult(Upper);
381 "ConstantRange types don't agree!");
391 if (Lower.
ult(CR.Lower)) {
392 if (Upper.
ule(CR.Lower))
395 if (Upper.
ult(CR.Upper))
400 if (Upper.
ult(CR.Upper))
403 if (Lower.
ult(CR.Upper))
410 if (CR.Lower.
ult(Upper)) {
411 if (CR.Upper.
ult(Upper))
414 if (CR.Upper.
ule(Lower))
421 if (CR.Lower.
ult(Lower)) {
422 if (CR.Upper.
ule(Lower))
430 if (CR.Upper.
ult(Upper)) {
431 if (CR.Lower.
ult(Upper)) {
437 if (CR.Lower.
ult(Lower))
442 if (CR.Upper.
ule(Lower)) {
443 if (CR.Lower.
ult(Lower))
462 "ConstantRange types don't agree!");
470 if (CR.Upper.
ult(Lower) || Upper.
ult(CR.Lower)) {
472 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
478 APInt L = Lower, U = Upper;
481 if ((CR.Upper - 1).ugt(U - 1))
484 if (L == 0 && U == 0)
493 if (CR.Upper.
ule(Upper) || CR.Lower.
uge(Lower))
498 if (CR.Lower.
ule(Upper) && Lower.
ule(CR.Upper))
504 if (Upper.
ule(CR.Lower) && CR.Upper.
ule(Lower)) {
505 APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
513 if (Upper.
ult(CR.Lower) && Lower.
ult(CR.Upper))
519 "ConstantRange::unionWith missed a case with one range wrapped");
525 if (CR.Lower.
ule(Upper) || Lower.
ule(CR.Upper))
528 APInt L = Lower, U = Upper;
542 case Instruction::Trunc:
544 case Instruction::SExt:
546 case Instruction::ZExt:
548 case Instruction::BitCast:
550 case Instruction::FPToUI:
551 case Instruction::FPToSI:
556 case Instruction::UIToFP: {
563 case Instruction::SIToFP: {
570 case Instruction::FPTrunc:
571 case Instruction::FPExt:
572 case Instruction::IntToPtr:
573 case Instruction::PtrToInt:
574 case Instruction::AddrSpaceCast:
588 assert(SrcTySize < DstTySize &&
"Not a value extension");
591 APInt LowerExt(DstTySize, 0);
593 LowerExt = Lower.
zext(DstTySize);
608 assert(SrcTySize < DstTySize &&
"Not a value extension");
635 MaxBitValue.
setBit(DstTySize);
637 APInt LowerDiv(Lower), UpperDiv(Upper);
645 if (Upper.
uge(MaxValue))
653 if (LowerDiv == UpperDiv)
658 if (LowerDiv.uge(MaxValue)) {
661 UpperDiv = UpperDiv - MaxBitValue * Div;
664 if (UpperDiv.
ule(MaxValue))
669 APInt UpperModulo = UpperDiv - MaxBitValue;
670 if (UpperModulo.
ult(LowerDiv))
681 if (SrcTySize > DstTySize)
683 if (SrcTySize < DstTySize)
692 if (SrcTySize > DstTySize)
694 if (SrcTySize < DstTySize)
701 assert(BinOp >= Instruction::BinaryOpsBegin &&
702 BinOp < Instruction::BinaryOpsEnd &&
"Binary operators only!");
707 case Instruction::Sub:
709 case Instruction::Mul:
711 case Instruction::UDiv:
713 case Instruction::Shl:
715 case Instruction::LShr:
723 case Instruction::FAdd:
725 case Instruction::FSub:
727 case Instruction::FMul:
745 if (NewLower == NewUpper)
779 if (NewLower == NewUpper)
813 this_max * Other_max + 1);
834 auto L = {this_min * Other_min, this_min * Other_max,
835 this_max * Other_min, this_max * Other_max};
996 OS <<
"[" << Lower <<
"," << Upper <<
")";
1007 assert(NumRanges >= 1 &&
"Must have at least one range!");
1010 auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.
getOperand(0));
1011 auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.
getOperand(1));
1013 ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
1015 for (
unsigned i = 1;
i < NumRanges; ++
i) {
1016 auto *Low = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 0));
1017 auto *
High = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 1));
1021 CR = CR.unionWith(
ConstantRange(Low->getValue(), High->getValue()));
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
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...
void setBit(unsigned bitPosition)
Set a given bit to 1.
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.
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...
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
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...
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
ConstantRange signExtend(uint32_t BitWidth) const
Return a new range in the specified integer type, which must be strictly larger than the current type...
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
APInt shl(unsigned shiftAmt) const
Left-shift function.
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.
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.
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
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 etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool ult(const APInt &RHS) const
Unsigned less than comparison.
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.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
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.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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 slt(const APInt &RHS) const
Signed less than comparison.
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.
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 ...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
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...
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.
static void udivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
Dual division/remainder interface.
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...
APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.