LLVM 20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | List of all members
llvm::ConstantRange Class Reference

This class represents a range of values. More...

#include "llvm/IR/ConstantRange.h"

Public Types

enum  PreferredRangeType { Smallest , Unsigned , Signed }
 If represented precisely, the result of some range operations may consist of multiple disjoint ranges. More...
 
enum class  OverflowResult { AlwaysOverflowsLow , AlwaysOverflowsHigh , MayOverflow , NeverOverflows }
 Represents whether an operation on the given constant range is known to always or never overflow. More...
 

Public Member Functions

 ConstantRange (uint32_t BitWidth, bool isFullSet)
 Initialize a full or empty set for the specified bit width.
 
 ConstantRange (APInt Value)
 Initialize a range to hold the single specified value.
 
 ConstantRange (APInt Lower, APInt Upper)
 Initialize a range of values explicitly.
 
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 predicate holds!
 
bool getEquivalentICmp (CmpInst::Predicate &Pred, APInt &RHS) const
 Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.
 
void getEquivalentICmp (CmpInst::Predicate &Pred, APInt &RHS, APInt &Offset) const
 Set up Pred, RHS and Offset such that (V + Offset) Pred RHS is true iff V is in the range.
 
const APIntgetLower () const
 Return the lower value for this range.
 
const APIntgetUpper () const
 Return the upper value for this range.
 
uint32_t getBitWidth () const
 Get the bit width of this ConstantRange.
 
bool isFullSet () const
 Return true if this set contains all of the elements possible for this data-type.
 
bool isEmptySet () const
 Return true if this set contains no members.
 
bool isWrappedSet () const
 Return true if this set wraps around the unsigned domain.
 
bool isUpperWrapped () const
 Return true if the exclusive upper bound wraps around the unsigned domain.
 
bool isSignWrappedSet () const
 Return true if this set wraps around the signed domain.
 
bool isUpperSignWrapped () const
 Return true if the (exclusive) upper bound wraps around the signed domain.
 
bool contains (const APInt &Val) const
 Return true if the specified value is in the set.
 
bool contains (const ConstantRange &CR) const
 Return true if the other range is a subset of this one.
 
const APIntgetSingleElement () const
 If this set contains a single element, return it, otherwise return null.
 
const APIntgetSingleMissingElement () const
 If this set contains all but a single element, return it, otherwise return null.
 
bool isSingleElement () const
 Return true if this set contains exactly one member.
 
bool isSizeStrictlySmallerThan (const ConstantRange &CR) const
 Compare set size of this range with the range CR.
 
bool isSizeLargerThan (uint64_t MaxSize) const
 Compare set size of this range with Value.
 
bool isAllNegative () const
 Return true if all values in this range are negative.
 
bool isAllNonNegative () const
 Return true if all values in this range are non-negative.
 
bool isAllPositive () const
 Return true if all values in this range are positive.
 
APInt getUnsignedMax () const
 Return the largest unsigned value contained in the ConstantRange.
 
APInt getUnsignedMin () const
 Return the smallest unsigned value contained in the ConstantRange.
 
APInt getSignedMax () const
 Return the largest signed value contained in the ConstantRange.
 
APInt getSignedMin () const
 Return the smallest signed value contained in the ConstantRange.
 
bool operator== (const ConstantRange &CR) const
 Return true if this range is equal to another range.
 
bool operator!= (const ConstantRange &CR) const
 
unsigned getActiveBits () const
 Compute the maximal number of active bits needed to represent every value in this range.
 
unsigned getMinSignedBits () const
 Compute the maximal number of bits needed to represent every value in this signed range.
 
ConstantRange subtract (const APInt &CI) const
 Subtract the specified constant from the endpoints of this constant range.
 
ConstantRange difference (const ConstantRange &CR) const
 Subtract the specified range from this range (aka relative complement of the sets).
 
ConstantRange intersectWith (const ConstantRange &CR, PreferredRangeType Type=Smallest) const
 Return the range that results from the intersection of this range with another range.
 
ConstantRange unionWith (const ConstantRange &CR, PreferredRangeType Type=Smallest) const
 Return the range that results from the union of this range with another range.
 
std::optional< ConstantRangeexactIntersectWith (const ConstantRange &CR) const
 Intersect the two ranges and return the result if it can be represented exactly, otherwise return std::nullopt.
 
std::optional< ConstantRangeexactUnionWith (const ConstantRange &CR) const
 Union the two ranges and return the result if it can be represented exactly, otherwise return std::nullopt.
 
ConstantRange castOp (Instruction::CastOps CastOp, uint32_t BitWidth) const
 Return a new range representing the possible values resulting from an application of the specified cast operator to this range.
 
ConstantRange zeroExtend (uint32_t BitWidth) const
 Return a new range in the specified integer type, which must be strictly larger than the current type.
 
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 truncate (uint32_t BitWidth) const
 Return a new range in the specified integer type, which must be strictly smaller than the current type.
 
ConstantRange zextOrTrunc (uint32_t BitWidth) const
 Make this range have the bit width given by BitWidth.
 
ConstantRange sextOrTrunc (uint32_t BitWidth) const
 Make this range have the bit width given by BitWidth.
 
ConstantRange binaryOp (Instruction::BinaryOps BinOp, const ConstantRange &Other) const
 Return a new range representing the possible values resulting from an application of the specified binary operator to an left hand side of this range and a right hand side of Other.
 
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 overflowing binary operator to a left hand side of this range and a right hand side of Other given the provided knowledge about lack of wrapping NoWrapKind.
 
ConstantRange add (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from an addition of a value in this range and a value in Other.
 
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 NoWrapKind of a value in this range and a value in Other.
 
ConstantRange sub (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a subtraction of a value in this range and a value in Other.
 
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 NoWrapKind of a value in this range and a value in Other.
 
ConstantRange multiply (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a multiplication of a value in this range and a value in Other, treating both this and Other as unsigned ranges.
 
ConstantRange multiplyWithNoWrap (const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const
 Return a new range representing the possible values resulting from a multiplication with wrap type NoWrapKind of a value in this range and a value in Other.
 
ConstantRange smul_fast (const ConstantRange &Other) const
 Return range of possible values for a signed multiplication of this and Other.
 
ConstantRange smax (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a signed maximum of a value in this range and a value in Other.
 
ConstantRange umax (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from an unsigned maximum of a value in this range and a value in Other.
 
ConstantRange smin (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a signed minimum of a value in this range and a value in Other.
 
ConstantRange umin (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from an unsigned minimum of a value in this range and a value in Other.
 
ConstantRange udiv (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from an unsigned division of a value in this range and a value in Other.
 
ConstantRange sdiv (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a signed division of a value in this range and a value in Other.
 
ConstantRange urem (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from an unsigned remainder operation of a value in this range and a value in Other.
 
ConstantRange srem (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a signed remainder operation of a value in this range and a value in Other.
 
ConstantRange binaryNot () const
 Return a new range representing the possible values resulting from a binary-xor of a value in this range by an all-one value, aka bitwise complement operation.
 
ConstantRange binaryAnd (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a binary-and of a value in this range by a value in Other.
 
ConstantRange binaryOr (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a binary-or of a value in this range by a value in Other.
 
ConstantRange binaryXor (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a binary-xor of a value in this range by a value in Other.
 
ConstantRange shl (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a left shift of a value in this range by a value in Other.
 
ConstantRange shlWithNoWrap (const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const
 Return a new range representing the possible values resulting from a left shift with wrap type NoWrapKind of a value in this range and a value in Other.
 
ConstantRange lshr (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a logical right shift of a value in this range and a value in Other.
 
ConstantRange ashr (const ConstantRange &Other) const
 Return a new range representing the possible values resulting from a arithmetic right shift of a value in this range and a value in Other.
 
ConstantRange uadd_sat (const ConstantRange &Other) const
 Perform an unsigned saturating addition of two constant ranges.
 
ConstantRange sadd_sat (const ConstantRange &Other) const
 Perform a signed saturating addition of two constant ranges.
 
ConstantRange usub_sat (const ConstantRange &Other) const
 Perform an unsigned saturating subtraction of two constant ranges.
 
ConstantRange ssub_sat (const ConstantRange &Other) const
 Perform a signed saturating subtraction of two constant ranges.
 
ConstantRange umul_sat (const ConstantRange &Other) const
 Perform an unsigned saturating multiplication of two constant ranges.
 
ConstantRange smul_sat (const ConstantRange &Other) const
 Perform a signed saturating multiplication of two constant ranges.
 
ConstantRange ushl_sat (const ConstantRange &Other) const
 Perform an unsigned saturating left shift of this constant range by a value in Other.
 
ConstantRange sshl_sat (const ConstantRange &Other) const
 Perform a signed saturating left shift of this constant range by a value in Other.
 
ConstantRange inverse () const
 Return a new range that is the logical not of the current set.
 
ConstantRange abs (bool IntMinIsPoison=false) const
 Calculate absolute value range.
 
ConstantRange ctlz (bool ZeroIsPoison=false) const
 Calculate ctlz range.
 
ConstantRange cttz (bool ZeroIsPoison=false) const
 Calculate cttz range.
 
ConstantRange ctpop () const
 Calculate ctpop range.
 
OverflowResult unsignedAddMayOverflow (const ConstantRange &Other) const
 Return whether unsigned add of the two ranges always/never overflows.
 
OverflowResult signedAddMayOverflow (const ConstantRange &Other) const
 Return whether signed add of the two ranges always/never overflows.
 
OverflowResult unsignedSubMayOverflow (const ConstantRange &Other) const
 Return whether unsigned sub of the two ranges always/never overflows.
 
OverflowResult signedSubMayOverflow (const ConstantRange &Other) const
 Return whether signed sub of the two ranges always/never overflows.
 
OverflowResult unsignedMulMayOverflow (const ConstantRange &Other) const
 Return whether unsigned mul of the two ranges always/never overflows.
 
KnownBits toKnownBits () const
 Return known bits for values in this range.
 
void print (raw_ostream &OS) const
 Print out the bounds to a stream.
 
void dump () const
 Allow printing from a debugger easily.
 

Static Public Member Functions

static ConstantRange getEmpty (uint32_t BitWidth)
 Create empty constant range with the given bit width.
 
static ConstantRange getFull (uint32_t BitWidth)
 Create full constant range with the given bit width.
 
static ConstantRange getNonEmpty (APInt Lower, APInt Upper)
 Create non-empty constant range with the given bounds.
 
static ConstantRange fromKnownBits (const KnownBits &Known, bool IsSigned)
 Initialize a range based on a known bits constraint.
 
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 contained within Other is contained in the returned 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 all values contained within Other.
 
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 any value contained within Other.
 
static bool areInsensitiveToSignednessOfICmpPredicate (const ConstantRange &CR1, const ConstantRange &CR2)
 Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.
 
static bool areInsensitiveToSignednessOfInvertedICmpPredicate (const ConstantRange &CR1, const ConstantRange &CR2)
 Return true iff CR1 ult CR2 is equivalent to CR1 sge CR2.
 
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 comparison predicate, return a predicate equivalent to Pred, with flipped signedness (i.e.
 
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) for all Y in 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.
 
static ConstantRange makeMaskNotEqualRange (const APInt &Mask, const APInt &C)
 Initialize a range containing all values X that satisfy (X & Mask) != C.
 
static bool isIntrinsicSupported (Intrinsic::ID IntrinsicID)
 Returns true if ConstantRange calculations are supported for intrinsic with IntrinsicID.
 
static ConstantRange intrinsic (Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)
 Compute range of intrinsic result for the given operand ranges.
 

Detailed Description

This class represents a range of values.

Definition at line 47 of file ConstantRange.h.

Member Enumeration Documentation

◆ OverflowResult

Represents whether an operation on the given constant range is known to always or never overflow.

Enumerator
AlwaysOverflowsLow 

Always overflows in the direction of signed/unsigned min value.

AlwaysOverflowsHigh 

Always overflows in the direction of signed/unsigned max value.

MayOverflow 

May or may not overflow.

NeverOverflows 

Never overflows.

Definition at line 567 of file ConstantRange.h.

◆ PreferredRangeType

If represented precisely, the result of some range operations may consist of multiple disjoint ranges.

As only a single range may be returned, any range covering these disjoint ranges constitutes a valid result, but some may be more useful than others depending on context. The preferred range type specifies whether a range that is non-wrapping in the unsigned or signed domain, or has the smallest size, is preferred. If a signedness is preferred but all ranges are non-wrapping or all wrapping, then the smallest set size is preferred. If there are multiple smallest sets, any one of them may be returned.

Enumerator
Smallest 
Unsigned 
Signed 

Definition at line 327 of file ConstantRange.h.

Constructor & Destructor Documentation

◆ ConstantRange() [1/3]

ConstantRange::ConstantRange ( uint32_t  BitWidth,
bool  isFullSet 
)
explicit

Initialize a full or empty set for the specified bit width.

Definition at line 45 of file ConstantRange.cpp.

◆ ConstantRange() [2/3]

ConstantRange::ConstantRange ( APInt  Value)

Initialize a range to hold the single specified value.

Definition at line 49 of file ConstantRange.cpp.

◆ ConstantRange() [3/3]

ConstantRange::ConstantRange ( APInt  Lower,
APInt  Upper 
)

Initialize a range of values explicitly.

This will assert out if Lower==Upper and Lower != Min or Max value for its type. It will also assert out if the two APInt's are not the same bit width.

Definition at line 52 of file ConstantRange.cpp.

References assert(), llvm::APInt::getBitWidth(), llvm::APInt::isMaxValue(), and llvm::APInt::isMinValue().

Member Function Documentation

◆ abs()

ConstantRange ConstantRange::abs ( bool  IntMinIsPoison = false) const

Calculate absolute value range.

If the original range contains signed min, then the resulting range will contain signed min if and only if IntMinIsPoison is false.

Definition at line 1879 of file ConstantRange.cpp.

References getBitWidth(), getNonEmpty(), getSignedMax(), getSignedMin(), llvm::APInt::getSignedMinValue(), llvm::APInt::getZero(), isEmptySet(), isSignWrappedSet(), llvm::APInt::isStrictlyPositive(), llvm::Lo, llvm::SMax, llvm::SMin, llvm::APIntOps::umax(), and llvm::APIntOps::umin().

Referenced by processSRem().

◆ add()

ConstantRange ConstantRange::add ( const ConstantRange Other) const

Return a new range representing the possible values resulting from an addition of a value in this range and a value in Other.

Definition at line 1067 of file ConstantRange.cpp.

References getLower(), getUpper(), isEmptySet(), isFullSet(), llvm::Other, and X.

Referenced by addWithNoWrap(), binaryOp(), llvm::JumpThreadingPass::computeValueKnownInPredecessorsImpl(), foldICmpUSubSatOrUAddSatWithConstant(), and getEquivalentICmp().

◆ addWithNoWrap()

ConstantRange 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 NoWrapKind of a value in this range and a value in Other.

If the result range is disjoint, the preferred range is determined by the PreferredRangeType.

Definition at line 1086 of file ConstantRange.cpp.

References add(), isEmptySet(), isFullSet(), llvm::Other, sadd_sat(), and uadd_sat().

Referenced by overflowingBinaryOp().

◆ areInsensitiveToSignednessOfICmpPredicate()

bool ConstantRange::areInsensitiveToSignednessOfICmpPredicate ( const ConstantRange CR1,
const ConstantRange CR2 
)
static

Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.

Does not depend on strictness/direction of the predicate.

Definition at line 170 of file ConstantRange.cpp.

References isAllNegative(), isAllNonNegative(), and isEmptySet().

Referenced by getEquivalentPredWithFlippedSignedness(), processICmp(), and processMinMaxIntrinsic().

◆ areInsensitiveToSignednessOfInvertedICmpPredicate()

bool ConstantRange::areInsensitiveToSignednessOfInvertedICmpPredicate ( const ConstantRange CR1,
const ConstantRange CR2 
)
static

Return true iff CR1 ult CR2 is equivalent to CR1 sge CR2.

Does not depend on strictness/direction of the predicate.

Definition at line 179 of file ConstantRange.cpp.

References isAllNegative(), isAllNonNegative(), and isEmptySet().

Referenced by getEquivalentPredWithFlippedSignedness().

◆ ashr()

ConstantRange ConstantRange::ashr ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a arithmetic right shift of a value in this range and a value in Other.

Definition at line 1735 of file ConstantRange.cpp.

References llvm::APInt::ashr(), getNonEmpty(), getSignedMax(), getSignedMin(), isEmptySet(), llvm::max(), and llvm::Other.

Referenced by binaryOp(), and makeGuaranteedNoWrapRegion().

◆ binaryAnd()

ConstantRange ConstantRange::binaryAnd ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a binary-and of a value in this range by a value in Other.

Definition at line 1523 of file ConstantRange.cpp.

References fromKnownBits(), getBitWidth(), getNonEmpty(), getUnsignedMax(), llvm::APInt::getZero(), intersectWith(), isEmptySet(), llvm::Other, toKnownBits(), and llvm::APIntOps::umin().

Referenced by binaryOp(), and canScalarizeAccess().

◆ binaryNot()

ConstantRange ConstantRange::binaryNot ( ) const

Return a new range representing the possible values resulting from a binary-xor of a value in this range by an all-one value, aka bitwise complement operation.

Definition at line 1519 of file ConstantRange.cpp.

References llvm::APInt::getAllOnes(), getBitWidth(), and sub().

Referenced by binaryXor().

◆ binaryOp()

ConstantRange ConstantRange::binaryOp ( Instruction::BinaryOps  BinOp,
const ConstantRange Other 
) const

Return a new range representing the possible values resulting from an application of the specified binary operator to an left hand side of this range and a right hand side of Other.

Definition at line 935 of file ConstantRange.cpp.

References add(), ashr(), assert(), binaryAnd(), binaryOr(), binaryXor(), llvm::Instruction::isBinaryOp(), lshr(), multiply(), llvm::Other, sdiv(), shl(), srem(), sub(), udiv(), and urem().

Referenced by overflowingBinaryOp().

◆ binaryOr()

ConstantRange ConstantRange::binaryOr ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a binary-or of a value in this range by a value in Other.

Definition at line 1535 of file ConstantRange.cpp.

References fromKnownBits(), getBitWidth(), getNonEmpty(), getUnsignedMin(), llvm::APInt::getZero(), intersectWith(), isEmptySet(), llvm::Other, toKnownBits(), and llvm::APIntOps::umax().

Referenced by binaryOp().

◆ binaryXor()

ConstantRange ConstantRange::binaryXor ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a binary-xor of a value in this range by a value in Other.

Definition at line 1548 of file ConstantRange.cpp.

References binaryNot(), fromKnownBits(), getBitWidth(), getSingleElement(), intersectWith(), isEmptySet(), isSingleElement(), llvm::KnownBits::One, llvm::Other, sub(), toKnownBits(), Unsigned, and llvm::KnownBits::Zero.

Referenced by binaryOp().

◆ castOp()

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 cast operator to this range.

BitWidth is the target bitwidth of the cast. For casts which don't change bitwidth, it must be the same as the source bitwidth. For casts which do change bitwidth, the bitwidth must be consistent with the requested cast and source bitwidth.

Definition at line 778 of file ConstantRange.cpp.

References getBitWidth(), llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), getNonEmpty(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), llvm_unreachable, signExtend(), llvm::SMax, llvm::SMin, truncate(), zeroExtend(), and llvm::APInt::zext().

◆ contains() [1/2]

bool ConstantRange::contains ( const APInt Val) const

◆ contains() [2/2]

bool ConstantRange::contains ( const ConstantRange CR) const

Return true if the other range is a subset of this one.

Definition at line 516 of file ConstantRange.cpp.

References isEmptySet(), isFullSet(), isUpperWrapped(), llvm::Other, and llvm::APInt::ule().

◆ ctlz()

ConstantRange ConstantRange::ctlz ( bool  ZeroIsPoison = false) const

Calculate ctlz range.

If ZeroIsPoison is set, the range is computed ignoring a possible zero value contained in the input range.

Definition at line 1921 of file ConstantRange.cpp.

References contains(), llvm::countl_zero(), getBitWidth(), getLower(), getNonEmpty(), getUnsignedMax(), getUnsignedMin(), getUpper(), llvm::APInt::getZero(), isEmptySet(), and isZero().

◆ ctpop()

ConstantRange ConstantRange::ctpop ( ) const

◆ cttz()

ConstantRange ConstantRange::cttz ( bool  ZeroIsPoison = false) const

Calculate cttz range.

If ZeroIsPoison is set, the range is computed ignoring a possible zero value contained in the input range.

Definition at line 1981 of file ConstantRange.cpp.

References llvm::BitWidth, contains(), getBitWidth(), getNonEmpty(), getUnsignedCountTrailingZerosRange(), llvm::APInt::getZero(), isEmptySet(), isFullSet(), isWrappedSet(), llvm::APInt::isZero(), and unionWith().

◆ difference()

ConstantRange ConstantRange::difference ( const ConstantRange CR) const

Subtract the specified range from this range (aka relative complement of the sets).

Definition at line 557 of file ConstantRange.cpp.

References intersectWith(), and inverse().

Referenced by llvm::InstCombinerImpl::foldICmpWithDominatingICmp().

◆ dump()

LLVM_DUMP_METHOD void ConstantRange::dump ( ) const

Allow printing from a debugger easily.

Definition at line 2195 of file ConstantRange.cpp.

References llvm::dbgs(), and print().

◆ exactIntersectWith()

std::optional< ConstantRange > ConstantRange::exactIntersectWith ( const ConstantRange CR) const

Intersect the two ranges and return the result if it can be represented exactly, otherwise return std::nullopt.

Definition at line 761 of file ConstantRange.cpp.

References intersectWith(), inverse(), and unionWith().

Referenced by foldICmpUSubSatOrUAddSatWithConstant().

◆ exactUnionWith()

std::optional< ConstantRange > ConstantRange::exactUnionWith ( const ConstantRange CR) const

Union the two ranges and return the result if it can be represented exactly, otherwise return std::nullopt.

Definition at line 770 of file ConstantRange.cpp.

References intersectWith(), inverse(), and unionWith().

Referenced by foldICmpUSubSatOrUAddSatWithConstant().

◆ fromKnownBits()

ConstantRange ConstantRange::fromKnownBits ( const KnownBits Known,
bool  IsSigned 
)
static

◆ getActiveBits()

unsigned ConstantRange::getActiveBits ( ) const

Compute the maximal number of active bits needed to represent every value in this range.

Definition at line 534 of file ConstantRange.cpp.

References llvm::APInt::getActiveBits(), getUnsignedMax(), and isEmptySet().

Referenced by llvm::TargetLoweringBase::getBitWidthForCttzElements(), narrowUDivOrURem(), and llvm::refineInstruction().

◆ getBitWidth()

uint32_t llvm::ConstantRange::getBitWidth ( ) const
inline

◆ getEmpty()

static ConstantRange llvm::ConstantRange::getEmpty ( uint32_t  BitWidth)
inlinestatic

Create empty constant range with the given bit width.

Definition at line 73 of file ConstantRange.h.

References BitWidth.

◆ getEquivalentICmp() [1/2]

bool ConstantRange::getEquivalentICmp ( CmpInst::Predicate Pred,
APInt RHS 
) const

Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.

Return true if successful.

Definition at line 236 of file ConstantRange.cpp.

References getEquivalentICmp(), llvm::Offset, and RHS.

Referenced by llvm::InstCombinerImpl::foldICmpAddConstant(), getEquivalentICmp(), and llvm::ScalarEvolution::SimplifyICmpOperands().

◆ getEquivalentICmp() [2/2]

void ConstantRange::getEquivalentICmp ( CmpInst::Predicate Pred,
APInt RHS,
APInt Offset 
) const

◆ getEquivalentPredWithFlippedSignedness()

CmpInst::Predicate ConstantRange::getEquivalentPredWithFlippedSignedness ( CmpInst::Predicate  Pred,
const ConstantRange CR1,
const ConstantRange CR2 
)
static

If the comparison between constant ranges this and Other is insensitive to the signedness of the comparison predicate, return a predicate equivalent to Pred, with flipped signedness (i.e.

unsigned instead of signed or vice versa), and maybe inverted, otherwise returns CmpInst::Predicate::BAD_ICMP_PREDICATE.

Definition at line 188 of file ConstantRange.cpp.

References areInsensitiveToSignednessOfICmpPredicate(), areInsensitiveToSignednessOfInvertedICmpPredicate(), assert(), llvm::CmpInst::BAD_ICMP_PREDICATE, llvm::ICmpInst::getFlippedSignednessPredicate(), llvm::CmpInst::getInversePredicate(), llvm::CmpInst::isIntPredicate(), and llvm::CmpInst::isRelational().

Referenced by processICmp().

◆ getFull()

static ConstantRange llvm::ConstantRange::getFull ( uint32_t  BitWidth)
inlinestatic

Create full constant range with the given bit width.

Definition at line 78 of file ConstantRange.h.

References BitWidth.

◆ getLower()

const APInt & llvm::ConstantRange::getLower ( ) const
inline

◆ getMinSignedBits()

unsigned ConstantRange::getMinSignedBits ( ) const

Compute the maximal number of bits needed to represent every value in this signed range.

Definition at line 541 of file ConstantRange.cpp.

References getSignedMax(), getSignedMin(), and isEmptySet().

Referenced by narrowSDivOrSRem(), and llvm::refineInstruction().

◆ getNonEmpty()

static ConstantRange llvm::ConstantRange::getNonEmpty ( APInt  Lower,
APInt  Upper 
)
inlinestatic

◆ getSignedMax()

APInt ConstantRange::getSignedMax ( ) const

◆ getSignedMin()

APInt ConstantRange::getSignedMin ( ) const

◆ getSingleElement()

const APInt * llvm::ConstantRange::getSingleElement ( ) const
inline

◆ getSingleMissingElement()

const APInt * llvm::ConstantRange::getSingleMissingElement ( ) const
inline

If this set contains all but a single element, return it, otherwise return null.

Definition at line 259 of file ConstantRange.h.

References llvm::Upper.

Referenced by getEquivalentICmp().

◆ getUnsignedMax()

APInt ConstantRange::getUnsignedMax ( ) const

◆ getUnsignedMin()

APInt ConstantRange::getUnsignedMin ( ) const

◆ getUpper()

const APInt & llvm::ConstantRange::getUpper ( ) const
inline

◆ icmp()

bool ConstantRange::icmp ( CmpInst::Predicate  Pred,
const ConstantRange Other 
) const

◆ intersectWith()

ConstantRange ConstantRange::intersectWith ( const ConstantRange CR,
PreferredRangeType  Type = Smallest 
) const

◆ intrinsic()

ConstantRange ConstantRange::intrinsic ( Intrinsic::ID  IntrinsicID,
ArrayRef< ConstantRange Ops 
)
static

Compute range of intrinsic result for the given operand ranges.

Definition at line 1021 of file ConstantRange.cpp.

References assert(), llvm::APInt::getBitWidth(), llvm::APInt::getBoolValue(), isIntrinsicSupported(), and llvm_unreachable.

◆ inverse()

ConstantRange ConstantRange::inverse ( ) const

◆ isAllNegative()

bool ConstantRange::isAllNegative ( ) const

◆ isAllNonNegative()

bool ConstantRange::isAllNonNegative ( ) const

◆ isAllPositive()

bool ConstantRange::isAllPositive ( ) const

Return true if all values in this range are positive.

Definition at line 473 of file ConstantRange.cpp.

References isEmptySet(), isFullSet(), isSignWrappedSet(), and llvm::APInt::isStrictlyPositive().

◆ isEmptySet()

bool ConstantRange::isEmptySet ( ) const

◆ isFullSet()

bool ConstantRange::isFullSet ( ) const

◆ isIntrinsicSupported()

bool ConstantRange::isIntrinsicSupported ( Intrinsic::ID  IntrinsicID)
static

Returns true if ConstantRange calculations are supported for intrinsic with IntrinsicID.

Definition at line 1001 of file ConstantRange.cpp.

Referenced by intrinsic().

◆ isSignWrappedSet()

bool ConstantRange::isSignWrappedSet ( ) const

Return true if this set wraps around the signed domain.

Special cases:

  • Empty set: Not wrapped.
  • Full set: Not wrapped.
  • [X, SignedMin) == [X, SignedMax]: Not wrapped.

Definition at line 430 of file ConstantRange.cpp.

References llvm::APInt::isMinSignedValue(), and llvm::APInt::sgt().

Referenced by abs(), getPreferredRange(), getSignedMin(), isAllNonNegative(), isAllPositive(), signExtend(), smax(), and smin().

◆ isSingleElement()

bool llvm::ConstantRange::isSingleElement ( ) const
inline

◆ isSizeLargerThan()

bool ConstantRange::isSizeLargerThan ( uint64_t  MaxSize) const

Compare set size of this range with Value.

Definition at line 449 of file ConstantRange.cpp.

References getBitWidth(), llvm::APInt::getMaxValue(), isFullSet(), and llvm::APInt::ugt().

Referenced by processSwitch().

◆ isSizeStrictlySmallerThan()

bool ConstantRange::isSizeStrictlySmallerThan ( const ConstantRange CR) const

Compare set size of this range with the range CR.

Definition at line 439 of file ConstantRange.cpp.

References assert(), getBitWidth(), isFullSet(), and llvm::Other.

Referenced by getPreferredRange(), and multiply().

◆ isUpperSignWrapped()

bool ConstantRange::isUpperSignWrapped ( ) const

Return true if the (exclusive) upper bound wraps around the signed domain.

Special cases:

  • Empty set: Not wrapped.
  • Full set: Not wrapped.
  • [X, SignedMin): Wrapped.

Definition at line 434 of file ConstantRange.cpp.

References llvm::APInt::sgt().

Referenced by getSignedMax(), and isAllNegative().

◆ isUpperWrapped()

bool ConstantRange::isUpperWrapped ( ) const

Return true if the exclusive upper bound wraps around the unsigned domain.

Special cases:

  • Empty set: Not wrapped.
  • Full set: Not wrapped.
  • [X, 0): Wrapped.

Definition at line 426 of file ConstantRange.cpp.

References llvm::APInt::ugt().

Referenced by contains(), getUnsignedMax(), intersectWith(), multiply(), switchToLookupTable(), truncate(), unionWith(), and zeroExtend().

◆ isWrappedSet()

bool ConstantRange::isWrappedSet ( ) const

Return true if this set wraps around the unsigned domain.

Special cases:

  • Empty set: Not wrapped.
  • Full set: Not wrapped.
  • [X, 0) == [X, Max]: Not wrapped.

Definition at line 422 of file ConstantRange.cpp.

References llvm::APInt::isZero(), and llvm::APInt::ugt().

Referenced by ctpop(), cttz(), getPreferredRange(), getUnsignedMin(), umax(), and umin().

◆ lshr()

ConstantRange ConstantRange::lshr ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a logical right shift of a value in this range and a value in Other.

Definition at line 1725 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::APInt::lshr(), llvm::max(), and llvm::Other.

Referenced by binaryOp(), and makeGuaranteedNoWrapRegion().

◆ makeAllowedICmpRegion()

ConstantRange ConstantRange::makeAllowedICmpRegion ( CmpInst::Predicate  Pred,
const ConstantRange Other 
)
static

Produce the smallest range such that all values that may satisfy the given predicate with any value contained within Other is contained in the returned range.

Formally, this returns a superset of 'union over all y in Other . { x : icmp op x y is true }'. If the exact answer is not representable as a ConstantRange, the return value will be a proper superset of the above.

Example: Pred = ult and Other = i8 [2, 5) returns Result = [0, 4)

Definition at line 98 of file ConstantRange.cpp.

References getBitWidth(), getLower(), llvm::APInt::getMinValue(), getNonEmpty(), getSignedMax(), getSignedMin(), llvm::APInt::getSignedMinValue(), getUnsignedMax(), getUnsignedMin(), getUpper(), llvm::APInt::getZero(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, isEmptySet(), isSingleElement(), llvm_unreachable, llvm::SMax, llvm::SMin, llvm::UMax, and llvm::UMin.

Referenced by llvm::computeConstantRange(), computeKnownBitsFromCmp(), isImpliedCondCommonOperandWithCR(), makeExactICmpRegion(), and makeSatisfyingICmpRegion().

◆ makeExactICmpRegion()

ConstantRange ConstantRange::makeExactICmpRegion ( CmpInst::Predicate  Pred,
const APInt Other 
)
static

Produce the exact range such that all values in the returned range satisfy the given predicate with any value contained within Other.

Formally, this returns the exact answer when the superset of 'union over all y in Other is exactly same as the subset of intersection over all y in Other. { x : icmp op x y is true}'.

Example: Pred = ult and Other = i8 3 returns [0, 3)

Definition at line 158 of file ConstantRange.cpp.

References assert(), llvm::CallingConv::C, makeAllowedICmpRegion(), and makeSatisfyingICmpRegion().

Referenced by cmpExcludesZero(), computeKnownBitsFromOperator(), llvm::JumpThreadingPass::computeValueKnownInPredecessorsImpl(), llvm::InstCombinerImpl::foldICmpAddConstant(), foldICmpUSubSatOrUAddSatWithConstant(), llvm::InstCombinerImpl::foldICmpWithDominatingICmp(), getEquivalentICmp(), llvm::isKnownInversion(), simplifyAndOrOfICmpsWithConstants(), llvm::ScalarEvolution::SimplifyICmpOperands(), simplifyICmpWithConstant(), and simplifySwitchOnSelectUsingRanges().

◆ makeExactNoWrapRegion()

ConstantRange ConstantRange::makeExactNoWrapRegion ( Instruction::BinaryOps  BinOp,
const APInt Other,
unsigned  NoWrapKind 
)
static

Produce the range that contains X if and only if "X BinOp Other" does not wrap.

Definition at line 389 of file ConstantRange.cpp.

References makeGuaranteedNoWrapRegion(), and llvm::Other.

Referenced by foldICmpUSubSatOrUAddSatWithConstant(), and getValueFromOverflowCondition().

◆ makeGuaranteedNoWrapRegion()

ConstantRange ConstantRange::makeGuaranteedNoWrapRegion ( Instruction::BinaryOps  BinOp,
const ConstantRange Other,
unsigned  NoWrapKind 
)
static

Produce the largest range containing all X such that "X BinOp Y" is guaranteed not to wrap (overflow) for all Y in Other.

However, there may be some Y in Other for which additional X not contained in the result also do not overflow.

NoWrapKind must be one of OBO::NoUnsignedWrap or OBO::NoSignedWrap.

Examples: typedef OverflowingBinaryOperator OBO; #define MGNR makeGuaranteedNoWrapRegion MGNR(Add, [i8 1, 2), OBO::NoSignedWrap) == [-128, 127) MGNR(Add, [i8 1, 2), OBO::NoUnsignedWrap) == [0, -1) MGNR(Add, [i8 0, 1), OBO::NoUnsignedWrap) == Full Set MGNR(Add, [i8 -1, 6), OBO::NoSignedWrap) == [INT_MIN+1, INT_MAX-4) MGNR(Sub, [i8 1, 2), OBO::NoSignedWrap) == [-127, 128) MGNR(Sub, [i8 1, 2), OBO::NoUnsignedWrap) == [1, 0)

Definition at line 315 of file ConstantRange.cpp.

References ashr(), assert(), llvm::BitWidth, llvm::CallingConv::C, llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), getNonEmpty(), llvm::APInt::getSignedMaxValue(), llvm::APInt::getSignedMinValue(), getUnsignedMax(), llvm::APInt::getZero(), intersectWith(), llvm::Instruction::isBinaryOp(), isEmptySet(), llvm_unreachable, lshr(), makeExactMulNSWRegion(), makeExactMulNUWRegion(), llvm::Other, llvm::SMax, llvm::SMin, and Unsigned.

Referenced by llvm::ScalarEvolution::getMulExpr(), makeExactNoWrapRegion(), processBinOp(), llvm::refineInstruction(), StrengthenNoWrapFlags(), and willNotOverflow().

◆ makeMaskNotEqualRange()

ConstantRange ConstantRange::makeMaskNotEqualRange ( const APInt Mask,
const APInt C 
)
static

Initialize a range containing all values X that satisfy (X & Mask) != C.

Note that the range returned may contain values where (X & Mask) == C holds, making it less precise, but still conservative.

Definition at line 397 of file ConstantRange.cpp.

References llvm::BitWidth, llvm::CallingConv::C, getNonEmpty(), and llvm::APInt::getOneBitSet().

◆ makeSatisfyingICmpRegion()

ConstantRange ConstantRange::makeSatisfyingICmpRegion ( CmpInst::Predicate  Pred,
const ConstantRange Other 
)
static

Produce the largest range such that all values in the returned range satisfy the given predicate with all values contained within Other.

Formally, this returns a subset of 'intersection over all y in Other . { x : icmp op x y is true }'. If the exact answer is not representable as a ConstantRange, the return value will be a proper subset of the above.

Example: Pred = ult and Other = i8 [2, 5) returns [0, 2)

Definition at line 148 of file ConstantRange.cpp.

References llvm::CmpInst::getInversePredicate(), inverse(), and makeAllowedICmpRegion().

Referenced by makeExactICmpRegion().

◆ multiply()

ConstantRange ConstantRange::multiply ( const ConstantRange Other) const

◆ multiplyWithNoWrap()

ConstantRange ConstantRange::multiplyWithNoWrap ( const ConstantRange Other,
unsigned  NoWrapKind,
PreferredRangeType  RangeType = Smallest 
) const

Return a new range representing the possible values resulting from a multiplication with wrap type NoWrapKind of a value in this range and a value in Other.

If the result range is disjoint, the preferred range is determined by the PreferredRangeType.

Definition at line 1232 of file ConstantRange.cpp.

References getBitWidth(), getNonEmpty(), getSignedMin(), llvm::APInt::getSignedMinValue(), llvm::APInt::getZero(), isEmptySet(), isFullSet(), multiply(), llvm::OverflowingBinaryOperator::NoSignedWrap, llvm::OverflowingBinaryOperator::NoUnsignedWrap, llvm::Other, smul_sat(), and umul_sat().

Referenced by overflowingBinaryOp().

◆ operator!=()

bool llvm::ConstantRange::operator!= ( const ConstantRange CR) const
inline

Definition at line 299 of file ConstantRange.h.

References llvm::operator==().

◆ operator==()

bool llvm::ConstantRange::operator== ( const ConstantRange CR) const
inline

Return true if this range is equal to another range.

Definition at line 296 of file ConstantRange.h.

References llvm::Upper.

◆ overflowingBinaryOp()

ConstantRange 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 overflowing binary operator to a left hand side of this range and a right hand side of Other given the provided knowledge about lack of wrapping NoWrapKind.

Definition at line 980 of file ConstantRange.cpp.

References addWithNoWrap(), assert(), binaryOp(), llvm::Instruction::isBinaryOp(), multiplyWithNoWrap(), llvm::Other, shlWithNoWrap(), and subWithNoWrap().

◆ print()

void ConstantRange::print ( raw_ostream OS) const

Print out the bounds to a stream.

Definition at line 2185 of file ConstantRange.cpp.

References isEmptySet(), isFullSet(), and OS.

Referenced by dump(), llvm::operator<<(), and llvm::ScalarEvolution::print().

◆ sadd_sat()

ConstantRange ConstantRange::sadd_sat ( const ConstantRange Other) const

Perform a signed saturating addition of two constant ranges.

Definition at line 1794 of file ConstantRange.cpp.

References getNonEmpty(), getSignedMax(), getSignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::sadd_sat().

Referenced by addWithNoWrap().

◆ sdiv()

ConstantRange ConstantRange::sdiv ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a signed division of a value in this range and a value in Other.

Division by zero and division of SignedMin by -1 are considered undefined behavior, in line with IR, and do not contribute towards the result.

Definition at line 1358 of file ConstantRange.cpp.

References contains(), getBitWidth(), llvm::APInt::getSignedMinValue(), llvm::APInt::getZero(), intersectWith(), llvm::APInt::isAllOnes(), isEmptySet(), llvm::APInt::isMinSignedValue(), llvm::APInt::isZero(), llvm::Lo, RHS, llvm::APInt::sdiv(), sdiv(), Signed, and unionWith().

Referenced by binaryOp(), processSDiv(), and sdiv().

◆ sextOrTrunc()

ConstantRange ConstantRange::sextOrTrunc ( uint32_t  BitWidth) const

Make this range have the bit width given by BitWidth.

The value is sign extended, truncated, or left alone to make it that width.

Definition at line 926 of file ConstantRange.cpp.

References getBitWidth(), signExtend(), and truncate().

Referenced by llvm::ScalarEvolution::getSignExtendExprImpl(), and writeFunctionTypeMetadataRecords().

◆ shl()

ConstantRange ConstantRange::shl ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a left shift of a value in this range by a value in Other.

TODO: This isn't fully implemented yet.

Definition at line 1581 of file ConstantRange.cpp.

References llvm::APInt::countl_one(), llvm::countl_zero(), llvm::APInt::getBitsSetFrom(), getBitWidth(), getNonEmpty(), getUnsignedMax(), getUnsignedMin(), llvm::APInt::getZero(), isAllNegative(), isEmptySet(), llvm::Other, RHS, llvm::APInt::ugt(), and llvm::APInt::ule().

Referenced by binaryOp(), and shlWithNoWrap().

◆ shlWithNoWrap()

ConstantRange ConstantRange::shlWithNoWrap ( const ConstantRange Other,
unsigned  NoWrapKind,
PreferredRangeType  RangeType = Smallest 
) const

Return a new range representing the possible values resulting from a left shift with wrap type NoWrapKind of a value in this range and a value in Other.

If the result range is disjoint, the preferred range is determined by the PreferredRangeType.

Definition at line 1702 of file ConstantRange.cpp.

References computeShlNSW(), computeShlNUW(), intersectWith(), isEmptySet(), llvm_unreachable, llvm::OverflowingBinaryOperator::NoSignedWrap, llvm::OverflowingBinaryOperator::NoUnsignedWrap, llvm::Other, and shl().

Referenced by overflowingBinaryOp().

◆ signedAddMayOverflow()

ConstantRange::OverflowResult ConstantRange::signedAddMayOverflow ( const ConstantRange Other) const

◆ signedSubMayOverflow()

ConstantRange::OverflowResult ConstantRange::signedSubMayOverflow ( const ConstantRange Other) const

◆ signExtend()

ConstantRange ConstantRange::signExtend ( uint32_t  BitWidth) const

Return a new range in the specified integer type, which must be strictly larger than the current type.

The returned range will correspond to the possible range of values if the source range had been sign extended to BitWidth.

Definition at line 846 of file ConstantRange.cpp.

References assert(), getBitWidth(), llvm::APInt::getHighBitsSet(), llvm::APInt::getLowBitsSet(), isEmptySet(), isFullSet(), llvm::APInt::isMinSignedValue(), isSignWrappedSet(), llvm::APInt::sext(), and llvm::APInt::zext().

Referenced by castOp(), llvm::SelectionDAG::ComputeNumSignBits(), computeNumSignBitsFromRangeMetadata(), llvm::ScalarEvolution::getSignExtendExprImpl(), and sextOrTrunc().

◆ smax()

ConstantRange ConstantRange::smax ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a signed maximum of a value in this range and a value in Other.

Definition at line 1282 of file ConstantRange.cpp.

References getNonEmpty(), getSignedMax(), getSignedMin(), intersectWith(), isEmptySet(), isSignWrappedSet(), llvm::Other, Signed, llvm::APIntOps::smax(), and unionWith().

◆ smin()

ConstantRange ConstantRange::smin ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a signed minimum of a value in this range and a value in Other.

Definition at line 1310 of file ConstantRange.cpp.

References getNonEmpty(), getSignedMax(), getSignedMin(), intersectWith(), isEmptySet(), isSignWrappedSet(), llvm::Other, Signed, llvm::APIntOps::smin(), and unionWith().

◆ smul_fast()

ConstantRange ConstantRange::smul_fast ( const ConstantRange Other) const

Return range of possible values for a signed multiplication of this and Other.

However, if overflow is possible always return a full range rather than trying to determine a more precise result.

Definition at line 1262 of file ConstantRange.cpp.

References A, B, getNonEmpty(), getSignedMax(), getSignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::smul_ov().

◆ smul_sat()

ConstantRange ConstantRange::smul_sat ( const ConstantRange Other) const

Perform a signed saturating multiplication of two constant ranges.

Definition at line 1830 of file ConstantRange.cpp.

References A, B, getNonEmpty(), getSignedMax(), getSignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::smul_sat().

Referenced by multiplyWithNoWrap().

◆ srem()

ConstantRange ConstantRange::srem ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a signed remainder operation of a value in this range and a value in Other.

Definition at line 1468 of file ConstantRange.cpp.

References getBitWidth(), getSignedMax(), getSignedMin(), getSingleElement(), getUnsignedMax(), getUnsignedMin(), llvm::APInt::getZero(), isEmptySet(), llvm::APInt::isNonNegative(), llvm::APInt::isZero(), RHS, llvm::APInt::ugt(), llvm::APIntOps::umax(), llvm::APIntOps::umin(), and llvm::Upper.

Referenced by binaryOp().

◆ sshl_sat()

ConstantRange ConstantRange::sshl_sat ( const ConstantRange Other) const

Perform a signed saturating left shift of this constant range by a value in Other.

Definition at line 1860 of file ConstantRange.cpp.

References getNonEmpty(), getSignedMax(), getSignedMin(), isEmptySet(), llvm::APInt::isNonNegative(), llvm::Other, and llvm::APInt::sshl_sat().

◆ ssub_sat()

ConstantRange ConstantRange::ssub_sat ( const ConstantRange Other) const

Perform a signed saturating subtraction of two constant ranges.

Definition at line 1812 of file ConstantRange.cpp.

References getNonEmpty(), getSignedMax(), getSignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::ssub_sat().

Referenced by subWithNoWrap().

◆ sub()

ConstantRange ConstantRange::sub ( const ConstantRange Other) const

Return a new range representing the possible values resulting from a subtraction of a value in this range and a value in Other.

Definition at line 1114 of file ConstantRange.cpp.

References getLower(), getUpper(), isEmptySet(), isFullSet(), llvm::Other, and X.

Referenced by binaryNot(), binaryOp(), binaryXor(), computeKnownBitsFromCmp(), foldICmpUSubSatOrUAddSatWithConstant(), multiply(), and subWithNoWrap().

◆ subtract()

ConstantRange ConstantRange::subtract ( const APInt CI) const

Subtract the specified constant from the endpoints of this constant range.

Definition at line 549 of file ConstantRange.cpp.

References assert(), llvm::APInt::getBitWidth(), and getBitWidth().

Referenced by llvm::InstCombinerImpl::foldICmpAddConstant(), llvm::TargetLoweringBase::getBitWidthForCttzElements(), and llvm::SCEVAddRecExpr::getNumIterationsInRange().

◆ subWithNoWrap()

ConstantRange 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 NoWrapKind of a value in this range and a value in Other.

If the result range is disjoint, the preferred range is determined by the PreferredRangeType.

Definition at line 1133 of file ConstantRange.cpp.

References getUnsignedMax(), isEmptySet(), isFullSet(), llvm::Other, ssub_sat(), sub(), and usub_sat().

Referenced by overflowingBinaryOp().

◆ toKnownBits()

KnownBits ConstantRange::toKnownBits ( ) const

◆ truncate()

ConstantRange ConstantRange::truncate ( uint32_t  BitWidth) const

Return a new range in the specified integer type, which must be strictly smaller than the current type.

The returned range will correspond to the possible range of values if the source range had been truncated to the specified type.

Definition at line 864 of file ConstantRange.cpp.

References assert(), llvm::APInt::clearBit(), llvm::APInt::countr_one(), llvm::APInt::getActiveBits(), llvm::APInt::getBitsSetFrom(), getBitWidth(), llvm::APInt::getMaxValue(), isEmptySet(), isFullSet(), isUpperWrapped(), llvm::APInt::setAllBits(), llvm::APInt::trunc(), llvm::APInt::ult(), and unionWith().

Referenced by castOp(), llvm::InstCombinerImpl::foldICmpAddConstant(), llvm::ScalarEvolution::getSignExtendExprImpl(), llvm::ScalarEvolution::getZeroExtendExprImpl(), multiply(), sextOrTrunc(), and zextOrTrunc().

◆ uadd_sat()

ConstantRange ConstantRange::uadd_sat ( const ConstantRange Other) const

Perform an unsigned saturating addition of two constant ranges.

Definition at line 1785 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::uadd_sat().

Referenced by addWithNoWrap(), and expandUDivOrURem().

◆ udiv()

ConstantRange ConstantRange::udiv ( const ConstantRange Other) const

Return a new range representing the possible values resulting from an unsigned division of a value in this range and a value in Other.

Definition at line 1338 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::APInt::isZero(), RHS, llvm::APInt::udiv(), and llvm::Upper.

Referenced by binaryOp().

◆ umax()

ConstantRange ConstantRange::umax ( const ConstantRange Other) const

Return a new range representing the possible values resulting from an unsigned maximum of a value in this range and a value in Other.

Definition at line 1296 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), intersectWith(), isEmptySet(), isWrappedSet(), llvm::Other, llvm::APIntOps::umax(), unionWith(), and Unsigned.

◆ umin()

ConstantRange ConstantRange::umin ( const ConstantRange Other) const

Return a new range representing the possible values resulting from an unsigned minimum of a value in this range and a value in Other.

Definition at line 1324 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), intersectWith(), isEmptySet(), isWrappedSet(), llvm::Other, llvm::APIntOps::umin(), unionWith(), and Unsigned.

◆ umul_sat()

ConstantRange ConstantRange::umul_sat ( const ConstantRange Other) const

Perform an unsigned saturating multiplication of two constant ranges.

Definition at line 1821 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::umul_sat().

Referenced by llvm::TargetLoweringBase::getBitWidthForCttzElements(), and multiplyWithNoWrap().

◆ unionWith()

ConstantRange ConstantRange::unionWith ( const ConstantRange CR,
PreferredRangeType  Type = Smallest 
) const

Return the range that results from the union of this range with another range.

The resultant range is guaranteed to include the elements of both sets, but may contain more. For example, [3, 9) union [12,15) is [3, 15), which includes 9, 10, and 11, which were not included in either set before.

Definition at line 687 of file ConstantRange.cpp.

References assert(), getBitWidth(), getPreferredRange(), isEmptySet(), isFullSet(), isUpperWrapped(), llvm::APInt::uge(), llvm::APInt::ugt(), llvm::APInt::ule(), llvm::APInt::ult(), and unionWith().

Referenced by llvm::computeConstantRange(), computeShlNSW(), ctpop(), cttz(), exactIntersectWith(), exactUnionWith(), llvm::getConstantRangeFromMetadata(), llvm::AttributeSet::intersectWith(), llvm::IntegerRangeState::operator&=(), sdiv(), smax(), smin(), llvm::Constant::toConstantRange(), truncate(), tryMergeRange(), umax(), umin(), llvm::IntegerRangeState::unionAssumed(), and unionWith().

◆ unsignedAddMayOverflow()

ConstantRange::OverflowResult ConstantRange::unsignedAddMayOverflow ( const ConstantRange Other) const

◆ unsignedMulMayOverflow()

ConstantRange::OverflowResult ConstantRange::unsignedMulMayOverflow ( const ConstantRange Other) const

Return whether unsigned mul of the two ranges always/never overflows.

Definition at line 2165 of file ConstantRange.cpp.

References AlwaysOverflowsHigh, getUnsignedMax(), getUnsignedMin(), isEmptySet(), MayOverflow, NeverOverflows, llvm::Other, and llvm::APInt::umul_ov().

Referenced by llvm::computeOverflowForUnsignedMul(), and llvm::SelectionDAG::computeOverflowForUnsignedMul().

◆ unsignedSubMayOverflow()

ConstantRange::OverflowResult ConstantRange::unsignedSubMayOverflow ( const ConstantRange Other) const

◆ urem()

ConstantRange ConstantRange::urem ( const ConstantRange Other) const

Return a new range representing the possible values resulting from an unsigned remainder operation of a value in this range and a value in Other.

Definition at line 1446 of file ConstantRange.cpp.

References getBitWidth(), getNonEmpty(), getSingleElement(), getUnsignedMax(), llvm::APInt::getZero(), isEmptySet(), RHS, llvm::APIntOps::umin(), and llvm::Upper.

Referenced by binaryOp(), and canScalarizeAccess().

◆ ushl_sat()

ConstantRange ConstantRange::ushl_sat ( const ConstantRange Other) const

Perform an unsigned saturating left shift of this constant range by a value in Other.

Definition at line 1851 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::ushl_sat().

◆ usub_sat()

ConstantRange ConstantRange::usub_sat ( const ConstantRange Other) const

Perform an unsigned saturating subtraction of two constant ranges.

Definition at line 1803 of file ConstantRange.cpp.

References getNonEmpty(), getUnsignedMax(), getUnsignedMin(), isEmptySet(), llvm::Other, and llvm::APInt::usub_sat().

Referenced by subWithNoWrap().

◆ zeroExtend()

ConstantRange ConstantRange::zeroExtend ( uint32_t  BitWidth) const

Return a new range in the specified integer type, which must be strictly larger than the current type.

The returned range will correspond to the possible range of values if the source range had been zero extended to BitWidth.

Definition at line 829 of file ConstantRange.cpp.

References assert(), getBitWidth(), llvm::APInt::getOneBitSet(), isEmptySet(), isFullSet(), isUpperWrapped(), and llvm::APInt::zext().

Referenced by castOp(), llvm::SelectionDAG::ComputeNumSignBits(), computeNumSignBitsFromRangeMetadata(), llvm::ScalarEvolution::getZeroExtendExprImpl(), and zextOrTrunc().

◆ zextOrTrunc()

ConstantRange ConstantRange::zextOrTrunc ( uint32_t  BitWidth) const

Make this range have the bit width given by BitWidth.

The value is zero extended, truncated, or left alone to make it that width.

Definition at line 917 of file ConstantRange.cpp.

References getBitWidth(), truncate(), and zeroExtend().

Referenced by llvm::ScalarEvolution::getZeroExtendExprImpl().


The documentation for this class was generated from the following files: