LLVM 20.0.0git
Functions
llvm::APIntOps Namespace Reference

Functions

const APIntsmin (const APInt &A, const APInt &B)
 Determine the smaller of two APInts considered to be signed.
 
const APIntsmax (const APInt &A, const APInt &B)
 Determine the larger of two APInts considered to be signed.
 
const APIntumin (const APInt &A, const APInt &B)
 Determine the smaller of two APInts considered to be unsigned.
 
const APIntumax (const APInt &A, const APInt &B)
 Determine the larger of two APInts considered to be unsigned.
 
const APInt abds (const APInt &A, const APInt &B)
 Determine the absolute difference of two APInts considered to be signed.
 
const APInt abdu (const APInt &A, const APInt &B)
 Determine the absolute difference of two APInts considered to be unsigned.
 
APInt avgFloorS (const APInt &C1, const APInt &C2)
 Compute the floor of the signed average of C1 and C2.
 
APInt avgFloorU (const APInt &C1, const APInt &C2)
 Compute the floor of the unsigned average of C1 and C2.
 
APInt avgCeilS (const APInt &C1, const APInt &C2)
 Compute the ceil of the signed average of C1 and C2.
 
APInt avgCeilU (const APInt &C1, const APInt &C2)
 Compute the ceil of the unsigned average of C1 and C2.
 
APInt mulhs (const APInt &C1, const APInt &C2)
 Performs (2*N)-bit multiplication on sign-extended operands.
 
APInt mulhu (const APInt &C1, const APInt &C2)
 Performs (2*N)-bit multiplication on zero-extended operands.
 
APInt GreatestCommonDivisor (APInt A, APInt B)
 Compute GCD of two unsigned APInt values.
 
double RoundAPIntToDouble (const APInt &APIVal)
 Converts the given APInt to a double value.
 
double RoundSignedAPIntToDouble (const APInt &APIVal)
 Converts the given APInt to a double value.
 
float RoundAPIntToFloat (const APInt &APIVal)
 Converts the given APInt to a float value.
 
float RoundSignedAPIntToFloat (const APInt &APIVal)
 Converts the given APInt to a float value.
 
APInt RoundDoubleToAPInt (double Double, unsigned width)
 Converts the given double value into a APInt.
 
APInt RoundFloatToAPInt (float Float, unsigned width)
 Converts a float value into a APInt.
 
APInt RoundingUDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
 Return A unsign-divided by B, rounded by the given rounding mode.
 
APInt RoundingSDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
 Return A sign-divided by B, rounded by the given rounding mode.
 
std::optional< APIntSolveQuadraticEquationWrap (APInt A, APInt B, APInt C, unsigned RangeWidth)
 Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g.
 
std::optional< unsignedGetMostSignificantDifferentBit (const APInt &A, const APInt &B)
 Compare two values, and if they are different, return the position of the most significant bit that is different in the values.
 
APInt ScaleBitMask (const APInt &A, unsigned NewBitWidth, bool MatchAllBits=false)
 Splat/Merge neighboring bits to widen/narrow the bitmask represented by.
 

Function Documentation

◆ abds()

const APInt llvm::APIntOps::abds ( const APInt A,
const APInt B 
)
inline

Determine the absolute difference of two APInts considered to be signed.

Definition at line 2237 of file APInt.h.

References A, abds(), and B.

Referenced by abds(), and FoldValue().

◆ abdu()

const APInt llvm::APIntOps::abdu ( const APInt A,
const APInt B 
)
inline

Determine the absolute difference of two APInts considered to be unsigned.

Definition at line 2242 of file APInt.h.

References A, abdu(), and B.

Referenced by abdu(), and FoldValue().

◆ avgCeilS()

APInt llvm::APIntOps::avgCeilS ( const APInt C1,
const APInt C2 
)

Compute the ceil of the signed average of C1 and C2.

Definition at line 3086 of file APInt.cpp.

Referenced by FoldValue().

◆ avgCeilU()

APInt llvm::APIntOps::avgCeilU ( const APInt C1,
const APInt C2 
)

Compute the ceil of the unsigned average of C1 and C2.

Definition at line 3091 of file APInt.cpp.

Referenced by FoldValue().

◆ avgFloorS()

APInt llvm::APIntOps::avgFloorS ( const APInt C1,
const APInt C2 
)

Compute the floor of the signed average of C1 and C2.

Definition at line 3076 of file APInt.cpp.

Referenced by FoldValue().

◆ avgFloorU()

APInt llvm::APIntOps::avgFloorU ( const APInt C1,
const APInt C2 
)

Compute the floor of the unsigned average of C1 and C2.

Definition at line 3081 of file APInt.cpp.

Referenced by FoldValue().

◆ GetMostSignificantDifferentBit()

std::optional< unsigned > llvm::APIntOps::GetMostSignificantDifferentBit ( const APInt A,
const APInt B 
)

Compare two values, and if they are different, return the position of the most significant bit that is different in the values.

Definition at line 2975 of file APInt.cpp.

References A, assert(), B, and llvm::countl_zero().

Referenced by llvm::ConstantRange::toKnownBits().

◆ GreatestCommonDivisor()

APInt llvm::APIntOps::GreatestCommonDivisor ( APInt  A,
APInt  B 
)

Compute GCD of two unsigned APInt values.

This function returns the greatest common divisor of the two APInt values using Stein's algorithm.

Returns
the greatest common divisor of A and B.

Definition at line 771 of file APInt.cpp.

References A, and B.

Referenced by gcd(), llvm::detail::gcd(), and getStrideAndModOffsetOfGEP().

◆ mulhs()

APInt llvm::APIntOps::mulhs ( const APInt C1,
const APInt C2 
)

Performs (2*N)-bit multiplication on sign-extended operands.

Returns the high N bits of the multiplication result.

Definition at line 3096 of file APInt.cpp.

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

Referenced by FoldValue().

◆ mulhu()

APInt llvm::APIntOps::mulhu ( const APInt C1,
const APInt C2 
)

Performs (2*N)-bit multiplication on zero-extended operands.

Returns the high N bits of the multiplication result.

Definition at line 3104 of file APInt.cpp.

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

Referenced by FoldValue().

◆ RoundAPIntToDouble()

double llvm::APIntOps::RoundAPIntToDouble ( const APInt APIVal)
inline

Converts the given APInt to a double value.

Treats the APInt as an unsigned value for conversion purposes.

Definition at line 2277 of file APInt.h.

References RoundAPIntToDouble(), and llvm::APInt::roundToDouble().

Referenced by RoundAPIntToDouble(), and RoundAPIntToFloat().

◆ RoundAPIntToFloat()

float llvm::APIntOps::RoundAPIntToFloat ( const APInt APIVal)
inline

Converts the given APInt to a float value.

Definition at line 2289 of file APInt.h.

References RoundAPIntToDouble(), and RoundAPIntToFloat().

Referenced by RoundAPIntToFloat().

◆ RoundDoubleToAPInt()

APInt llvm::APIntOps::RoundDoubleToAPInt ( double  Double,
unsigned  width 
)

Converts the given double value into a APInt.

This function convert a double value to an APInt value.

Definition at line 814 of file APInt.cpp.

References I, and isNeg().

Referenced by llvm::ExecutionEngine::getConstantValue(), and RoundFloatToAPInt().

◆ RoundFloatToAPInt()

APInt llvm::APIntOps::RoundFloatToAPInt ( float  Float,
unsigned  width 
)
inline

Converts a float value into a APInt.

Converts a float value into an APInt value.

Definition at line 2308 of file APInt.h.

References Float, RoundDoubleToAPInt(), and RoundFloatToAPInt().

Referenced by llvm::ExecutionEngine::getConstantValue(), and RoundFloatToAPInt().

◆ RoundingSDiv()

APInt llvm::APIntOps::RoundingSDiv ( const APInt A,
const APInt B,
APInt::Rounding  RM 
)

◆ RoundingUDiv()

APInt llvm::APIntOps::RoundingUDiv ( const APInt A,
const APInt B,
APInt::Rounding  RM 
)

Return A unsign-divided by B, rounded by the given rounding mode.

Definition at line 2736 of file APInt.cpp.

References A, B, llvm::APInt::DOWN, llvm::APInt::isZero(), llvm_unreachable, llvm::APInt::TOWARD_ZERO, llvm::APInt::udivrem(), and llvm::APInt::UP.

Referenced by llvm::InstCombinerImpl::foldICmpMulConstant(), and makeExactMulNUWRegion().

◆ RoundSignedAPIntToDouble()

double llvm::APIntOps::RoundSignedAPIntToDouble ( const APInt APIVal)
inline

Converts the given APInt to a double value.

Treats the APInt as a signed value for conversion purposes.

Definition at line 2284 of file APInt.h.

References RoundSignedAPIntToDouble(), and llvm::APInt::signedRoundToDouble().

Referenced by RoundSignedAPIntToDouble().

◆ RoundSignedAPIntToFloat()

float llvm::APIntOps::RoundSignedAPIntToFloat ( const APInt APIVal)
inline

Converts the given APInt to a float value.

Treats the APInt as a signed value for conversion purposes.

Definition at line 2296 of file APInt.h.

References RoundSignedAPIntToFloat(), and llvm::APInt::signedRoundToDouble().

Referenced by RoundSignedAPIntToFloat().

◆ ScaleBitMask()

APInt llvm::APIntOps::ScaleBitMask ( const APInt A,
unsigned  NewBitWidth,
bool  MatchAllBits = false 
)

Splat/Merge neighboring bits to widen/narrow the bitmask represented by.

Parameters
Ato
NewBitWidthbits.

MatchAnyBits: (Default) e.g. ScaleBitMask(0b0101, 8) -> 0b00110011 e.g. ScaleBitMask(0b00011011, 4) -> 0b0111

MatchAllBits: e.g. ScaleBitMask(0b0101, 8) -> 0b00110011 e.g. ScaleBitMask(0b00011011, 4) -> 0b0001 A.getBitwidth() or NewBitWidth must be a whole multiples of the other.

Definition at line 2982 of file APInt.cpp.

References A, assert(), llvm::APInt::getZero(), llvm::APInt::setBit(), and llvm::APInt::setBits().

Referenced by combineTargetShuffle(), combineX86ShufflesRecursively(), llvm::SelectionDAG::computeKnownBits(), computeKnownBitsForPMADDUBSW(), computeKnownBitsForPMADDWD(), computeKnownBitsForPSADBW(), llvm::SelectionDAG::ComputeNumSignBits(), getExtractedDemandedElts(), llvm::BasicTTIImplBase< T >::getReplicationShuffleCost(), llvm::X86TTIImpl::getReplicationShuffleCost(), llvm::X86TTIImpl::getScalarizationOverhead(), llvm::SelectionDAG::isSplatValue(), llvm::TargetLowering::SimplifyDemandedVectorElts(), llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode(), and llvm::X86TTIImpl::simplifyDemandedVectorEltsIntrinsic().

◆ smax()

const APInt & llvm::APIntOps::smax ( const APInt A,
const APInt B 
)
inline

◆ smin()

const APInt & llvm::APIntOps::smin ( const APInt A,
const APInt B 
)
inline

Determine the smaller of two APInts considered to be signed.

Definition at line 2217 of file APInt.h.

References A, B, and smin().

Referenced by llvm::ConstantFoldBinOp(), foldAndOrOfSETCC(), llvm::ScalarEvolution::getMinMaxExpr(), llvm::ConstantRangeList::intersectWith(), smin(), and llvm::ConstantRange::smin().

◆ SolveQuadraticEquationWrap()

std::optional< APInt > llvm::APIntOps::SolveQuadraticEquationWrap ( APInt  A,
APInt  B,
APInt  C,
unsigned  RangeWidth 
)

Let q(n) = An^2 + Bn + C, and BW = bit width of the value range (e.g.

32 for i32). This function finds the smallest number n, such that (a) n >= 0 and q(n) = 0, or (b) n >= 1 and q(n-1) and q(n), when evaluated in the set of all integers, belong to two different intervals [Rk, Rk+R), where R = 2^BW, and k is an integer. The idea here is to find when q(n) "overflows" 2^BW, while at the same time "allowing" subtraction. In unsigned modulo arithmetic a subtraction (treated as addition of negated numbers) would always count as an overflow, but here we want to allow values to decrease and increase as long as they are within the same interval. Specifically, adding of two negative numbers should not cause an overflow (as long as the magnitude does not exceed the bit width). On the other hand, given a positive number, adding a negative number to it can give a negative result, which would cause the value to go from [-2^BW, 0) to [0, 2^BW). In that sense, zero is treated as a special case of an overflow.

This function returns std::nullopt if after finding k that minimizes the positive solution to q(n) = kR, both solutions are contained between two consecutive integers.

There are cases where q(n) > T, and q(n+1) < T (assuming evaluation in arithmetic modulo 2^BW, and treating the values as signed) by the virtue of signed overflow. This function will not find such an n, however it may find a value of n satisfying the inequalities due to an unsigned overflow (if the values are treated as unsigned). To find a solution for a signed overflow, treat it as a problem of finding an unsigned overflow with a range with of BW-1.

The returned value may have a different bit width from the input coefficients.

Definition at line 2785 of file APInt.cpp.

References A, assert(), B, llvm::CallingConv::C, D, llvm::dbgs(), llvm::APInt::getOneBitSet(), llvm::APInt::isNegative(), llvm::APInt::isZero(), LLVM_DEBUG, llvm::APInt::sdivrem(), llvm::APInt::sgt(), llvm::APInt::udiv(), and X.

Referenced by SolveQuadraticAddRecExact(), and SolveQuadraticAddRecRange().

◆ umax()

const APInt & llvm::APIntOps::umax ( const APInt A,
const APInt B 
)
inline

◆ umin()

const APInt & llvm::APIntOps::umin ( const APInt A,
const APInt B 
)
inline