Go to the documentation of this file.
24 #include "llvm/Config/llvm-config.h"
53 "ConstantRange with unequal bit widths");
55 "Lower == Upper, but they aren't min or max value!");
113 if (
UMax.isMinValue())
119 if (
SMax.isMinSignedValue())
129 if (
UMin.isMaxValue())
135 if (
SMin.isMaxSignedValue())
190 "Only for relational integer predicates!");
196 return FlippedSignednessPred;
201 return CmpInst::Predicate::BAD_ICMP_PREDICATE;
215 RHS = *OnlyMissingElt;
264 if (V == 0 || V.
isOne())
265 return ConstantRange::getFull(
BitWidth);
290 unsigned NoWrapKind) {
295 assert((NoWrapKind == OBO::NoSignedWrap ||
296 NoWrapKind == OBO::NoUnsignedWrap) &&
297 "NoWrapKind invalid!");
299 bool Unsigned = NoWrapKind == OBO::NoUnsignedWrap;
313 SMin.isNegative() ? SignedMinVal -
SMin : SignedMinVal,
314 SMax.isStrictlyPositive() ? SignedMinVal -
SMax : SignedMinVal);
317 case Instruction::Sub: {
324 SMax.isStrictlyPositive() ? SignedMinVal +
SMax : SignedMinVal,
325 SMin.isNegative() ? SignedMinVal +
SMin : SignedMinVal);
335 case Instruction::Shl: {
360 unsigned NoWrapKind) {
379 return Lower.ugt(Upper);
387 return Lower.sgt(Upper);
395 if (
Other.isFullSet())
407 return (Upper -
Lower).ugt(MaxSize);
454 return Lower.ule(V) && V.
ult(Upper);
455 return Lower.ule(V) || V.
ult(Upper);
463 if (
Other.isUpperWrapped())
469 if (!
Other.isUpperWrapped())
470 return Other.getUpper().ule(Upper) ||
526 "ConstantRange types don't agree!");
536 if (
Lower.ult(CR.Lower)) {
539 if (Upper.
ule(CR.Lower))
544 if (Upper.
ult(CR.Upper))
553 if (Upper.
ult(CR.Upper))
558 if (
Lower.ult(CR.Upper))
567 if (CR.Lower.
ult(Upper)) {
570 if (CR.Upper.
ult(Upper))
598 if (CR.Upper.
ult(Upper)) {
601 if (CR.Lower.
ult(Upper))
632 "ConstantRange types don't agree!");
651 APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper;
667 if (CR.Lower.
ule(Upper) &&
Lower.ule(CR.Upper))
681 if (Upper.
ult(CR.Lower) &&
Lower.ule(CR.Upper))
687 "ConstantRange::unionWith missed a case with one range wrapped");
693 if (CR.Lower.
ule(Upper) ||
Lower.ule(CR.Upper))
697 APInt U = CR.Upper.
ugt(Upper) ? CR.Upper : Upper;
725 case Instruction::Trunc:
727 case Instruction::SExt:
729 case Instruction::ZExt:
731 case Instruction::BitCast:
733 case Instruction::FPToUI:
734 case Instruction::FPToSI:
738 return getFull(ResultBitWidth);
739 case Instruction::UIToFP: {
744 if (ResultBitWidth > BW) {
745 Min = Min.
zext(ResultBitWidth);
746 Max = Max.zext(ResultBitWidth);
750 case Instruction::SIToFP: {
755 if (ResultBitWidth > BW) {
761 case Instruction::FPTrunc:
762 case Instruction::FPExt:
763 case Instruction::IntToPtr:
764 case Instruction::PtrToInt:
765 case Instruction::AddrSpaceCast:
767 return getFull(ResultBitWidth);
775 assert(SrcTySize < DstTySize &&
"Not a value extension");
778 APInt LowerExt(DstTySize, 0);
780 LowerExt =
Lower.zext(DstTySize);
792 assert(SrcTySize < DstTySize &&
"Not a value extension");
809 return getEmpty(DstTySize);
811 return getFull(DstTySize);
824 return getFull(DstTySize);
831 if (LowerDiv == UpperDiv)
836 if (LowerDiv.getActiveBits() > DstTySize) {
844 if (UpperDivWidth <= DstTySize)
846 UpperDiv.
trunc(DstTySize)).unionWith(Union);
849 if (UpperDivWidth == DstTySize + 1) {
852 if (UpperDiv.
ult(LowerDiv))
854 UpperDiv.
trunc(DstTySize)).unionWith(Union);
857 return getFull(DstTySize);
862 if (SrcTySize > DstTySize)
864 if (SrcTySize < DstTySize)
871 if (SrcTySize > DstTySize)
873 if (SrcTySize < DstTySize)
885 case Instruction::Sub:
889 case Instruction::UDiv:
891 case Instruction::SDiv:
893 case Instruction::URem:
895 case Instruction::SRem:
897 case Instruction::Shl:
899 case Instruction::LShr:
901 case Instruction::AShr:
903 case Instruction::And:
905 case Instruction::Or:
907 case Instruction::Xor:
911 case Instruction::FAdd:
913 case Instruction::FSub:
915 case Instruction::FMul:
925 unsigned NoWrapKind)
const {
931 case Instruction::Sub:
941 switch (IntrinsicID) {
942 case Intrinsic::uadd_sat:
943 case Intrinsic::usub_sat:
944 case Intrinsic::sadd_sat:
945 case Intrinsic::ssub_sat:
959 switch (IntrinsicID) {
960 case Intrinsic::uadd_sat:
961 return Ops[0].uadd_sat(Ops[1]);
962 case Intrinsic::usub_sat:
963 return Ops[0].usub_sat(Ops[1]);
964 case Intrinsic::sadd_sat:
965 return Ops[0].sadd_sat(Ops[1]);
966 case Intrinsic::ssub_sat:
967 return Ops[0].ssub_sat(Ops[1]);
969 return Ops[0].umin(Ops[1]);
971 return Ops[0].umax(Ops[1]);
973 return Ops[0].smin(Ops[1]);
975 return Ops[0].smax(Ops[1]);
977 const APInt *IntMinIsPoison = Ops[1].getSingleElement();
978 assert(IntMinIsPoison &&
"Must be known (immarg)");
997 if (NewLower == NewUpper)
1001 if (
X.isSizeStrictlySmallerThan(*
this) ||
1002 X.isSizeStrictlySmallerThan(
Other))
1009 unsigned NoWrapKind,
1026 if (NoWrapKind & OBO::NoSignedWrap)
1029 if (NoWrapKind & OBO::NoUnsignedWrap)
1044 if (NewLower == NewUpper)
1048 if (
X.isSizeStrictlySmallerThan(*
this) ||
1049 X.isSizeStrictlySmallerThan(
Other))
1056 unsigned NoWrapKind,
1073 if (NoWrapKind & OBO::NoSignedWrap)
1076 if (NoWrapKind & OBO::NoUnsignedWrap) {
1108 this_max * Other_max + 1);
1130 auto L = {this_min * Other_min, this_min * Other_max,
1131 this_max * Other_min, this_max * Other_max};
1148 bool O1, O2, O3, O4;
1149 auto Muls = {Min.
smul_ov(OtherMin, O1), Min.
smul_ov(OtherMax, O2),
1150 Max.smul_ov(OtherMin, O3), Max.smul_ov(OtherMax, O4)};
1151 if (O1 || O2 || O3 || O4)
1221 APInt RHS_umin =
RHS.getUnsignedMin();
1225 if (
RHS.getUpper() == 1)
1226 RHS_umin =
RHS.getLower();
1252 (PosL.Upper - 1).
sdiv(PosR.Lower) + 1);
1267 if (
RHS.Lower.isAllOnes())
1269 AdjNegRUpper =
RHS.Upper;
1272 AdjNegRUpper = NegR.Upper - 1;
1280 if (NegL.Upper != SignedMin + 1) {
1282 if (Upper == SignedMin + 1)
1284 AdjNegLLower =
Lower;
1287 AdjNegLLower = NegL.Lower + 1;
1291 AdjNegLLower.
sdiv(NegR.Upper - 1) + 1));
1302 NegRes =
ConstantRange((PosL.Upper - 1).sdiv(NegR.Upper - 1),
1303 PosL.Lower.
sdiv(NegR.Lower) + 1);
1309 (NegL.Upper - 1).
sdiv(PosR.Upper - 1) + 1));
1324 if (
const APInt *RHSInt =
RHS.getSingleElement()) {
1326 if (RHSInt->isZero())
1330 return {LHSInt->urem(*RHSInt)};
1346 if (
const APInt *RHSInt =
RHS.getSingleElement()) {
1348 if (RHSInt->isZero())
1352 return {LHSInt->srem(*RHSInt)};
1370 if (MaxLHS.ult(MinAbsRHS))
1379 if (MaxLHS.isNegative()) {
1380 if (MinLHS.
ugt(-MinAbsRHS))
1432 if (
Other.isSingleElement() &&
Other.getSingleElement()->isAllOnes())
1435 return Other.binaryNot();
1453 if (
RHS->ule(EqualLeadingBits))
1463 if (OtherMax.
ugt(Max.countLeadingZeros()))
1468 Min <<=
Other.getUnsignedMin();
1596 Max.smul_sat(OtherMin), Max.smul_sat(OtherMax)};
1615 APInt ShAmtMin =
Other.getUnsignedMin(), ShAmtMax =
Other.getUnsignedMax();
1617 APInt NewU = Max.sshl_sat(Max.isNegative() ? ShAmtMin : ShAmtMax) + 1;
1651 if (IntMinIsPoison &&
SMin.isMinSignedValue()) {
1653 if (
SMax.isMinSignedValue())
1659 if (
SMin.isNonNegative())
1663 if (
SMax.isNegative())
1677 APInt OtherMin =
Other.getUnsignedMin(), OtherMax =
Other.getUnsignedMax();
1680 if (Min.
ugt(~OtherMin))
1682 if (Max.ugt(~OtherMax))
1693 APInt OtherMin =
Other.getSignedMin(), OtherMax =
Other.getSignedMax();
1701 Min.
sgt(SignedMax - OtherMin))
1703 if (Max.isNegative() && OtherMax.isNegative() &&
1704 Max.slt(SignedMin - OtherMax))
1707 if (Max.isNonNegative() && OtherMax.isNonNegative() &&
1708 Max.sgt(SignedMax - OtherMax))
1711 Min.
slt(SignedMin - OtherMin))
1723 APInt OtherMin =
Other.getUnsignedMin(), OtherMax =
Other.getUnsignedMax();
1726 if (Max.ult(OtherMin))
1728 if (Min.
ult(OtherMax))
1739 APInt OtherMin =
Other.getSignedMin(), OtherMax =
Other.getSignedMax();
1747 Min.
sgt(SignedMax + OtherMax))
1750 Max.slt(SignedMin + OtherMin))
1753 if (Max.isNonNegative() && OtherMin.
isNegative() &&
1754 Max.sgt(SignedMax + OtherMin))
1756 if (Min.
isNegative() && OtherMax.isNonNegative() &&
1757 Min.
slt(SignedMin + OtherMax))
1769 APInt OtherMin =
Other.getUnsignedMin(), OtherMax =
Other.getUnsignedMax();
1772 (void) Min.
umul_ov(OtherMin, Overflow);
1776 (void) Max.umul_ov(OtherMax, Overflow);
1789 OS <<
"[" <<
Lower <<
"," << Upper <<
")";
1792 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1800 assert(NumRanges >= 1 &&
"Must have at least one range!");
1803 auto *FirstLow = mdconst::extract<ConstantInt>(Ranges.
getOperand(0));
1804 auto *FirstHigh = mdconst::extract<ConstantInt>(Ranges.
getOperand(1));
1806 ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());
1808 for (
unsigned i = 1;
i < NumRanges; ++
i) {
1809 auto *
Low = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 0));
1810 auto *
High = mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 1));
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
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 binaryOr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a binary-or of a value in this ran...
void setAllBits()
Set every bit to 1.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This is an optimization pass for GlobalISel generic memory operations.
@ AlwaysOverflowsLow
Always overflows in the direction of signed/unsigned min value.
ConstantRange ushl_sat(const ConstantRange &Other) const
Perform an unsigned saturating left shift of this constant range by a value in Other.
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...
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
ConstantRange sdiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed division of a value in th...
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 dump() const
Allow printing from a debugger easily.
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
ConstantRange umul_sat(const ConstantRange &Other) const
Perform an unsigned saturating multiplication of two constant ranges.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
ConstantRange udiv(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned division of a value in...
ConstantRange ssub_sat(const ConstantRange &Other) const
Perform a signed saturating subtraction of two constant ranges.
Predicate getFlippedSignednessPredicate()
For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->Failed assert.
bool isUnknown() const
Returns true if we don't know any bits.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
@ AlwaysOverflowsHigh
Always overflows in the direction of signed/unsigned max value.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
bool isUpperSignWrapped() const
Return true if the (exclusive) upper bound wraps around the signed domain.
bool isAllNonNegative() const
Return true if all values in this range are non-negative.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
bool isOne() const
Determine if this is a value of 1.
bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const
Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
Optional< ConstantRange > exactIntersectWith(const ConstantRange &CR) const
Intersect the two ranges and return the result if it can be represented exactly, otherwise return Non...
@ ICMP_SGT
signed greater than
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isSignWrappedSet() const
Return true if this set wraps around the signed domain.
ConstantRange uadd_sat(const ConstantRange &Other) const
Perform an unsigned saturating addition of two constant ranges.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
ConstantRange multiply(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
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...
@ ICMP_SLE
signed less or equal
ConstantRange sshl_sat(const ConstantRange &Other) const
Perform a signed saturating left shift of this constant range by a value in Other.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
@ SMin
Signed integer min implemented in terms of select(cmp()).
Optional< unsigned > GetMostSignificantDifferentBit(const APInt &A, const APInt &B)
Compare two values, and if they are different, return the position of the most significant bit that i...
OverflowResult unsignedAddMayOverflow(const ConstantRange &Other) const
Return whether unsigned add of the two ranges always/never overflows.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
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 bool isIntrinsicSupported(Intrinsic::ID IntrinsicID)
Returns true if ConstantRange calculations are supported for intrinsic with IntrinsicID.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
OverflowResult
Represents whether an operation on the given constant range is known to always or never overflow.
static ConstantRange getPreferredRange(const ConstantRange &CR1, const ConstantRange &CR2, ConstantRange::PreferredRangeType Type)
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...
unsigned getNumOperands() const
Return number of MDNode operands.
OverflowResult signedSubMayOverflow(const ConstantRange &Other) const
Return whether signed sub of the two ranges always/never overflows.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool isNegative() const
Determine sign of this APInt.
ConstantRange binaryXor(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a binary-xor of a value in this ra...
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
bool isWrappedSet() const
Return true if this set wraps around the unsigned domain.
static bool areInsensitiveToSignednessOfICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)
Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.
APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
(vector float) vec_cmpeq(*A, *B) C
APInt usub_sat(const APInt &RHS) const
@ ICMP_ULE
unsigned less or equal
PreferredRangeType
If represented precisely, the result of some range operations may consist of multiple disjoint ranges...
bool isSingleElement() const
Return true if this set contains exactly one member.
ConstantRange abs(bool IntMinIsPoison=false) const
Calculate absolute value range.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
bool hasConflict() const
Returns true if there is conflicting information.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)
Produce the largest range containing all X such that "X BinOp Y" is guaranteed not to wrap (overflow)...
ConstantRange srem(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed remainder operation of a ...
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
Optional< ConstantRange > exactUnionWith(const ConstantRange &CR) const
Union the two ranges and return the result if it can be represented exactly, otherwise return None.
ConstantRange lshr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a logical right shift of a value i...
bool isUpperWrapped() const
Return true if the exclusive upper bound wraps around the unsigned domain.
ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
This class implements an extremely fast bulk output stream that can only output to a stream.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
APInt smul_sat(const APInt &RHS) const
bool isNegative() const
Returns true if this value is known to be negative.
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 isSizeLargerThan(uint64_t MaxSize) const
Compare set size of this range with Value.
ConstantRange smul_fast(const ConstantRange &Other) const
Return range of possible values for a signed multiplication of this and Other.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
@ UMin
Unisgned integer min implemented in terms of select(cmp()).
static ConstantRange intrinsic(Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)
Compute range of intrinsic result for the given operand ranges.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
ConstantRange overflowingBinaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind) const
Return a new range representing the possible values resulting from an application of the specified ov...
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
const MDOperand & getOperand(unsigned I) const
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...
@ Lower
The operation itself must be expressed in terms of simpler actions on this target.
bool isAllNegative() const
Return true if all values in this range are negative.
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 slt(const APInt &RHS) const
Signed less than comparison.
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
ConstantRange zextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
static CmpInst::Predicate getEquivalentPredWithFlippedSignedness(CmpInst::Predicate Pred, const ConstantRange &CR1, const ConstantRange &CR2)
If the comparison between constant ranges this and Other is insensitive to the signedness of the comp...
ConstantRange smul_sat(const ConstantRange &Other) const
Perform a signed saturating multiplication of two constant ranges.
bool getBoolValue() const
Convert APInt to a boolean value.
ConstantRange addWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const
Return a new range representing the possible values resulting from an addition with wrap type NoWrapK...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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 sadd_sat(const ConstantRange &Other) const
Perform a signed saturating addition of two constant ranges.
@ ICMP_UGE
unsigned greater or equal
OverflowResult unsignedMulMayOverflow(const ConstantRange &Other) const
Return whether unsigned mul of the two ranges always/never overflows.
static bool areInsensitiveToSignednessOfInvertedICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)
Return true iff CR1 ult CR2 is equivalent to CR1 sge CR2.
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
Class for arbitrary precision integers.
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
@ ICMP_SLT
signed less than
bool isIntPredicate() const
QP Compare Ordered outs ins xscmpudp No builtin are required Or llvm fcmp order unorder compare DP QP Compare builtin are required DP Compare
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
@ UMax
Unsigned integer max implemented in terms of select(cmp()).
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
APInt sshl_sat(const APInt &RHS) const
@ ICMP_ULT
unsigned less than
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static ConstantRange makeExactMulNSWRegion(const APInt &V)
Exact mul nsw region for single element RHS.
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
APInt ushl_sat(const APInt &RHS) const
APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A sign-divided by B, rounded by the given rounding mode.
ConstantRange(uint32_t BitWidth, bool isFullSet)
Initialize a full or empty set for the specified bit width.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
APInt umul_sat(const APInt &RHS) const
bool ult(const APInt &RHS) const
Unsigned less than comparison.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
APInt zext(unsigned width) const
Zero extend to a new width.
bool isSizeStrictlySmallerThan(const ConstantRange &CR) const
Compare set size of this range with the range CR.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
APInt ssub_sat(const APInt &RHS) const
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
const APInt & umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
const APInt & getLower() const
Return the lower value for this range.
APInt uadd_sat(const APInt &RHS) const
APInt trunc(unsigned width) const
Truncate to new width.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
void clearSignBit()
Set the sign bit to 0.
ConstantRange smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
unsigned getMinSignedBits() const
Compute the maximal number of bits needed to represent every value in this signed range.
ConstantRange subWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const
Return a new range representing the possible values resulting from an subtraction with wrap type NoWr...
constexpr unsigned BitWidth
APInt smul_ov(const APInt &RHS, bool &Overflow) const
unsigned getActiveBits() const
Compute the maximal number of active bits needed to represent every value in this range.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
@ ICMP_SGE
signed greater or equal
unsigned 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.
const APInt * getSingleMissingElement() const
If this set contains all but a single element, return it, otherwise return null.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
This class represents a range of values.
APInt sext(unsigned width) const
Sign extend to a new width.
ConstantRange urem(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned remainder operation of...
static ConstantRange getNonEmpty(APInt Lower, APInt Upper)
Create non-empty constant range with the given bounds.
KnownBits toKnownBits() const
Return known bits for values in this range.
ConstantRange binaryNot() const
Return a new range representing the possible values resulting from a binary-xor of a value in this ra...
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the maximum value of an extendable operand.
ConstantRange ashr(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a arithmetic right shift of a valu...
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
static ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)
Initialize a range based on a known bits constraint.
@ ICMP_UGT
unsigned greater than
OverflowResult signedAddMayOverflow(const ConstantRange &Other) const
Return whether signed add of the two ranges always/never overflows.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getActiveBits() const
Compute the number of active bits in the value.
void print(raw_ostream &OS) const
Print out the bounds to a stream.
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other? NOTE: false does not mean that inverse pr...
ConstantRange usub_sat(const ConstantRange &Other) const
Perform an unsigned saturating subtraction of two constant ranges.
static ConstantRange makeExactMulNUWRegion(const APInt &V)
Exact mul nuw region for single element RHS.
@ NeverOverflows
Never overflows.
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...
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the minimum value of an extendable operand.
OverflowResult unsignedSubMayOverflow(const ConstantRange &Other) const
Return whether unsigned sub of the two ranges always/never overflows.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
APInt sadd_sat(const APInt &RHS) const
APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A unsign-divided by B, rounded by the given rounding mode.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits 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...
unsigned getBitWidth() const
Get the bit width of this value.
static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)
Constructs an APInt value that has a contiguous range of bits set.
bool isEmptySet() const
Return true if this set contains no members.
ConstantRange sextOrTrunc(uint32_t BitWidth) const
Make this range have the bit width given by BitWidth.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
const APInt & getUpper() const
Return the upper value for this range.
@ SMax
Signed integer max implemented in terms of select(cmp()).
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
@ MayOverflow
May or may not overflow.
Optional< std::vector< StOtherPiece > > Other
static ConstantRange makeExactNoWrapRegion(Instruction::BinaryOps BinOp, const APInt &Other, unsigned NoWrapKind)
Produce the range that contains X if and only if "X BinOp Other" does not wrap.