LLVM  14.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. More...
 
const APIntsmax (const APInt &A, const APInt &B)
 Determine the larger of two APInts considered to be signed. More...
 
const APIntumin (const APInt &A, const APInt &B)
 Determine the smaller of two APInts considered to be unsigned. More...
 
const APIntumax (const APInt &A, const APInt &B)
 Determine the larger of two APInts considered to be unsigned. More...
 
APInt GreatestCommonDivisor (APInt A, APInt B)
 Compute GCD of two unsigned APInt values. More...
 
double RoundAPIntToDouble (const APInt &APIVal)
 Converts the given APInt to a double value. More...
 
double RoundSignedAPIntToDouble (const APInt &APIVal)
 Converts the given APInt to a double value. More...
 
float RoundAPIntToFloat (const APInt &APIVal)
 Converts the given APInt to a float value. More...
 
float RoundSignedAPIntToFloat (const APInt &APIVal)
 Converts the given APInt to a float value. More...
 
APInt RoundDoubleToAPInt (double Double, unsigned width)
 Converts the given double value into a APInt. More...
 
APInt RoundFloatToAPInt (float Float, unsigned width)
 Converts a float value into a APInt. More...
 
APInt RoundingUDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
 Return A unsign-divided by B, rounded by the given rounding mode. More...
 
APInt RoundingSDiv (const APInt &A, const APInt &B, APInt::Rounding RM)
 Return A sign-divided by B, rounded by the given rounding mode. More...
 
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. More...
 
Optional< unsigned > GetMostSignificantDifferentBit (const APInt &A, const APInt &B)
 Compare two values, and if they are different, return the position of the most significant bit that is different in the values. More...
 
APInt ScaleBitMask (const APInt &A, unsigned NewBitWidth)
 Splat/Merge neighboring bits to widen/narrow the bitmask represented by. More...
 

Function Documentation

◆ GetMostSignificantDifferentBit()

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 2958 of file APInt.cpp.

References assert(), B, llvm::countLeadingZeros(), and llvm::None.

◆ 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 744 of file APInt.cpp.

References B.

Referenced by llvm::ConstraintSystem::addVariableRow(), and gcd().

◆ 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 2146 of file APInt.h.

References llvm::APInt::roundToDouble().

Referenced by RoundAPIntToFloat().

◆ RoundAPIntToFloat()

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

Converts the given APInt to a float value.

Definition at line 2158 of file APInt.h.

References RoundAPIntToDouble().

◆ 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 787 of file APInt.cpp.

References I.

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 2177 of file APInt.h.

References RoundDoubleToAPInt().

Referenced by llvm::ExecutionEngine::getConstantValue().

◆ RoundingSDiv()

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

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

Definition at line 2737 of file APInt.cpp.

References B, llvm::APInt::DOWN, llvm::APInt::isNegative(), llvm::APInt::isZero(), llvm_unreachable, llvm::AArch64::RM, llvm::APInt::sdivrem(), llvm::APInt::TOWARD_ZERO, and llvm::APInt::UP.

Referenced by makeExactMulNSWRegion().

◆ 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 2719 of file APInt.cpp.

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

Referenced by 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 2153 of file APInt.h.

References llvm::APInt::signedRoundToDouble().

◆ 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 2165 of file APInt.h.

References llvm::APInt::signedRoundToDouble().

◆ ScaleBitMask()

APInt llvm::APIntOps::ScaleBitMask ( const APInt A,
unsigned  NewBitWidth 
)

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

Parameters
Ato
NewBitWidthbits.

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

TODO: Do we need a mode where all bits must be set when merging down?

Definition at line 2965 of file APInt.cpp.

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

Referenced by combineX86ShufflesRecursively(), llvm::SelectionDAG::computeKnownBits(), llvm::SelectionDAG::ComputeNumSignBits(), llvm::X86TTIImpl::getReplicationShuffleCost(), llvm::BasicTTIImplBase< AMDGPUTTIImpl >::getReplicationShuffleCost(), llvm::TargetLowering::SimplifyDemandedVectorElts(), and llvm::X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode().

◆ 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

◆ SolveQuadraticEquationWrap()

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 None 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 2768 of file APInt.cpp.

References llvm::APInt::abs(), assert(), B, D, llvm::dbgs(), llvm::APInt::getOneBitSet(), llvm::APInt::isNegative(), llvm::APInt::isZero(), LLVM_DEBUG, llvm::None, RoundUp(), llvm::APInt::sdivrem(), llvm::APInt::sgt(), llvm::APInt::srem(), llvm::APInt::udiv(), llvm::APInt::urem(), 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