27 Zero.setBitVal(SignBitPosition, Val.
One[SignBitPosition]);
28 One.setBitVal(SignBitPosition, Val.
Zero[SignBitPosition]);
33 bool CarryZero,
bool CarryOne) {
35 APInt PossibleSumZero =
LHS.getMaxValue() +
RHS.getMaxValue() + !CarryZero;
36 APInt PossibleSumOne =
LHS.getMinValue() +
RHS.getMinValue() + CarryOne;
39 APInt CarryKnownZero = ~(PossibleSumZero ^
LHS.Zero ^
RHS.Zero);
40 APInt CarryKnownOne = PossibleSumOne ^
LHS.One ^
RHS.One;
45 APInt CarryKnownUnion = std::move(CarryKnownZero) | CarryKnownOne;
46 APInt Known = std::move(LHSKnownUnion) & RHSKnownUnion & CarryKnownUnion;
51 KnownOut.
One = std::move(PossibleSumOne) &
Known;
56 const KnownBits &LHS,
const KnownBits &RHS,
const KnownBits &Carry) {
58 return ::computeForAddCarry(
64 const KnownBits &RHS) {
65 unsigned BitWidth = LHS.getBitWidth();
69 if (LHS.isUnknown() && RHS.isUnknown())
72 if (!LHS.isUnknown() && !RHS.isUnknown()) {
79 KnownBits NotRHS = RHS;
149 const KnownBits &Borrow) {
155 return ::computeForAddCarry(LHS, RHS,
169 if (InputMin.
sge(MinInRange) && InputMax.
sle(MaxInRange)) {
173 else if (InputMax.
slt(MinInRange)) {
177 else if (InputMin.
sgt(MaxInRange)) {
209 if (InputMax.
sle(MaxInRange)) {
211 Known.Zero = InputZeroLower & MinSatKB.
Zero;
212 Known.One = InputOneLower & MinSatKB.
One;
213 }
else if (InputMin.
sge(MinInRange)) {
215 Known.Zero = InputZeroLower & MaxSatKB.
Zero;
216 Known.One = InputOneLower & MaxSatKB.
One;
220 Known.One = InputOneLower & MinSatKB.
One & MaxSatKB.
One;
247 if (InputMax.
ule(MaxInRange)) {
270 if (InputMax.
ule(MaxInRange)) {
272 }
else if (InputMin.
ugt(MaxInRange)) {
284 "Illegal sext-in-register");
289 unsigned ExtBits =
BitWidth - SrcBitWidth;
291 Result.One =
One << ExtBits;
292 Result.Zero =
Zero << ExtBits;
293 Result.One.ashrInPlace(ExtBits);
294 Result.Zero.ashrInPlace(ExtBits);
305 APInt MaskedVal(Val);
315 if (LHS.getMinValue().uge(RHS.getMaxValue()))
317 if (RHS.getMinValue().uge(LHS.getMaxValue()))
323 KnownBits L = LHS.makeGE(RHS.getMinValue());
324 KnownBits R = RHS.makeGE(LHS.getMinValue());
325 return L.intersectWith(R);
330 auto Flip = [](
const KnownBits &Val) {
return KnownBits(Val.
One, Val.
Zero); };
331 return Flip(
umax(Flip(LHS), Flip(RHS)));
335 return flipSignBit(
umax(flipSignBit(LHS), flipSignBit(RHS)));
339 return flipSignBit(
umin(flipSignBit(LHS), flipSignBit(RHS)));
345 if (LHS.getMinValue().uge(RHS.getMaxValue()))
348 if (RHS.getMinValue().uge(LHS.getMaxValue()))
364 return abdu(flipSignBit(LHS), flipSignBit(RHS));
378 bool NSW,
bool ShAmtNonZero) {
379 unsigned BitWidth = LHS.getBitWidth();
380 auto ShiftByConst = [&](
const KnownBits &LHS,
unsigned ShiftAmt) {
382 bool ShiftedOutZero, ShiftedOutOne;
383 Known.Zero = LHS.Zero.ushl_ov(ShiftAmt, ShiftedOutZero);
384 Known.Zero.setLowBits(ShiftAmt);
385 Known.One = LHS.One.ushl_ov(ShiftAmt, ShiftedOutOne);
389 if (NUW && ShiftAmt != 0)
391 ShiftedOutZero =
true;
394 Known.makeNonNegative();
395 else if (ShiftedOutOne)
396 Known.makeNegative();
403 unsigned MinShiftAmount = RHS.getMinValue().getLimitedValue(
BitWidth);
404 if (MinShiftAmount == 0 && ShAmtNonZero)
406 if (LHS.isUnknown()) {
407 Known.Zero.setLowBits(MinShiftAmount);
408 if (NUW && NSW && MinShiftAmount != 0)
409 Known.makeNonNegative();
417 MaxShiftAmount = std::min(MaxShiftAmount, LHS.countMaxLeadingZeros() - 1);
419 MaxShiftAmount = std::min(MaxShiftAmount, LHS.countMaxLeadingZeros());
421 MaxShiftAmount = std::min(
423 std::max(LHS.countMaxLeadingZeros(), LHS.countMaxLeadingOnes()) - 1);
426 if (MinShiftAmount == 0 && MaxShiftAmount ==
BitWidth - 1 &&
428 Known.Zero.setLowBits(LHS.countMinTrailingZeros());
430 Known.One.setSignBit();
432 if (LHS.isNonNegative())
433 Known.makeNonNegative();
434 if (LHS.isNegative())
435 Known.makeNegative();
441 unsigned ShiftAmtZeroMask = RHS.Zero.zextOrTrunc(32).getZExtValue();
442 unsigned ShiftAmtOneMask = RHS.One.zextOrTrunc(32).getZExtValue();
443 Known.setAllConflict();
444 for (
unsigned ShiftAmt = MinShiftAmount; ShiftAmt <= MaxShiftAmount;
447 if ((ShiftAmtZeroMask & ShiftAmt) != 0 ||
448 (ShiftAmtOneMask | ShiftAmt) != ShiftAmt)
450 Known =
Known.intersectWith(ShiftByConst(LHS, ShiftAmt));
451 if (
Known.isUnknown())
456 if (
Known.hasConflict())
462 bool ShAmtNonZero,
bool Exact) {
463 unsigned BitWidth = LHS.getBitWidth();
464 auto ShiftByConst = [&](
const KnownBits &LHS,
unsigned ShiftAmt) {
465 KnownBits
Known = LHS;
468 Known.Zero.setHighBits(ShiftAmt);
474 unsigned MinShiftAmount = RHS.getMinValue().getLimitedValue(
BitWidth);
475 if (MinShiftAmount == 0 && ShAmtNonZero)
477 if (LHS.isUnknown()) {
478 Known.Zero.setHighBits(MinShiftAmount);
488 unsigned FirstOne = LHS.countMaxTrailingZeros();
489 if (FirstOne < MinShiftAmount) {
494 MaxShiftAmount = std::min(MaxShiftAmount, FirstOne);
497 unsigned ShiftAmtZeroMask = RHS.Zero.zextOrTrunc(32).getZExtValue();
498 unsigned ShiftAmtOneMask = RHS.One.zextOrTrunc(32).getZExtValue();
499 Known.setAllConflict();
500 for (
unsigned ShiftAmt = MinShiftAmount; ShiftAmt <= MaxShiftAmount;
503 if ((ShiftAmtZeroMask & ShiftAmt) != 0 ||
504 (ShiftAmtOneMask | ShiftAmt) != ShiftAmt)
506 Known =
Known.intersectWith(ShiftByConst(LHS, ShiftAmt));
507 if (
Known.isUnknown())
512 if (
Known.hasConflict())
518 bool ShAmtNonZero,
bool Exact) {
519 unsigned BitWidth = LHS.getBitWidth();
520 auto ShiftByConst = [&](
const KnownBits &LHS,
unsigned ShiftAmt) {
521 KnownBits
Known = LHS;
522 Known.Zero.ashrInPlace(ShiftAmt);
523 Known.One.ashrInPlace(ShiftAmt);
529 unsigned MinShiftAmount = RHS.getMinValue().getLimitedValue(
BitWidth);
530 if (MinShiftAmount == 0 && ShAmtNonZero)
532 if (LHS.isUnknown()) {
547 unsigned FirstOne = LHS.countMaxTrailingZeros();
548 if (FirstOne < MinShiftAmount) {
553 MaxShiftAmount = std::min(MaxShiftAmount, FirstOne);
556 unsigned ShiftAmtZeroMask = RHS.Zero.zextOrTrunc(32).getZExtValue();
557 unsigned ShiftAmtOneMask = RHS.One.zextOrTrunc(32).getZExtValue();
558 Known.setAllConflict();
559 for (
unsigned ShiftAmt = MinShiftAmount; ShiftAmt <= MaxShiftAmount;
562 if ((ShiftAmtZeroMask & ShiftAmt) != 0 ||
563 (ShiftAmtOneMask | ShiftAmt) != ShiftAmt)
565 Known =
Known.intersectWith(ShiftByConst(LHS, ShiftAmt));
566 if (
Known.isUnknown())
571 if (
Known.hasConflict())
594 auto ClMulOr = [](
const APInt &LHS,
const APInt &RHS) {
595 unsigned BW = LHS.getBitWidth();
596 assert(BW == RHS.getBitWidth() &&
"Operand mismatch");
599 seq(std::min(RHS.getActiveBits(), BW - LHS.countr_zero())))
607 APInt Known = ~(ClMulOr(~LHS.Zero & ~LHS.One, ~RHS.Zero) |
608 ClMulOr(~LHS.Zero, ~RHS.Zero & ~RHS.One));
626 unsigned M0 = 0,
M1 = 0;
639 else if (!Mask.Zero[
I])
660 unsigned M0 = 0,
M1 = 0;
677 else if (!Mask.Zero[
I])
683std::optional<bool>
KnownBits::eq(
const KnownBits &LHS,
const KnownBits &RHS) {
684 if (LHS.isConstant() && RHS.isConstant())
686 if (LHS.One.intersects(RHS.Zero) || RHS.One.intersects(LHS.Zero))
691std::optional<bool>
KnownBits::ne(
const KnownBits &LHS,
const KnownBits &RHS) {
692 if (std::optional<bool> KnownEQ =
eq(LHS, RHS))
699 if (LHS.getMaxValue().ule(RHS.getMinValue()))
702 if (LHS.getMinValue().ugt(RHS.getMaxValue()))
708 if (std::optional<bool> IsUGT =
ugt(RHS, LHS))
714 return ugt(RHS, LHS);
718 return uge(RHS, LHS);
723 if (LHS.getSignedMaxValue().sle(RHS.getSignedMinValue()))
726 if (LHS.getSignedMinValue().sgt(RHS.getSignedMaxValue()))
732 if (std::optional<bool> KnownSGT =
sgt(RHS, LHS))
738 return sgt(RHS, LHS);
742 return sge(RHS, LHS);
755 KnownBits Tmp = *
this;
764 false, IntMinIsPoison,
false,
794 if (IntMinIsPoison || (!
One.isZero() && !
One.isMinSignedValue())) {
807 MaxLZ = std::min(MaxLZ,
BitWidth - 1);
843 LeadingZeros = LeadingZeros > LostBits ? LeadingZeros - LostBits : 0;
844 Result.Zero.setHighBits(LeadingZeros);
847 LeadingOnes = LeadingOnes > LostBits ? LeadingOnes - LostBits : 0;
848 Result.One.setHighBits(LeadingOnes);
861 std::optional<bool> Overflow;
866 bool MayNegClamp =
true;
867 bool MayPosClamp =
true;
870 if (
Add && ((
LHS.isNegative() &&
RHS.isNonNegative()) ||
871 (
LHS.isNonNegative() &&
RHS.isNegative())))
873 else if (!
Add && (((
LHS.isNegative() &&
RHS.isNegative()) ||
874 (
LHS.isNonNegative() &&
RHS.isNonNegative()))))
891 false, UnsignedLHS, UnsignedRHS);
897 if (
LHS.isNonNegative() &&
RHS.isNonNegative())
903 if (
LHS.isNegative() &&
RHS.isNegative())
907 if (
LHS.isNegative() ||
RHS.isNegative())
909 if (
LHS.isNonNegative() ||
RHS.isNonNegative())
916 if (
LHS.isNegative() &&
RHS.isNonNegative())
922 if (
LHS.isNonNegative() &&
RHS.isNegative())
926 if (
LHS.isNegative() ||
RHS.isNonNegative())
928 if (
LHS.isNonNegative() ||
RHS.isNegative())
933 if (!MayNegClamp && !MayPosClamp)
938 (void)
LHS.getMaxValue().uadd_ov(
RHS.getMaxValue(), Of);
942 (void)
LHS.getMinValue().uadd_ov(
RHS.getMinValue(), Of);
949 (void)
LHS.getMinValue().usub_ov(
RHS.getMaxValue(), Of);
953 (void)
LHS.getMaxValue().usub_ov(
RHS.getMinValue(), Of);
974 "We somehow know overflow without knowing input sign");
1035 return flipSignBit(
avgFloorU(flipSignBit(LHS), flipSignBit(RHS)));
1043 return flipSignBit(
avgCeilU(flipSignBit(LHS), flipSignBit(RHS)));
1051 bool NoUndefSelfMultiply) {
1052 unsigned BitWidth = LHS.getBitWidth();
1054 assert((!NoUndefSelfMultiply || LHS == RHS) &&
1055 "Self multiplication knownbits mismatch");
1068 APInt UMaxResult = UMaxLHS.
umul_ov(UMaxRHS, HasOverflow);
1069 unsigned LeadZ = HasOverflow ? 0 : UMaxResult.
countl_zero();
1116 unsigned TrailBitsKnownLHS = (LHS.Zero | LHS.One).
countr_one();
1117 unsigned TrailBitsKnownRHS = (RHS.Zero | RHS.One).
countr_one();
1118 unsigned TrailZeroLHS = LHS.countMinTrailingZeros();
1119 unsigned TrailZeroRHS = RHS.countMinTrailingZeros();
1120 unsigned TrailZ = TrailZeroLHS + TrailZeroRHS;
1123 unsigned SmallestOperand = std::min(TrailBitsKnownLHS - TrailZeroLHS,
1124 TrailBitsKnownRHS - TrailZeroRHS);
1125 unsigned ResultBitsKnown = std::min(SmallestOperand + TrailZ,
BitWidth);
1128 APInt BottomKnown = LHS.One * RHS.One;
1132 Res.
Zero |= (~BottomKnown).getLoBits(ResultBitsKnown);
1135 if (NoUndefSelfMultiply) {
1137 unsigned TwoTZP1 = 2 * TrailZeroLHS + 1;
1143 if (TrailZeroLHS <
BitWidth && LHS.One[TrailZeroLHS]) {
1144 unsigned TwoTZP2 = TwoTZP1 + 1;
1154 unsigned BitWidth = LHS.getBitWidth();
1156 KnownBits WideLHS = LHS.sext(2 *
BitWidth);
1157 KnownBits WideRHS = RHS.sext(2 *
BitWidth);
1162 unsigned BitWidth = LHS.getBitWidth();
1164 KnownBits WideLHS = LHS.zext(2 *
BitWidth);
1165 KnownBits WideRHS = RHS.zext(2 *
BitWidth);
1179 Known.One.setBit(0);
1182 (int)
LHS.countMinTrailingZeros() - (int)
RHS.countMaxTrailingZeros();
1184 (int)
LHS.countMaxTrailingZeros() - (int)
RHS.countMinTrailingZeros();
1187 Known.Zero.setLowBits(MinTZ);
1188 if (MinTZ == MaxTZ) {
1190 Known.One.setBit(MinTZ);
1192 }
else if (MaxTZ < 0) {
1199 if (
Known.hasConflict())
1208 if (LHS.isNonNegative() && RHS.isNonNegative())
1209 return udiv(LHS, RHS, Exact);
1211 unsigned BitWidth = LHS.getBitWidth();
1214 if (LHS.isZero() || RHS.isZero()) {
1221 std::optional<APInt> Res;
1222 if (LHS.isNegative() && RHS.isNegative()) {
1231 }
else if (LHS.isNegative() && RHS.isNonNegative()) {
1233 if (Exact || (-LHS.getSignedMaxValue()).uge(RHS.getSignedMaxValue())) {
1239 Denom.
setBit(RHS.countMinTrailingZeros());
1240 Res = Num.
sdiv(Denom);
1242 }
else if (LHS.isStrictlyPositive() && RHS.isNegative()) {
1244 if (Exact || LHS.getSignedMinValue().uge(-RHS.getSignedMinValue())) {
1247 Res = Num.
sdiv(Denom);
1252 if (Res->isNonNegative()) {
1253 unsigned LeadZ = Res->countLeadingZeros();
1254 Known.Zero.setHighBits(LeadZ);
1256 unsigned LeadO = Res->countLeadingOnes();
1257 Known.One.setHighBits(LeadO);
1267 unsigned BitWidth = LHS.getBitWidth();
1270 if (LHS.isZero() || RHS.isZero()) {
1281 MinDenom.
setBit(RHS.countMinTrailingZeros());
1294 : LHS.getMinValue().udiv(MaxDenom);
1297 if (std::optional<unsigned> DifferentBit =
1299 Known.Zero.clearLowBits(*DifferentBit + 1);
1300 Known.One.clearLowBits(*DifferentBit + 1);
1309 unsigned BitWidth = LHS.getBitWidth();
1310 if (!RHS.isZero() && RHS.Zero[0]) {
1312 unsigned RHSZeros = RHS.countMinTrailingZeros();
1314 APInt OnesMask = LHS.One & Mask;
1315 APInt ZerosMask = LHS.Zero & Mask;
1324 if (LHS.getMaxValue().ult(RHS.getMinValue()))
1327 KnownBits
Known = remGetLowBits(LHS, RHS);
1341 KnownBits
Known = remGetLowBits(LHS, RHS);
1342 if (RHS.isConstant() && RHS.getConstant().isPowerOf2()) {
1344 APInt LowBits = RHS.getConstant() - 1;
1347 if (LHS.isNonNegative() || LowBits.
isSubsetOf(LHS.Zero))
1348 Known.Zero |= ~LowBits;
1352 if (LHS.isNegative() && LowBits.
intersects(LHS.One))
1353 Known.One |= ~LowBits;
1360 if (LHS.isNegative() &&
Known.isNonZero())
1361 Known.One.setHighBits(
1362 std::max(LHS.countMinLeadingOnes(), RHS.countMinSignBits()));
1363 else if (LHS.isNonNegative())
1364 Known.Zero.setHighBits(
1365 std::max(LHS.countMinLeadingZeros(), RHS.countMinSignBits()));
1390 Zero = std::move(Z);
1401 Known.One.setBit(Max);
1430#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1438 std::optional<APInt> RotAmt,
1439 bool IsRotateRight) {
1447 unsigned Amt = RotAmt->urem(
BitWidth);
1455 if (SrcSignBits > Amt + 1)
1456 return SrcSignBits - Amt;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static KnownBits avgComputeU(KnownBits LHS, KnownBits RHS, bool IsCeil)
static KnownBits computeForSatAddSub(bool Add, bool Signed, const KnownBits &LHS, const KnownBits &RHS)
static KnownBits divComputeLowBit(KnownBits Known, const KnownBits &LHS, const KnownBits &RHS, bool Exact)
static KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, bool CarryZero, bool CarryOne)
static unsigned getMaxShiftAmount(const APInt &MaxValue, unsigned BitWidth)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
Provides some synthesis utilities to produce sequences of values.
This file implements the C++20 <bit> header.
Class for arbitrary precision integers.
LLVM_ABI APInt umul_ov(const APInt &RHS, bool &Overflow) const
LLVM_ABI APInt usub_sat(const APInt &RHS) const
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
LLVM_ABI APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
LLVM_ABI uint64_t extractBitsAsZExtValue(unsigned numBits, unsigned bitPosition) const
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
void setBit(unsigned BitPosition)
Set the given bit to 1 whose position is given as "bitPosition".
LLVM_ABI APInt sadd_sat(const APInt &RHS) const
bool sgt(const APInt &RHS) const
Signed greater than comparison.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
void setSignBit()
Set the sign bit to 1.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
bool isNegative() const
Determine sign of this APInt.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
LLVM_ABI APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
void clearAllBits()
Set every bit to 0.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
unsigned countl_zero() const
The APInt version of std::countl_zero.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned countLeadingZeros() const
unsigned countl_one() const
Count the number of leading one bits.
void clearLowBits(unsigned loBits)
Set bottom loBits bits to 0.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
LLVM_ABI APInt uadd_sat(const APInt &RHS) const
bool getBoolValue() const
Convert APInt to a boolean value.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
void setBits(unsigned loBit, unsigned hiBit)
Set the bits from loBit (inclusive) to hiBit (exclusive) to 1.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
void clearBits(unsigned LoBit, unsigned HiBit)
Clear the bits from LoBit (inclusive) to HiBit (exclusive) to 0.
bool slt(const APInt &RHS) const
Signed less than comparison.
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
void clearSignBit()
Set the sign bit to 0.
LLVM_ABI APInt ssub_sat(const APInt &RHS) const
This class implements an extremely fast bulk output stream that can only output to a stream.
LLVM_ABI std::optional< unsigned > GetMostSignificantDifferentBit(const APInt &A, const APInt &B)
Compare two values, and if they are different, return the position of the most significant bit that i...
LLVM_ABI APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM)
Return A unsign-divided by B, rounded by the given rounding mode.
LLVM_ABI APInt fshr(const APInt &Hi, const APInt &Lo, const APInt &Shift)
Perform a funnel shift right.
LLVM_ABI APInt clmul(const APInt &LHS, const APInt &RHS)
Perform a carry-less multiply, also known as XOR multiplication, and return low-bits.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be unsigned.
LLVM_ABI APInt fshl(const APInt &Hi, const APInt &Lo, const APInt &Shift)
Perform a funnel shift left.
LLVM_ABI unsigned rot(unsigned SrcSignBits, unsigned BitWidth, std::optional< APInt > RotAmt, bool IsRotateRight)
Compute the number of sign bits after rotating a value.
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
@ Known
Known to have no common set bits.
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
int bit_width(T Value)
Returns the number of bits needed to represent Value if Value is nonzero.
unsigned M1(unsigned Val)
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
unsigned M0(unsigned Val)
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static KnownBits makeConstant(const APInt &C)
Create known bits from a known constant.
static LLVM_ABI KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
static LLVM_ABI std::optional< bool > eq(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_EQ result.
LLVM_ABI KnownBits sextInReg(unsigned SrcBitWidth) const
Return known bits for a in-register sign extension of the value we're tracking.
static LLVM_ABI KnownBits mulhu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from zero-extended multiply-hi.
static LLVM_ABI KnownBits smax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smax(LHS, RHS).
bool isNonNegative() const
Returns true if this value is known to be non-negative.
LLVM_ABI KnownBits blsi() const
Compute known bits for X & -X, which has only the lowest bit set of X set.
static LLVM_ABI KnownBits usub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.usub.sat(LHS, RHS)
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
LLVM_ABI KnownBits reduceAdd(unsigned NumElts) const
Compute known bits for horizontal add for a vector with NumElts elements, where each element has the ...
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
static LLVM_ABI KnownBits ashr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for ashr(LHS, RHS).
static LLVM_ABI KnownBits ssub_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.ssub.sat(LHS, RHS)
static LLVM_ABI KnownBits urem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for urem(LHS, RHS).
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
static LLVM_ABI std::optional< bool > ne(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_NE result.
LLVM_ABI KnownBits makeGE(const APInt &Val) const
Return KnownBits based on this, but updated given that the underlying value is known to be greater th...
APInt getSignedMaxValue() const
Return the maximal signed value possible given these KnownBits.
LLVM_ABI KnownBits blsmsk() const
Compute known bits for X ^ (X - 1), which has all bits up to and including the lowest set bit of X se...
LLVM_ABI KnownBits ctlz(bool ZeroIsPoison=false) const
Compute known bits for the count of leading zeros.
void setAllConflict()
Make all bits known to be both zero and one.
KnownBits trunc(unsigned BitWidth) const
Return known bits for a truncation of the value we're tracking.
bool hasConflict() const
Returns true if there is conflicting information.
static LLVM_ABI KnownBits fshl(const KnownBits &LHS, const KnownBits &RHS, const APInt &Amt)
Compute known bits for fshl(LHS, RHS, Amt).
static LLVM_ABI std::optional< bool > sge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGE result.
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
void setAllZero()
Make all bits known to be zero and discard any previous information.
LLVM_ABI KnownBits & operator|=(const KnownBits &RHS)
Update known bits based on ORing with RHS.
LLVM_ABI void print(raw_ostream &OS) const
unsigned getBitWidth() const
Get the bit width of this value.
static LLVM_ABI KnownBits umax(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umax(LHS, RHS).
bool isConstant() const
Returns true if we know the value of all bits.
LLVM_DUMP_METHOD void dump() const
static LLVM_ABI KnownBits lshr(const KnownBits &LHS, const KnownBits &RHS, bool ShAmtNonZero=false, bool Exact=false)
Compute known bits for lshr(LHS, RHS).
static LLVM_ABI KnownBits abdu(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for abdu(LHS, RHS).
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const
Return a subset of the known bits from [bitPosition,bitPosition+numBits).
static LLVM_ABI KnownBits pdep(const KnownBits &Val, const KnownBits &Mask)
Compute known bits for pdep(Val, Mask).
static LLVM_ABI KnownBits avgFloorU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorU.
KnownBits intersectWith(const KnownBits &RHS) const
Returns KnownBits information that is known to be true for both this and RHS.
static LLVM_ABI KnownBits computeForSubBorrow(const KnownBits &LHS, KnownBits RHS, const KnownBits &Borrow)
Compute known bits results from subtracting RHS from LHS with 1-bit Borrow.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
APInt getMaxValue() const
Return the maximal unsigned value possible given these KnownBits.
static LLVM_ABI KnownBits fshr(const KnownBits &LHS, const KnownBits &RHS, const APInt &Amt)
Compute known bits for fshr(LHS, RHS, Amt).
static LLVM_ABI KnownBits abds(KnownBits LHS, KnownBits RHS)
Compute known bits for abds(LHS, RHS).
static LLVM_ABI KnownBits smin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for smin(LHS, RHS).
LLVM_ABI KnownBits & operator&=(const KnownBits &RHS)
Update known bits based on ANDing with RHS.
static LLVM_ABI KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits from sign-extended multiply-hi.
static LLVM_ABI KnownBits srem(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for srem(LHS, RHS).
static LLVM_ABI std::optional< bool > ugt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGT result.
static LLVM_ABI KnownBits udiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for udiv(LHS, RHS).
static LLVM_ABI std::optional< bool > slt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLT result.
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
static LLVM_ABI KnownBits computeForAddSub(bool Add, bool NSW, bool NUW, const KnownBits &LHS, const KnownBits &RHS)
Compute known bits resulting from adding LHS and RHS.
static LLVM_ABI KnownBits sdiv(const KnownBits &LHS, const KnownBits &RHS, bool Exact=false)
Compute known bits for sdiv(LHS, RHS).
static LLVM_ABI std::optional< bool > ult(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULT result.
static LLVM_ABI KnownBits avgFloorS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgFloorS.
static LLVM_ABI std::optional< bool > ule(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_ULE result.
bool isNegative() const
Returns true if this value is known to be negative.
LLVM_ABI KnownBits truncSSat(unsigned BitWidth) const
Truncate with signed saturation (signed input -> signed output)
static LLVM_ABI KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry)
Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
static LLVM_ABI KnownBits avgCeilU(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilU.
static LLVM_ABI KnownBits uadd_sat(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from llvm.uadd.sat(LHS, RHS)
static LLVM_ABI KnownBits mul(const KnownBits &LHS, const KnownBits &RHS, bool NoUndefSelfMultiply=false)
Compute known bits resulting from multiplying LHS and RHS.
static LLVM_ABI KnownBits clmul(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for clmul(LHS, RHS).
LLVM_ABI KnownBits abs(bool IntMinIsPoison=false) const
Compute known bits for the absolute value.
static LLVM_ABI std::optional< bool > sle(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SLE result.
static LLVM_ABI std::optional< bool > sgt(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_SGT result.
unsigned countMinPopulation() const
Returns the number of bits known to be one.
LLVM_ABI KnownBits truncUSat(unsigned BitWidth) const
Truncate with unsigned saturation (unsigned input -> unsigned output)
static LLVM_ABI std::optional< bool > uge(const KnownBits &LHS, const KnownBits &RHS)
Determine if these known bits always give the same ICMP_UGE result.
APInt getSignedMinValue() const
Return the minimal signed value possible given these KnownBits.
LLVM_ABI KnownBits & operator^=(const KnownBits &RHS)
Update known bits based on XORing with RHS.
static LLVM_ABI 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 LLVM_ABI KnownBits umin(const KnownBits &LHS, const KnownBits &RHS)
Compute known bits for umin(LHS, RHS).
LLVM_ABI KnownBits truncSSatU(unsigned BitWidth) const
Truncate with signed saturation to unsigned (signed input -> unsigned output)
static LLVM_ABI KnownBits pext(const KnownBits &Val, const KnownBits &Mask)
Compute known bits for pext(Val, Mask).
static LLVM_ABI KnownBits avgCeilS(const KnownBits &LHS, const KnownBits &RHS)
Compute knownbits resulting from APIntOps::avgCeilS.
const APInt & getConstant() const
Returns the value when all bits have a known value.