LLVM 19.0.0git
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
llvm::KnownBits Struct Reference

#include "llvm/Support/KnownBits.h"

Public Member Functions

 KnownBits ()=default
 
 KnownBits (unsigned BitWidth)
 Create a known bits object of BitWidth bits initialized to unknown.
 
unsigned getBitWidth () const
 Get the bit width of this value.
 
bool hasConflict () const
 Returns true if there is conflicting information.
 
bool isConstant () const
 Returns true if we know the value of all bits.
 
const APIntgetConstant () const
 Returns the value when all bits have a known value.
 
bool isUnknown () const
 Returns true if we don't know any bits.
 
void resetAll ()
 Resets the known state of all bits.
 
bool isZero () const
 Returns true if value is all zero.
 
bool isAllOnes () const
 Returns true if value is all one bits.
 
void setAllZero ()
 Make all bits known to be zero and discard any previous information.
 
void setAllOnes ()
 Make all bits known to be one and discard any previous information.
 
bool isNegative () const
 Returns true if this value is known to be negative.
 
bool isNonNegative () const
 Returns true if this value is known to be non-negative.
 
bool isNonZero () const
 Returns true if this value is known to be non-zero.
 
bool isStrictlyPositive () const
 Returns true if this value is known to be positive.
 
void makeNegative ()
 Make this value negative.
 
void makeNonNegative ()
 Make this value non-negative.
 
APInt getMinValue () const
 Return the minimal unsigned value possible given these KnownBits.
 
APInt getSignedMinValue () const
 Return the minimal signed value possible given these KnownBits.
 
APInt getMaxValue () const
 Return the maximal unsigned value possible given these KnownBits.
 
APInt getSignedMaxValue () const
 Return the maximal signed value possible given these KnownBits.
 
KnownBits trunc (unsigned BitWidth) const
 Return known bits for a truncation of the value we're tracking.
 
KnownBits anyext (unsigned BitWidth) const
 Return known bits for an "any" extension of the value we're tracking, where we don't know anything about the extended bits.
 
KnownBits zext (unsigned BitWidth) const
 Return known bits for a zero extension of the value we're tracking.
 
KnownBits sext (unsigned BitWidth) const
 Return known bits for a sign extension of the value we're tracking.
 
KnownBits anyextOrTrunc (unsigned BitWidth) const
 Return known bits for an "any" extension or truncation of the value we're tracking.
 
KnownBits zextOrTrunc (unsigned BitWidth) const
 Return known bits for a zero extension or truncation of the value we're tracking.
 
KnownBits sextOrTrunc (unsigned BitWidth) const
 Return known bits for a sign extension or truncation of the value we're tracking.
 
KnownBits sextInReg (unsigned SrcBitWidth) const
 Return known bits for a in-register sign extension of the value we're tracking.
 
void insertBits (const KnownBits &SubBits, unsigned BitPosition)
 Insert the bits from a smaller known bits starting at bitPosition.
 
KnownBits extractBits (unsigned NumBits, unsigned BitPosition) const
 Return a subset of the known bits from [bitPosition,bitPosition+numBits).
 
KnownBits concat (const KnownBits &Lo) const
 Concatenate the bits from Lo onto the bottom of *this.
 
KnownBits makeGE (const APInt &Val) const
 Return KnownBits based on this, but updated given that the underlying value is known to be greater than or equal to Val.
 
unsigned countMinTrailingZeros () const
 Returns the minimum number of trailing zero bits.
 
unsigned countMinTrailingOnes () const
 Returns the minimum number of trailing one bits.
 
unsigned countMinLeadingZeros () const
 Returns the minimum number of leading zero bits.
 
unsigned countMinLeadingOnes () const
 Returns the minimum number of leading one bits.
 
unsigned countMinSignBits () const
 Returns the number of times the sign bit is replicated into the other bits.
 
unsigned countMaxSignificantBits () const
 Returns the maximum number of bits needed to represent all possible signed values with these known bits.
 
unsigned countMaxTrailingZeros () const
 Returns the maximum number of trailing zero bits possible.
 
unsigned countMaxTrailingOnes () const
 Returns the maximum number of trailing one bits possible.
 
unsigned countMaxLeadingZeros () const
 Returns the maximum number of leading zero bits possible.
 
unsigned countMaxLeadingOnes () const
 Returns the maximum number of leading one bits possible.
 
unsigned countMinPopulation () const
 Returns the number of bits known to be one.
 
unsigned countMaxPopulation () const
 Returns the maximum number of bits that could be one.
 
unsigned countMaxActiveBits () const
 Returns the maximum number of bits needed to represent all possible unsigned values with these known bits.
 
KnownBits intersectWith (const KnownBits &RHS) const
 Returns KnownBits information that is known to be true for both this and RHS.
 
KnownBits unionWith (const KnownBits &RHS) const
 Returns KnownBits information that is known to be true for either this or RHS or both.
 
KnownBitsoperator&= (const KnownBits &RHS)
 Update known bits based on ANDing with RHS.
 
KnownBitsoperator|= (const KnownBits &RHS)
 Update known bits based on ORing with RHS.
 
KnownBitsoperator^= (const KnownBits &RHS)
 Update known bits based on XORing with RHS.
 
KnownBits abs (bool IntMinIsPoison=false) const
 Compute known bits for the absolute value.
 
KnownBits byteSwap () const
 
KnownBits reverseBits () const
 
KnownBits blsi () const
 Compute known bits for X & -X, which has only the lowest bit set of X set.
 
KnownBits blsmsk () const
 Compute known bits for X ^ (X - 1), which has all bits up to and including the lowest set bit of X set.
 
bool operator== (const KnownBits &Other) const
 
bool operator!= (const KnownBits &Other) const
 
void print (raw_ostream &OS) const
 
void dump () const
 

Static Public Member Functions

static KnownBits makeConstant (const APInt &C)
 Create known bits from a known constant.
 
static KnownBits commonBits (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits common to LHS and RHS.
 
static bool haveNoCommonBitsSet (const KnownBits &LHS, const KnownBits &RHS)
 Return true if LHS and RHS have no common bits set.
 
static KnownBits computeForAddCarry (const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry)
 Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
 
static KnownBits computeForAddSub (bool Add, bool NSW, const KnownBits &LHS, KnownBits RHS)
 Compute known bits resulting from adding LHS and RHS.
 
static KnownBits computeForSubBorrow (const KnownBits &LHS, KnownBits RHS, const KnownBits &Borrow)
 Compute known bits results from subtracting RHS from LHS with 1-bit Borrow.
 
static KnownBits sadd_sat (const KnownBits &LHS, const KnownBits &RHS)
 Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
 
static KnownBits uadd_sat (const KnownBits &LHS, const KnownBits &RHS)
 Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
 
static KnownBits ssub_sat (const KnownBits &LHS, const KnownBits &RHS)
 Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
 
static KnownBits usub_sat (const KnownBits &LHS, const KnownBits &RHS)
 Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
 
static KnownBits mul (const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
 Compute known bits resulting from multiplying LHS and RHS.
 
static KnownBits mulhs (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits from sign-extended multiply-hi.
 
static KnownBits mulhu (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits from zero-extended multiply-hi.
 
static KnownBits sdiv (const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
 Compute known bits for sdiv(LHS, RHS).
 
static KnownBits udiv (const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
 Compute known bits for udiv(LHS, RHS).
 
static KnownBits urem (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits for urem(LHS, RHS).
 
static KnownBits srem (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits for srem(LHS, RHS).
 
static KnownBits umax (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits for umax(LHS, RHS).
 
static KnownBits umin (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits for umin(LHS, RHS).
 
static KnownBits smax (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits for smax(LHS, RHS).
 
static KnownBits smin (const KnownBits &LHS, const KnownBits &RHS)
 Compute known bits for smin(LHS, RHS).
 
static KnownBits shl (const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
 Compute known bits for shl(LHS, RHS).
 
static KnownBits lshr (const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false)
 Compute known bits for lshr(LHS, RHS).
 
static KnownBits ashr (const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false)
 Compute known bits for ashr(LHS, RHS).
 
static std::optional< booleq (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_EQ result.
 
static std::optional< boolne (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_NE result.
 
static std::optional< boolugt (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_UGT result.
 
static std::optional< booluge (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_UGE result.
 
static std::optional< boolult (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_ULT result.
 
static std::optional< boolule (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_ULE result.
 
static std::optional< boolsgt (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_SGT result.
 
static std::optional< boolsge (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_SGE result.
 
static std::optional< boolslt (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_SLT result.
 
static std::optional< boolsle (const KnownBits &LHS, const KnownBits &RHS)
 Determine if these known bits always give the same ICMP_SLE result.
 

Public Attributes

APInt Zero
 
APInt One
 

Detailed Description

Definition at line 23 of file KnownBits.h.

Constructor & Destructor Documentation

◆ KnownBits() [1/2]

llvm::KnownBits::KnownBits ( )
default

◆ KnownBits() [2/2]

llvm::KnownBits::KnownBits ( unsigned  BitWidth)
inline

Create a known bits object of BitWidth bits initialized to unknown.

Definition at line 37 of file KnownBits.h.

Member Function Documentation

◆ abs()

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

◆ anyext()

KnownBits llvm::KnownBits::anyext ( unsigned  BitWidth) const
inline

Return known bits for an "any" extension of the value we're tracking, where we don't know anything about the extended bits.

Definition at line 158 of file KnownBits.h.

References llvm::BitWidth, KnownBits(), One, Zero, and llvm::APInt::zext().

Referenced by anyextOrTrunc(), llvm::SelectionDAG::computeKnownBits(), llvm::GISelKnownBits::computeKnownBitsImpl(), llvm::FunctionLoweringInfo::GetLiveOutRegInfo(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ anyextOrTrunc()

KnownBits llvm::KnownBits::anyextOrTrunc ( unsigned  BitWidth) const
inline

◆ ashr()

KnownBits KnownBits::ashr ( const KnownBits LHS,
const KnownBits RHS,
bool  ShAmtNonZero = false 
)
static

◆ blsi()

KnownBits KnownBits::blsi ( ) const

Compute known bits for X & -X, which has only the lowest bit set of X set.

The name comes from the X86 BMI instruction

Definition at line 971 of file KnownBits.cpp.

References llvm::BitWidth, countMaxTrailingZeros(), countMinTrailingZeros(), getBitWidth(), One, llvm::APInt::setBit(), llvm::APInt::setBitsFrom(), and Zero.

Referenced by getKnownBitsFromAndXorOr().

◆ blsmsk()

KnownBits KnownBits::blsmsk ( ) const

Compute known bits for X ^ (X - 1), which has all bits up to and including the lowest set bit of X set.

The name comes from the X86 BMI instruction.

Definition at line 982 of file KnownBits.cpp.

References llvm::BitWidth, countMaxTrailingZeros(), countMinTrailingZeros(), getBitWidth(), One, llvm::APInt::setBitsFrom(), llvm::APInt::setLowBits(), and Zero.

Referenced by getKnownBitsFromAndXorOr().

◆ byteSwap()

KnownBits llvm::KnownBits::byteSwap ( ) const
inline

◆ commonBits()

static KnownBits llvm::KnownBits::commonBits ( const KnownBits LHS,
const KnownBits RHS 
)
inlinestatic

Compute known bits common to LHS and RHS.

Definition at line 318 of file KnownBits.h.

References LHS, and RHS.

◆ computeForAddCarry()

KnownBits KnownBits::computeForAddCarry ( const KnownBits LHS,
const KnownBits RHS,
const KnownBits Carry 
)
static

Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.

Definition at line 50 of file KnownBits.cpp.

References assert(), getBitWidth(), llvm::APInt::getBoolValue(), LHS, One, RHS, and Zero.

Referenced by computeForAddSub(), and llvm::SelectionDAG::computeKnownBits().

◆ computeForAddSub()

KnownBits KnownBits::computeForAddSub ( bool  Add,
bool  NSW,
const KnownBits LHS,
KnownBits  RHS 
)
static

◆ computeForSubBorrow()

KnownBits KnownBits::computeForSubBorrow ( const KnownBits LHS,
KnownBits  RHS,
const KnownBits Borrow 
)
static

Compute known bits results from subtracting RHS from LHS with 1-bit Borrow.

Definition at line 88 of file KnownBits.cpp.

References assert(), getBitWidth(), llvm::APInt::getBoolValue(), LHS, One, RHS, std::swap(), and Zero.

Referenced by llvm::SelectionDAG::computeKnownBits().

◆ concat()

KnownBits llvm::KnownBits::concat ( const KnownBits Lo) const
inline

Concatenate the bits from Lo onto the bottom of *this.

This is equivalent to: (this->zext(NewWidth) << Lo.getBitWidth()) | Lo.zext(NewWidth)

Definition at line 224 of file KnownBits.h.

References llvm::APInt::concat(), KnownBits(), llvm::Lo, One, and Zero.

Referenced by llvm::SelectionDAG::computeKnownBits(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ countMaxActiveBits()

unsigned llvm::KnownBits::countMaxActiveBits ( ) const
inline

Returns the maximum number of bits needed to represent all possible unsigned values with these known bits.

This is the inverse of the minimum number of leading zeros.

Definition at line 287 of file KnownBits.h.

References countMinLeadingZeros(), and getBitWidth().

Referenced by combinePMULH(), llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode(), llvm::SITargetLowering::computeKnownBitsForTargetNode(), detectAVGPattern(), detectExtMul(), llvm::InstCombinerImpl::foldICmpTruncWithTruncOrExt(), getPack(), narrowIndex(), llvm::AMDGPUTargetLowering::numBitsUnsigned(), simplifyAndInst(), and simplifyLShrInst().

◆ countMaxLeadingOnes()

unsigned llvm::KnownBits::countMaxLeadingOnes ( ) const
inline

Returns the maximum number of leading one bits possible.

Definition at line 274 of file KnownBits.h.

References llvm::APInt::countl_zero(), and Zero.

◆ countMaxLeadingZeros()

unsigned llvm::KnownBits::countMaxLeadingZeros ( ) const
inline

Returns the maximum number of leading zero bits possible.

Definition at line 271 of file KnownBits.h.

References llvm::APInt::countl_zero(), and One.

Referenced by llvm::SelectionDAG::computeKnownBits(), llvm::RISCVTargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromOperator(), and foldCttzCtlz().

◆ countMaxPopulation()

unsigned llvm::KnownBits::countMaxPopulation ( ) const
inline

◆ countMaxSignificantBits()

unsigned llvm::KnownBits::countMaxSignificantBits ( ) const
inline

Returns the maximum number of bits needed to represent all possible signed values with these known bits.

This is the inverse of the minimum number of known sign bits. Examples for bitwidth 5: 110?? --> 4 0000? --> 2

Definition at line 260 of file KnownBits.h.

References countMinSignBits(), and getBitWidth().

Referenced by llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode().

◆ countMaxTrailingOnes()

unsigned llvm::KnownBits::countMaxTrailingOnes ( ) const
inline

Returns the maximum number of trailing one bits possible.

Definition at line 268 of file KnownBits.h.

References llvm::APInt::countr_zero(), and Zero.

◆ countMaxTrailingZeros()

unsigned llvm::KnownBits::countMaxTrailingZeros ( ) const
inline

◆ countMinLeadingOnes()

unsigned llvm::KnownBits::countMinLeadingOnes ( ) const
inline

Returns the minimum number of leading one bits.

Definition at line 242 of file KnownBits.h.

References llvm::APInt::countl_one(), and One.

Referenced by computeKnownBitsFromOperator(), countMinSignBits(), llvm::GCNTTIImpl::rewriteIntrinsicWithAddressSpace(), and llvm::InstCombinerImpl::visitSwitchInst().

◆ countMinLeadingZeros()

unsigned llvm::KnownBits::countMinLeadingZeros ( ) const
inline

◆ countMinPopulation()

unsigned llvm::KnownBits::countMinPopulation ( ) const
inline

Returns the number of bits known to be one.

Definition at line 277 of file KnownBits.h.

References One, and llvm::APInt::popcount().

Referenced by abs(), foldCtpop(), foldCtpopPow2Test(), llvm::InstCombinerImpl::foldICmpWithZero(), llvm::isKnownToBeAPowerOfTwo(), and llvm::TargetLowering::SimplifySetCC().

◆ countMinSignBits()

unsigned llvm::KnownBits::countMinSignBits ( ) const
inline

Returns the number of times the sign bit is replicated into the other bits.

Definition at line 246 of file KnownBits.h.

References countMinLeadingOnes(), countMinLeadingZeros(), isNegative(), and isNonNegative().

Referenced by llvm::SelectionDAG::ComputeNumSignBits(), ComputeNumSignBitsImpl(), countMaxSignificantBits(), setShiftFlags(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ countMinTrailingOnes()

unsigned llvm::KnownBits::countMinTrailingOnes ( ) const
inline

Returns the minimum number of trailing one bits.

Definition at line 236 of file KnownBits.h.

References llvm::APInt::countr_one(), and One.

Referenced by getKnownBitsFromAndXorOr().

◆ countMinTrailingZeros()

unsigned llvm::KnownBits::countMinTrailingZeros ( ) const
inline

◆ dump()

void KnownBits::dump ( ) const

Definition at line 1006 of file KnownBits.cpp.

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

◆ eq()

std::optional< bool > KnownBits::eq ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_EQ result.

Definition at line 365 of file KnownBits.cpp.

References LHS, and RHS.

Referenced by llvm::X86TargetLowering::computeKnownBitsForTargetNode(), llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), and ne().

◆ extractBits()

KnownBits llvm::KnownBits::extractBits ( unsigned  NumBits,
unsigned  BitPosition 
) const
inline

◆ getBitWidth()

unsigned llvm::KnownBits::getBitWidth ( ) const
inline

Get the bit width of this value.

Definition at line 40 of file KnownBits.h.

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

Referenced by abs(), anyextOrTrunc(), blsi(), blsmsk(), combineFMulcFCMulc(), computeForAddCarry(), computeForSatAddSub(), computeForSubBorrow(), computeKnownBits(), llvm::SelectionDAG::computeKnownBits(), llvm::ARMTargetLowering::computeKnownBitsForTargetNode(), llvm::RISCVTargetLowering::computeKnownBitsForTargetNode(), llvm::AArch64TargetLowering::computeKnownBitsForTargetNode(), llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode(), llvm::LanaiTargetLowering::computeKnownBitsForTargetNode(), llvm::SystemZTargetLowering::computeKnownBitsForTargetNode(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromCmp(), llvm::computeKnownBitsFromContext(), computeKnownBitsFromOperator(), llvm::computeKnownBitsFromRangeMetadata(), computeKnownBitsFromShiftOperator(), llvm::GISelKnownBits::computeKnownBitsImpl(), countMaxActiveBits(), countMaxPopulation(), countMaxSignificantBits(), eliminateDeadSwitchCases(), foldShiftIntoShiftInAnotherHandOfAndInICmp(), llvm::ConstantRange::fromKnownBits(), getKnownBitsFromAndXorOr(), llvm::FunctionLoweringInfo::GetLiveOutRegInfo(), llvm::getOrEnforceKnownAlignment(), inferAlignment(), isConstant(), llvm::SelectionDAG::isKnownNeverZero(), isNonZeroShift(), LowerCTPOP(), makeGE(), print(), setShiftFlags(), sextInReg(), sextOrTrunc(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), simplifyDivRem(), simplifyShift(), smax(), smin(), tryBitfieldInsertOpFromOr(), llvm::InstCombinerImpl::visitCallInst(), llvm::InstCombinerImpl::visitSwitchInst(), zext(), and zextOrTrunc().

◆ getConstant()

const APInt & llvm::KnownBits::getConstant ( ) const
inline

Returns the value when all bits have a known value.

This just returns One with a protective assertion.

Definition at line 57 of file KnownBits.h.

References assert(), isConstant(), and One.

Referenced by combineFMulcFCMulc(), computeKnownBitsFromOperator(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), LowerVectorAllEqual(), and llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode().

◆ getMaxValue()

APInt llvm::KnownBits::getMaxValue ( ) const
inline

◆ getMinValue()

APInt llvm::KnownBits::getMinValue ( ) const
inline

Return the minimal unsigned value possible given these KnownBits.

Definition at line 120 of file KnownBits.h.

References One.

Referenced by extractBits(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), llvm::ConstantRange::fromKnownBits(), simplifyShift(), and simplifyX86immShift().

◆ getSignedMaxValue()

APInt llvm::KnownBits::getSignedMaxValue ( ) const
inline

Return the maximal signed value possible given these KnownBits.

Definition at line 142 of file KnownBits.h.

References llvm::APInt::isSignBitClear(), and One.

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

◆ getSignedMinValue()

APInt llvm::KnownBits::getSignedMinValue ( ) const
inline

Return the minimal signed value possible given these KnownBits.

Definition at line 126 of file KnownBits.h.

References llvm::APInt::isSignBitClear(), One, llvm::APInt::setSignBit(), and Zero.

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

◆ hasConflict()

bool llvm::KnownBits::hasConflict ( ) const
inline

◆ haveNoCommonBitsSet()

static bool llvm::KnownBits::haveNoCommonBitsSet ( const KnownBits LHS,
const KnownBits RHS 
)
inlinestatic

Return true if LHS and RHS have no common bits set.

Definition at line 323 of file KnownBits.h.

References LHS, and RHS.

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

◆ insertBits()

void llvm::KnownBits::insertBits ( const KnownBits SubBits,
unsigned  BitPosition 
)
inline

Insert the bits from a smaller known bits starting at bitPosition.

Definition at line 210 of file KnownBits.h.

References llvm::APInt::insertBits(), One, and Zero.

Referenced by llvm::SelectionDAG::computeKnownBits(), computeKnownBitsFromOperator(), and llvm::GISelKnownBits::computeKnownBitsImpl().

◆ intersectWith()

KnownBits llvm::KnownBits::intersectWith ( const KnownBits RHS) const
inline

◆ isAllOnes()

bool llvm::KnownBits::isAllOnes ( ) const
inline

Returns true if value is all one bits.

Definition at line 78 of file KnownBits.h.

References assert(), hasConflict(), llvm::APInt::isAllOnes(), and One.

Referenced by isTruncateOf(), matchBinaryShuffle(), and llvm::InstCombinerImpl::visitCallInst().

◆ isConstant()

bool llvm::KnownBits::isConstant ( ) const
inline

◆ isNegative()

bool llvm::KnownBits::isNegative ( ) const
inline

◆ isNonNegative()

bool llvm::KnownBits::isNonNegative ( ) const
inline

◆ isNonZero()

bool llvm::KnownBits::isNonZero ( ) const
inline

◆ isStrictlyPositive()

bool llvm::KnownBits::isStrictlyPositive ( ) const
inline

Returns true if this value is known to be positive.

Definition at line 105 of file KnownBits.h.

References llvm::APInt::isSignBitSet(), llvm::APInt::isZero(), One, and Zero.

Referenced by llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode().

◆ isUnknown()

bool llvm::KnownBits::isUnknown ( ) const
inline

◆ isZero()

bool llvm::KnownBits::isZero ( ) const
inline

◆ lshr()

KnownBits KnownBits::lshr ( const KnownBits LHS,
const KnownBits RHS,
bool  ShAmtNonZero = false 
)
static

◆ makeConstant()

static KnownBits llvm::KnownBits::makeConstant ( const APInt C)
inlinestatic

◆ makeGE()

KnownBits KnownBits::makeGE ( const APInt Val) const

Return KnownBits based on this, but updated given that the underlying value is known to be greater than or equal to Val.

Definition at line 117 of file KnownBits.cpp.

References llvm::APInt::clearLowBits(), llvm::countl_one(), getBitWidth(), KnownBits(), N, One, and Zero.

◆ makeNegative()

void llvm::KnownBits::makeNegative ( )
inline

Make this value negative.

Definition at line 110 of file KnownBits.h.

References One, and llvm::APInt::setSignBit().

Referenced by computeForAddSub(), computeKnownBitsFromCmp(), computeKnownBitsFromOperator(), computeKnownBitsMul(), and shl().

◆ makeNonNegative()

void llvm::KnownBits::makeNonNegative ( )
inline

◆ mul()

KnownBits KnownBits::mul ( const KnownBits LHS,
const KnownBits RHS,
bool  NoUndefSelfMultiply = false 
)
static

◆ mulhs()

KnownBits KnownBits::mulhs ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute known bits from sign-extended multiply-hi.

Definition at line 745 of file KnownBits.cpp.

References assert(), llvm::BitWidth, extractBits(), LHS, mul(), and RHS.

Referenced by llvm::SelectionDAG::computeKnownBits().

◆ mulhu()

KnownBits KnownBits::mulhu ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute known bits from zero-extended multiply-hi.

Definition at line 754 of file KnownBits.cpp.

References assert(), llvm::BitWidth, extractBits(), LHS, mul(), and RHS.

Referenced by llvm::SelectionDAG::computeKnownBits().

◆ ne()

std::optional< bool > KnownBits::ne ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_NE result.

Definition at line 373 of file KnownBits.cpp.

References eq(), LHS, and RHS.

Referenced by llvm::SelectionDAG::isKnownNeverZero(), and llvm::CombinerHelper::matchICmpToTrueFalseKnownBits().

◆ operator!=()

bool llvm::KnownBits::operator!= ( const KnownBits Other) const
inline

Definition at line 466 of file KnownBits.h.

References llvm::Other.

◆ operator&=()

KnownBits & KnownBits::operator&= ( const KnownBits RHS)

Update known bits based on ANDing with RHS.

Definition at line 946 of file KnownBits.cpp.

References One, RHS, and Zero.

◆ operator==()

bool llvm::KnownBits::operator== ( const KnownBits Other) const
inline

Definition at line 462 of file KnownBits.h.

References One, llvm::Other, and Zero.

◆ operator^=()

KnownBits & KnownBits::operator^= ( const KnownBits RHS)

Update known bits based on XORing with RHS.

Definition at line 962 of file KnownBits.cpp.

References One, RHS, and Zero.

◆ operator|=()

KnownBits & KnownBits::operator|= ( const KnownBits RHS)

Update known bits based on ORing with RHS.

Definition at line 954 of file KnownBits.cpp.

References One, RHS, and Zero.

◆ print()

void KnownBits::print ( raw_ostream OS) const

Definition at line 992 of file KnownBits.cpp.

References llvm::BitWidth, getBitWidth(), I, N, One, OS, and Zero.

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

◆ resetAll()

void llvm::KnownBits::resetAll ( )
inline

◆ reverseBits()

KnownBits llvm::KnownBits::reverseBits ( ) const
inline

◆ sadd_sat()

KnownBits KnownBits::sadd_sat ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)

Definition at line 634 of file KnownBits.cpp.

References computeForSatAddSub(), LHS, and RHS.

Referenced by computeKnownBitsFromOperator().

◆ sdiv()

KnownBits KnownBits::sdiv ( const KnownBits LHS,
const KnownBits RHS,
bool  Exact = false 
)
static

◆ setAllOnes()

void llvm::KnownBits::setAllOnes ( )
inline

Make all bits known to be one and discard any previous information.

Definition at line 90 of file KnownBits.h.

References llvm::APInt::clearAllBits(), One, llvm::APInt::setAllBits(), and Zero.

Referenced by llvm::X86TargetLowering::computeKnownBitsForTargetNode(), and llvm::computeKnownBitsFromContext().

◆ setAllZero()

void llvm::KnownBits::setAllZero ( )
inline

◆ sext()

KnownBits llvm::KnownBits::sext ( unsigned  BitWidth) const
inline

◆ sextInReg()

KnownBits KnownBits::sextInReg ( unsigned  SrcBitWidth) const

Return known bits for a in-register sign extension of the value we're tracking.

Definition at line 100 of file KnownBits.cpp.

References assert(), llvm::BitWidth, getBitWidth(), One, and Zero.

Referenced by llvm::SelectionDAG::computeKnownBits(), and llvm::GISelKnownBits::computeKnownBitsImpl().

◆ sextOrTrunc()

KnownBits llvm::KnownBits::sextOrTrunc ( unsigned  BitWidth) const
inline

Return known bits for a sign extension or truncation of the value we're tracking.

Definition at line 197 of file KnownBits.h.

References llvm::BitWidth, getBitWidth(), sext(), and trunc().

Referenced by computeKnownBitsFromOperator().

◆ sge()

std::optional< bool > KnownBits::sge ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_SGE result.

Definition at line 413 of file KnownBits.cpp.

References LHS, RHS, and sgt().

Referenced by llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), llvm::TargetLowering::SimplifyDemandedBits(), and sle().

◆ sgt()

std::optional< bool > KnownBits::sgt ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_SGT result.

Definition at line 403 of file KnownBits.cpp.

References LHS, and RHS.

Referenced by llvm::X86TargetLowering::computeKnownBitsForTargetNode(), llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), sge(), llvm::TargetLowering::SimplifyDemandedBits(), and slt().

◆ shl()

KnownBits KnownBits::shl ( const KnownBits LHS,
const KnownBits RHS,
bool  NUW = false,
bool  NSW = false,
bool  ShAmtNonZero = false 
)
static

◆ sle()

std::optional< bool > KnownBits::sle ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_SLE result.

Definition at line 423 of file KnownBits.cpp.

References LHS, RHS, and sge().

Referenced by llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ slt()

std::optional< bool > KnownBits::slt ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_SLT result.

Definition at line 419 of file KnownBits.cpp.

References LHS, RHS, and sgt().

Referenced by llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ smax()

KnownBits KnownBits::smax ( const KnownBits LHS,
const KnownBits RHS 
)
static

◆ smin()

KnownBits KnownBits::smin ( const KnownBits LHS,
const KnownBits RHS 
)
static

◆ srem()

KnownBits KnownBits::srem ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute known bits for srem(LHS, RHS).

Definition at line 919 of file KnownBits.cpp.

References assert(), llvm::APInt::intersects(), llvm::APInt::isSubsetOf(), LHS, One, RHS, llvm::APInt::setHighBits(), and Zero.

Referenced by llvm::SelectionDAG::computeKnownBits(), and computeKnownBitsFromOperator().

◆ ssub_sat()

KnownBits KnownBits::ssub_sat ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)

Definition at line 637 of file KnownBits.cpp.

References computeForSatAddSub(), LHS, and RHS.

Referenced by computeKnownBitsFromOperator().

◆ trunc()

KnownBits llvm::KnownBits::trunc ( unsigned  BitWidth) const
inline

◆ uadd_sat()

KnownBits KnownBits::uadd_sat ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)

Definition at line 640 of file KnownBits.cpp.

References computeForSatAddSub(), LHS, and RHS.

Referenced by computeKnownBitsFromOperator().

◆ udiv()

KnownBits KnownBits::udiv ( const KnownBits LHS,
const KnownBits RHS,
bool  Exact = false 
)
static

◆ uge()

std::optional< bool > KnownBits::uge ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_UGE result.

Definition at line 389 of file KnownBits.cpp.

References LHS, RHS, and ugt().

Referenced by isKnownNonZeroFromOperator(), llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), llvm::TargetLowering::SimplifyDemandedBits(), and ule().

◆ ugt()

std::optional< bool > KnownBits::ugt ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_UGT result.

Definition at line 379 of file KnownBits.cpp.

References LHS, and RHS.

Referenced by llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), llvm::TargetLowering::SimplifyDemandedBits(), uge(), and ult().

◆ ule()

std::optional< bool > KnownBits::ule ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_ULE result.

Definition at line 399 of file KnownBits.cpp.

References LHS, RHS, and uge().

Referenced by llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ ult()

std::optional< bool > KnownBits::ult ( const KnownBits LHS,
const KnownBits RHS 
)
static

Determine if these known bits always give the same ICMP_ULT result.

Definition at line 395 of file KnownBits.cpp.

References LHS, RHS, and ugt().

Referenced by llvm::CombinerHelper::matchICmpToTrueFalseKnownBits(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ umax()

KnownBits KnownBits::umax ( const KnownBits LHS,
const KnownBits RHS 
)
static

◆ umin()

KnownBits KnownBits::umin ( const KnownBits LHS,
const KnownBits RHS 
)
static

◆ unionWith()

KnownBits llvm::KnownBits::unionWith ( const KnownBits RHS) const
inline

Returns KnownBits information that is known to be true for either this or RHS or both.

This can be used to combine different sources of information about the known bits of a single value, e.g. information about the low bits and the high bits of the result of a multiplication.

Definition at line 312 of file KnownBits.h.

References KnownBits(), One, RHS, and Zero.

Referenced by llvm::SelectionDAG::computeKnownBits(), computeKnownBitsFromCmp(), computeKnownBitsFromOperator(), and llvm::TargetLowering::SimplifyDemandedBits().

◆ urem()

KnownBits KnownBits::urem ( const KnownBits LHS,
const KnownBits RHS 
)
static

◆ usub_sat()

KnownBits KnownBits::usub_sat ( const KnownBits LHS,
const KnownBits RHS 
)
static

Compute knownbits resulting from llvm.usub.sat(LHS, RHS)

Definition at line 643 of file KnownBits.cpp.

References computeForSatAddSub(), LHS, and RHS.

Referenced by llvm::SelectionDAG::computeKnownBits(), and computeKnownBitsFromOperator().

◆ zext()

KnownBits llvm::KnownBits::zext ( unsigned  BitWidth) const
inline

◆ zextOrTrunc()

KnownBits llvm::KnownBits::zextOrTrunc ( unsigned  BitWidth) const
inline

Member Data Documentation

◆ One

APInt llvm::KnownBits::One

Definition at line 25 of file KnownBits.h.

Referenced by abs(), llvm::FunctionLoweringInfo::AddLiveOutRegInfo(), anyext(), ashr(), llvm::ConstantRange::binaryXor(), blsi(), blsmsk(), byteSwap(), llvm::SelectionDAGISel::CheckOrMask(), combineSetCC(), computeForAddCarry(), computeForAddCarry(), computeForSatAddSub(), computeForSubBorrow(), computeKnownBits(), llvm::SelectionDAG::computeKnownBits(), llvm::SITargetLowering::computeKnownBitsForTargetInstr(), llvm::ARMTargetLowering::computeKnownBitsForTargetNode(), llvm::RISCVTargetLowering::computeKnownBitsForTargetNode(), llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromCmp(), computeKnownBitsFromOperator(), llvm::computeKnownBitsFromRangeMetadata(), llvm::GISelKnownBits::computeKnownBitsImpl(), llvm::GISelKnownBits::computeNumSignBits(), llvm::FunctionLoweringInfo::ComputePHILiveOutRegInfo(), concat(), countMaxLeadingZeros(), countMaxTrailingZeros(), countMinLeadingOnes(), countMinPopulation(), countMinTrailingOnes(), llvm::DemandedBits::determineLiveOperandBitsSub(), divComputeLowBit(), dumpResult(), eliminateDeadSwitchCases(), extractBits(), foldCtpopPow2Test(), foldCttzCtlz(), llvm::InstCombinerImpl::foldICmpBinOp(), llvm::InstCombinerImpl::foldICmpTruncConstant(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), llvm::InstCombinerImpl::foldICmpWithZero(), getBitWidth(), getConstant(), getKnownBitsFromAndXorOr(), llvm::GISelKnownBits::getKnownOnes(), getMinValue(), getSignedMaxValue(), getSignedMinValue(), hasConflict(), insertBits(), intersectWith(), isAllOnes(), isConstant(), llvm::SelectionDAG::isKnownNeverZero(), isKnownNonEqual(), isKnownNonZeroFromOperator(), isKnownToBeAPowerOfTwo(), isNegative(), isNonZero(), isNonZeroAdd(), isNonZeroShift(), isStrictlyPositive(), isUnknown(), lshr(), makeGE(), makeNegative(), matchBinaryShuffle(), llvm::CombinerHelper::matchRedundantAnd(), llvm::CombinerHelper::matchRedundantOr(), mul(), operator&=(), operator==(), operator^=(), operator|=(), print(), resetAll(), reverseBits(), sdiv(), setAllOnes(), setAllZero(), sext(), sextInReg(), shl(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::InstCombinerImpl::SimplifyMultipleUseDemandedBits(), llvm::TargetLowering::SimplifyMultipleUseDemandedBits(), simplifyRightShift(), simplifyShift(), llvm::InstCombinerImpl::simplifyShrShlDemandedBits(), smax(), smin(), srem(), llvm::ConstantRange::toKnownBits(), trunc(), unionWith(), llvm::InstCombinerImpl::visitOr(), and zext().

◆ Zero

APInt llvm::KnownBits::Zero

Definition at line 24 of file KnownBits.h.

Referenced by abs(), llvm::FunctionLoweringInfo::AddLiveOutRegInfo(), adjustForRedundantAnd(), anyext(), ashr(), llvm::ConstantRange::binaryXor(), blsi(), blsmsk(), byteSwap(), combineSetCC(), computeForAddCarry(), computeForAddCarry(), computeForSatAddSub(), computeForSubBorrow(), computeKnownBits(), llvm::SelectionDAG::computeKnownBits(), llvm::GISelKnownBits::computeKnownBitsForAlignment(), llvm::TargetLowering::computeKnownBitsForFrameIndex(), llvm::SITargetLowering::computeKnownBitsForFrameIndex(), llvm::SITargetLowering::computeKnownBitsForTargetInstr(), llvm::ARMTargetLowering::computeKnownBitsForTargetNode(), llvm::RISCVTargetLowering::computeKnownBitsForTargetNode(), llvm::AArch64TargetLowering::computeKnownBitsForTargetNode(), llvm::AMDGPUTargetLowering::computeKnownBitsForTargetNode(), llvm::SITargetLowering::computeKnownBitsForTargetNode(), llvm::LanaiTargetLowering::computeKnownBitsForTargetNode(), llvm::PPCTargetLowering::computeKnownBitsForTargetNode(), llvm::SystemZTargetLowering::computeKnownBitsForTargetNode(), llvm::X86TargetLowering::computeKnownBitsForTargetNode(), computeKnownBitsFromCmp(), llvm::computeKnownBitsFromContext(), computeKnownBitsFromOperator(), llvm::computeKnownBitsFromRangeMetadata(), llvm::GISelKnownBits::computeKnownBitsImpl(), computeKnownFPClass(), llvm::GISelKnownBits::computeNumSignBits(), llvm::SelectionDAG::ComputeNumSignBits(), ComputeNumSignBitsImpl(), llvm::FunctionLoweringInfo::ComputePHILiveOutRegInfo(), concat(), countMaxLeadingOnes(), countMaxPopulation(), countMaxTrailingOnes(), countMinLeadingZeros(), countMinTrailingZeros(), llvm::DemandedBits::determineLiveOperandBitsSub(), divComputeLowBit(), dumpResult(), eliminateDeadSwitchCases(), extractBits(), llvm::InstCombinerImpl::foldAddWithConstant(), foldCtpop(), llvm::InstCombinerImpl::foldICmpTruncConstant(), llvm::InstCombinerImpl::foldICmpUsingKnownBits(), getBitWidth(), getKnownBitsFromAndXorOr(), llvm::GISelKnownBits::getKnownZeroes(), getSignedMinValue(), hasConflict(), insertBits(), intersectWith(), isConstant(), isKnownNonEqual(), isKnownToBeAPowerOfTwo(), isNonNegative(), isNonZeroShift(), isStrictlyPositive(), isTruePredicate(), isTruncateOf(), isUnknown(), isZero(), knownBitsForWorkitemID(), LowerMUL(), lshr(), makeGE(), makeNonNegative(), llvm::MaskedValueIsZero(), matchBinaryShuffle(), llvm::CombinerHelper::matchRedundantAnd(), llvm::CombinerHelper::matchRedundantOr(), mul(), operator&=(), operator==(), operator^=(), operator|=(), performANDCombine(), llvm::ARMTargetLowering::PerformCMOVCombine(), llvm::ARMTargetLowering::PerformCMOVToBFICombine(), performORCombine(), print(), provablyDisjointOr(), resetAll(), reverseBits(), sdiv(), llvm::PPCTargetLowering::SelectAddressRegImm(), llvm::PPCTargetLowering::SelectAddressRegImm34(), llvm::PPCTargetLowering::SelectAddressRegReg(), llvm::LoongArchDAGToDAGISel::selectShiftMask(), llvm::RISCVDAGToDAGISel::selectShiftMask(), setAllOnes(), setAllZero(), sext(), sextInReg(), shl(), simplifyBinaryIntrinsic(), llvm::TargetLowering::SimplifyDemandedBits(), llvm::X86TargetLowering::SimplifyDemandedBitsForTargetNode(), llvm::InstCombinerImpl::SimplifyDemandedUseBits(), llvm::X86TTIImpl::simplifyDemandedUseBitsIntrinsic(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::InstCombinerImpl::SimplifyMultipleUseDemandedBits(), llvm::TargetLowering::SimplifyMultipleUseDemandedBits(), llvm::X86TargetLowering::SimplifyMultipleUseDemandedBitsForTargetNode(), simplifyShift(), llvm::InstCombinerImpl::simplifyShrShlDemandedBits(), simplifySubInst(), smax(), smin(), srem(), llvm::ConstantRange::toKnownBits(), trunc(), tryBitfieldInsertOpFromOr(), tryBitfieldInsertOpFromOrAndImm(), udiv(), unionWith(), urem(), llvm::InstCombinerImpl::visitSub(), and zext().


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