58#include "llvm/IR/IntrinsicsAArch64.h"
59#include "llvm/IR/IntrinsicsAMDGPU.h"
60#include "llvm/IR/IntrinsicsRISCV.h"
61#include "llvm/IR/IntrinsicsX86.h"
98 return DL.getPointerTypeSizeInBits(Ty);
110 CxtI = dyn_cast<Instruction>(V);
124 CxtI = dyn_cast<Instruction>(V1);
128 CxtI = dyn_cast<Instruction>(V2);
136 const APInt &DemandedElts,
138 if (isa<ScalableVectorType>(Shuf->
getType())) {
140 DemandedLHS = DemandedRHS = DemandedElts;
147 DemandedElts, DemandedLHS, DemandedRHS);
159 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
187 V, DemandedElts,
Depth,
243 "LHS and RHS should have the same type");
245 "LHS and RHS should be integers");
256 return !
I->user_empty() &&
all_of(
I->users(), [](
const User *U) {
257 return match(U, m_ICmp(m_Value(), m_Zero()));
262 return !
I->user_empty() &&
all_of(
I->users(), [](
const User *U) {
263 ICmpInst::Predicate P;
264 return match(U, m_ICmp(P, m_Value(), m_Zero())) && ICmpInst::isEquality(P);
272 bool OrZero,
unsigned Depth,
275 return ::isKnownToBeAPowerOfTwo(
290 if (
auto *CI = dyn_cast<ConstantInt>(V))
291 return CI->getValue().isStrictlyPositive();
314 "Testing equality of non-equal types!");
315 auto *FVTy = dyn_cast<FixedVectorType>(V1->
getType());
318 return ::isKnownNonEqual(
319 V1, V2, DemandedElts, 0,
327 return Mask.isSubsetOf(Known.
Zero);
335 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
345 return ::ComputeNumSignBits(
354 return V->getType()->getScalarSizeInBits() - SignBits + 1;
359 const APInt &DemandedElts,
366 if (KnownOut.
isUnknown() && !NSW && !NUW)
391 bool isKnownNegativeOp0 = Known2.
isNegative();
394 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
399 (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
401 (isKnownNegativeOp0 && isKnownNonNegativeOp1 && Known.
isNonZero());
405 bool SelfMultiply = Op0 == Op1;
425 unsigned NumRanges = Ranges.getNumOperands() / 2;
431 for (
unsigned i = 0; i < NumRanges; ++i) {
433 mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
435 mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
439 unsigned CommonPrefixBits =
443 Known.
One &= UnsignedMax & Mask;
444 Known.
Zero &= ~UnsignedMax & Mask;
459 while (!WorkSet.
empty()) {
461 if (!Visited.
insert(V).second)
466 return EphValues.count(U);
471 if (V ==
I || (isa<Instruction>(V) &&
473 !cast<Instruction>(V)->isTerminator())) {
475 if (
const User *U = dyn_cast<User>(V))
487 return CI->isAssumeLikeIntrinsic();
495 bool AllowEphemerals) {
513 if (!AllowEphemerals && Inv == CxtI)
548 if (Pred == ICmpInst::ICMP_UGT)
552 if (Pred == ICmpInst::ICMP_NE)
563 auto *VC = dyn_cast<ConstantDataVector>(
RHS);
567 for (
unsigned ElemIdx = 0, NElem = VC->getNumElements(); ElemIdx < NElem;
570 Pred, VC->getElementAsAPInt(ElemIdx));
589 "Got assumption for the wrong function!");
592 if (!V->getType()->isPointerTy())
595 *
I,
I->bundle_op_info_begin()[Elem.Index])) {
597 (RK.AttrKind == Attribute::NonNull ||
598 (RK.AttrKind == Attribute::Dereferenceable &&
600 V->getType()->getPointerAddressSpace()))) &&
632 case ICmpInst::ICMP_EQ:
635 case ICmpInst::ICMP_SGE:
636 case ICmpInst::ICMP_SGT:
639 case ICmpInst::ICMP_SLT:
657 case ICmpInst::ICMP_EQ:
667 Known.
Zero |= ~*
C & *Mask;
673 Known.
One |= *
C & ~*Mask;
694 Known.
Zero |= RHSKnown.
Zero << ShAmt;
695 Known.
One |= RHSKnown.
One << ShAmt;
698 case ICmpInst::ICMP_NE: {
714 if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE) {
720 (*
C + (Pred == ICmpInst::ICMP_UGT)).countLeadingOnes());
722 if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_ULE) {
728 (*
C - (Pred == ICmpInst::ICMP_ULT)).countLeadingZeros());
740 Invert ? Cmp->getInversePredicate() : Cmp->getPredicate();
773 if (
auto *Cmp = dyn_cast<ICmpInst>(
Cond))
818 "Got assumption for the wrong function!");
821 if (!V->getType()->isPointerTy())
824 *
I,
I->bundle_op_info_begin()[Elem.Index])) {
825 if (RK.WasOn == V && RK.AttrKind == Attribute::Alignment &&
837 Value *Arg =
I->getArgOperand(0);
857 ICmpInst *Cmp = dyn_cast<ICmpInst>(Arg);
893 Known = KF(Known2, Known, ShAmtNonZero);
904 Value *
X =
nullptr, *
Y =
nullptr;
906 switch (
I->getOpcode()) {
907 case Instruction::And:
908 KnownOut = KnownLHS & KnownRHS;
918 KnownOut = KnownLHS.
blsi();
920 KnownOut = KnownRHS.
blsi();
923 case Instruction::Or:
924 KnownOut = KnownLHS | KnownRHS;
926 case Instruction::Xor:
927 KnownOut = KnownLHS ^ KnownRHS;
937 const KnownBits &XBits =
I->getOperand(0) ==
X ? KnownLHS : KnownRHS;
938 KnownOut = XBits.
blsmsk();
951 if (!KnownOut.
Zero[0] && !KnownOut.
One[0] &&
972 APInt DemandedEltsLHS, DemandedEltsRHS;
974 DemandedElts, DemandedEltsLHS,
977 const auto ComputeForSingleOpFunc =
979 return KnownBitsFunc(
984 if (DemandedEltsRHS.
isZero())
985 return ComputeForSingleOpFunc(
I->getOperand(0), DemandedEltsLHS);
986 if (DemandedEltsLHS.
isZero())
987 return ComputeForSingleOpFunc(
I->getOperand(1), DemandedEltsRHS);
989 return ComputeForSingleOpFunc(
I->getOperand(0), DemandedEltsLHS)
990 .intersectWith(ComputeForSingleOpFunc(
I->getOperand(1), DemandedEltsRHS));
999 auto *FVTy = dyn_cast<FixedVectorType>(
I->getType());
1000 APInt DemandedElts =
1008 Attribute Attr =
F->getFnAttribute(Attribute::VScaleRange);
1016 return ConstantRange::getEmpty(
BitWidth);
1061 const APInt &DemandedElts,
1067 switch (
I->getOpcode()) {
1069 case Instruction::Load:
1074 case Instruction::And:
1080 case Instruction::Or:
1086 case Instruction::Xor:
1092 case Instruction::Mul: {
1095 Known, Known2,
Depth, Q);
1098 case Instruction::UDiv: {
1105 case Instruction::SDiv: {
1112 case Instruction::Select: {
1113 auto ComputeForArm = [&](
Value *Arm,
bool Invert) {
1121 ComputeForArm(
I->getOperand(1),
false)
1125 case Instruction::FPTrunc:
1126 case Instruction::FPExt:
1127 case Instruction::FPToUI:
1128 case Instruction::FPToSI:
1129 case Instruction::SIToFP:
1130 case Instruction::UIToFP:
1132 case Instruction::PtrToInt:
1133 case Instruction::IntToPtr:
1136 case Instruction::ZExt:
1137 case Instruction::Trunc: {
1138 Type *SrcTy =
I->getOperand(0)->getType();
1140 unsigned SrcBitWidth;
1148 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1151 if (
auto *Inst = dyn_cast<PossiblyNonNegInst>(
I);
1152 Inst && Inst->hasNonNeg() && !Known.
isNegative())
1157 case Instruction::BitCast: {
1158 Type *SrcTy =
I->getOperand(0)->getType();
1162 !
I->getType()->isVectorTy()) {
1170 V->getType()->isFPOrFPVectorTy()) {
1171 Type *FPType = V->getType()->getScalarType();
1184 if (FPClasses &
fcInf)
1196 if (Result.SignBit) {
1197 if (*Result.SignBit)
1207 auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcTy);
1208 if (!SrcVecTy || !SrcVecTy->getElementType()->isIntegerTy() ||
1209 !
I->getType()->isIntOrIntVectorTy() ||
1210 isa<ScalableVectorType>(
I->getType()))
1215 unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits();
1232 unsigned SubScale =
BitWidth / SubBitWidth;
1234 for (
unsigned i = 0; i != NumElts; ++i) {
1235 if (DemandedElts[i])
1236 SubDemandedElts.
setBit(i * SubScale);
1240 for (
unsigned i = 0; i != SubScale; ++i) {
1244 Known.
insertBits(KnownSrc, ShiftElt * SubBitWidth);
1249 case Instruction::SExt: {
1251 unsigned SrcBitWidth =
I->getOperand(0)->getType()->getScalarSizeInBits();
1253 Known = Known.
trunc(SrcBitWidth);
1260 case Instruction::Shl: {
1264 bool ShAmtNonZero) {
1265 return KnownBits::shl(KnownVal, KnownAmt, NUW, NSW, ShAmtNonZero);
1275 case Instruction::LShr: {
1276 bool Exact = Q.
IIQ.
isExact(cast<BinaryOperator>(
I));
1278 bool ShAmtNonZero) {
1289 case Instruction::AShr: {
1290 bool Exact = Q.
IIQ.
isExact(cast<BinaryOperator>(
I));
1292 bool ShAmtNonZero) {
1299 case Instruction::Sub: {
1303 DemandedElts, Known, Known2,
Depth, Q);
1306 case Instruction::Add: {
1310 DemandedElts, Known, Known2,
Depth, Q);
1313 case Instruction::SRem:
1319 case Instruction::URem:
1324 case Instruction::Alloca:
1327 case Instruction::GetElementPtr: {
1336 for (
unsigned i = 1, e =
I->getNumOperands(); i != e; ++i, ++GTI) {
1352 "Access to structure field must be known at compile time");
1357 unsigned Idx = cast<ConstantInt>(
Index)->getZExtValue();
1360 AccConstIndices +=
Offset;
1371 unsigned IndexBitWidth =
Index->getType()->getScalarSizeInBits();
1385 APInt ScalingFactor(IndexBitWidth, TypeSizeInBytes);
1386 IndexConst *= ScalingFactor;
1410 case Instruction::PHI: {
1413 Value *R =
nullptr, *L =
nullptr;
1423 if ((Opcode == Instruction::LShr || Opcode == Instruction::AShr ||
1424 Opcode == Instruction::Shl) &&
1439 case Instruction::Shl:
1443 case Instruction::LShr:
1448 case Instruction::AShr:
1459 if (Opcode == Instruction::Add ||
1460 Opcode == Instruction::Sub ||
1461 Opcode == Instruction::And ||
1462 Opcode == Instruction::Or ||
1463 Opcode == Instruction::Mul) {
1470 unsigned OpNum =
P->getOperand(0) == R ? 0 : 1;
1471 Instruction *RInst =
P->getIncomingBlock(OpNum)->getTerminator();
1472 Instruction *LInst =
P->getIncomingBlock(1 - OpNum)->getTerminator();
1487 auto *OverflowOp = dyn_cast<OverflowingBinaryOperator>(BO);
1498 if (Opcode == Instruction::Add) {
1507 else if (Opcode == Instruction::Sub && BO->
getOperand(0) ==
I) {
1515 else if (Opcode == Instruction::Mul && Known2.
isNonNegative() &&
1525 if (
P->getNumIncomingValues() == 0)
1532 if (isa_and_nonnull<UndefValue>(
P->hasConstantValue()))
1537 for (
unsigned u = 0, e =
P->getNumIncomingValues(); u < e; ++u) {
1538 Value *IncValue =
P->getIncomingValue(u);
1540 if (IncValue ==
P)
continue;
1547 RecQ.
CxtI =
P->getIncomingBlock(u)->getTerminator();
1569 if ((TrueSucc ==
P->getParent()) != (FalseSucc ==
P->getParent())) {
1571 if (FalseSucc ==
P->getParent())
1585 Known2 = KnownUnion;
1599 case Instruction::Call:
1600 case Instruction::Invoke: {
1608 const auto *CB = cast<CallBase>(
I);
1610 if (std::optional<ConstantRange>
Range = CB->getRange())
1613 if (
const Value *RV = CB->getReturnedArgOperand()) {
1614 if (RV->getType() ==
I->getType()) {
1626 switch (
II->getIntrinsicID()) {
1629 case Intrinsic::abs: {
1631 bool IntMinIsPoison =
match(
II->getArgOperand(1),
m_One());
1632 Known = Known2.
abs(IntMinIsPoison);
1635 case Intrinsic::bitreverse:
1640 case Intrinsic::bswap:
1645 case Intrinsic::ctlz: {
1651 PossibleLZ = std::min(PossibleLZ,
BitWidth - 1);
1656 case Intrinsic::cttz: {
1662 PossibleTZ = std::min(PossibleTZ,
BitWidth - 1);
1667 case Intrinsic::ctpop: {
1678 case Intrinsic::fshr:
1679 case Intrinsic::fshl: {
1686 if (
II->getIntrinsicID() == Intrinsic::fshr)
1699 case Intrinsic::uadd_sat:
1704 case Intrinsic::usub_sat:
1709 case Intrinsic::sadd_sat:
1714 case Intrinsic::ssub_sat:
1720 case Intrinsic::vector_reverse:
1726 case Intrinsic::vector_reduce_and:
1727 case Intrinsic::vector_reduce_or:
1728 case Intrinsic::vector_reduce_umax:
1729 case Intrinsic::vector_reduce_umin:
1730 case Intrinsic::vector_reduce_smax:
1731 case Intrinsic::vector_reduce_smin:
1734 case Intrinsic::vector_reduce_xor: {
1739 auto *VecTy = cast<VectorType>(
I->getOperand(0)->getType());
1741 bool EvenCnt = VecTy->getElementCount().isKnownEven();
1745 if (VecTy->isScalableTy() || EvenCnt)
1749 case Intrinsic::umin:
1754 case Intrinsic::umax:
1759 case Intrinsic::smin:
1764 case Intrinsic::smax:
1769 case Intrinsic::ptrmask: {
1772 const Value *Mask =
I->getOperand(1);
1773 Known2 =
KnownBits(Mask->getType()->getScalarSizeInBits());
1779 case Intrinsic::x86_sse2_pmulh_w:
1780 case Intrinsic::x86_avx2_pmulh_w:
1781 case Intrinsic::x86_avx512_pmulh_w_512:
1786 case Intrinsic::x86_sse2_pmulhu_w:
1787 case Intrinsic::x86_avx2_pmulhu_w:
1788 case Intrinsic::x86_avx512_pmulhu_w_512:
1793 case Intrinsic::x86_sse42_crc32_64_64:
1796 case Intrinsic::x86_ssse3_phadd_d_128:
1797 case Intrinsic::x86_ssse3_phadd_w_128:
1798 case Intrinsic::x86_avx2_phadd_d:
1799 case Intrinsic::x86_avx2_phadd_w: {
1801 I, DemandedElts,
Depth, Q,
1807 case Intrinsic::x86_ssse3_phadd_sw_128:
1808 case Intrinsic::x86_avx2_phadd_sw: {
1813 case Intrinsic::x86_ssse3_phsub_d_128:
1814 case Intrinsic::x86_ssse3_phsub_w_128:
1815 case Intrinsic::x86_avx2_phsub_d:
1816 case Intrinsic::x86_avx2_phsub_w: {
1818 I, DemandedElts,
Depth, Q,
1824 case Intrinsic::x86_ssse3_phsub_sw_128:
1825 case Intrinsic::x86_avx2_phsub_sw: {
1830 case Intrinsic::riscv_vsetvli:
1831 case Intrinsic::riscv_vsetvlimax: {
1832 bool HasAVL =
II->getIntrinsicID() == Intrinsic::riscv_vsetvli;
1835 cast<ConstantInt>(
II->getArgOperand(HasAVL))->getZExtValue());
1837 cast<ConstantInt>(
II->getArgOperand(1 + HasAVL))->getZExtValue());
1844 if (
auto *CI = dyn_cast<ConstantInt>(
II->getArgOperand(0)))
1845 MaxVL = std::min(MaxVL, CI->getZExtValue());
1847 unsigned KnownZeroFirstBit =
Log2_32(MaxVL) + 1;
1852 case Intrinsic::vscale: {
1853 if (!
II->getParent() || !
II->getFunction())
1863 case Instruction::ShuffleVector: {
1864 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
1872 APInt DemandedLHS, DemandedRHS;
1879 if (!!DemandedLHS) {
1880 const Value *
LHS = Shuf->getOperand(0);
1886 if (!!DemandedRHS) {
1887 const Value *
RHS = Shuf->getOperand(1);
1893 case Instruction::InsertElement: {
1894 if (isa<ScalableVectorType>(
I->getType())) {
1898 const Value *Vec =
I->getOperand(0);
1899 const Value *Elt =
I->getOperand(1);
1900 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
1902 APInt DemandedVecElts = DemandedElts;
1903 bool NeedsElt =
true;
1905 if (CIdx && CIdx->getValue().ult(NumElts)) {
1906 DemandedVecElts.
clearBit(CIdx->getZExtValue());
1907 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1919 if (!DemandedVecElts.
isZero()) {
1925 case Instruction::ExtractElement: {
1928 const Value *Vec =
I->getOperand(0);
1930 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
1931 if (isa<ScalableVectorType>(Vec->
getType())) {
1936 unsigned NumElts = cast<FixedVectorType>(Vec->
getType())->getNumElements();
1938 if (CIdx && CIdx->getValue().ult(NumElts))
1943 case Instruction::ExtractValue:
1948 switch (
II->getIntrinsicID()) {
1950 case Intrinsic::uadd_with_overflow:
1951 case Intrinsic::sadd_with_overflow:
1953 true,
II->getArgOperand(0),
II->getArgOperand(1),
false,
1954 false, DemandedElts, Known, Known2,
Depth, Q);
1956 case Intrinsic::usub_with_overflow:
1957 case Intrinsic::ssub_with_overflow:
1959 false,
II->getArgOperand(0),
II->getArgOperand(1),
false,
1960 false, DemandedElts, Known, Known2,
Depth, Q);
1962 case Intrinsic::umul_with_overflow:
1963 case Intrinsic::smul_with_overflow:
1965 DemandedElts, Known, Known2,
Depth, Q);
1971 case Instruction::Freeze:
2015 if (!DemandedElts) {
2021 assert(V &&
"No Value?");
2025 Type *Ty = V->getType();
2029 "Not integer or pointer type!");
2031 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
2033 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
2034 "DemandedElt width should equal the fixed vector number of elements");
2037 "DemandedElt width should be 1 for scalars or scalable vectors");
2043 "V and Known should have same BitWidth");
2046 "V and Known should have same BitWidth");
2057 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
2064 assert(!isa<ScalableVectorType>(V->getType()));
2068 for (
unsigned i = 0, e = CDV->getNumElements(); i != e; ++i) {
2069 if (!DemandedElts[i])
2071 APInt Elt = CDV->getElementAsAPInt(i);
2080 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
2081 assert(!isa<ScalableVectorType>(V->getType()));
2085 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
2086 if (!DemandedElts[i])
2089 if (isa<PoisonValue>(Element))
2091 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
2096 const APInt &Elt = ElementCI->getValue();
2109 if (isa<UndefValue>(V))
2114 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
2116 if (
const auto *
A = dyn_cast<Argument>(V))
2117 if (std::optional<ConstantRange>
Range =
A->getRange())
2126 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
2127 if (!GA->isInterposable())
2132 if (
const Operator *
I = dyn_cast<Operator>(V))
2134 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2135 if (std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange())
2136 Known = CR->toKnownBits();
2140 if (isa<PointerType>(V->getType())) {
2141 Align Alignment = V->getPointerAlignment(Q.
DL);
2157 Value *Start =
nullptr, *Step =
nullptr;
2163 if (U.get() == Start) {
2179 case Instruction::Mul:
2184 case Instruction::SDiv:
2190 case Instruction::UDiv:
2196 case Instruction::Shl:
2198 case Instruction::AShr:
2202 case Instruction::LShr:
2217 if (isa<Constant>(V))
2221 if (OrZero && V->getType()->getScalarSizeInBits() == 1)
2224 auto *
I = dyn_cast<Instruction>(V);
2231 return F->hasFnAttribute(Attribute::VScaleRange);
2248 switch (
I->getOpcode()) {
2249 case Instruction::ZExt:
2251 case Instruction::Trunc:
2253 case Instruction::Shl:
2257 case Instruction::LShr:
2258 if (OrZero || Q.
IIQ.
isExact(cast<BinaryOperator>(
I)))
2261 case Instruction::UDiv:
2265 case Instruction::Mul:
2269 case Instruction::And:
2280 case Instruction::Add: {
2286 if (
match(
I->getOperand(0),
2290 if (
match(
I->getOperand(1),
2295 unsigned BitWidth = V->getType()->getScalarSizeInBits();
2304 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
2317 case Instruction::Select:
2320 case Instruction::PHI: {
2324 auto *PN = cast<PHINode>(
I);
2341 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
2342 return isKnownToBeAPowerOfTwo(U.get(), OrZero, NewDepth, RecQ);
2345 case Instruction::Invoke:
2346 case Instruction::Call: {
2347 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
2348 switch (
II->getIntrinsicID()) {
2349 case Intrinsic::umax:
2350 case Intrinsic::smax:
2351 case Intrinsic::umin:
2352 case Intrinsic::smin:
2357 case Intrinsic::bitreverse:
2358 case Intrinsic::bswap:
2360 case Intrinsic::fshr:
2361 case Intrinsic::fshl:
2363 if (
II->getArgOperand(0) ==
II->getArgOperand(1))
2387 F =
I->getFunction();
2391 if (!
GEP->hasNoUnsignedWrap() &&
2392 !(
GEP->isInBounds() &&
2397 assert(
GEP->getType()->isPointerTy() &&
"We only support plain pointer GEP");
2408 GTI != GTE; ++GTI) {
2410 if (
StructType *STy = GTI.getStructTypeOrNull()) {
2411 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
2415 if (ElementOffset > 0)
2421 if (GTI.getSequentialElementStride(Q.
DL).isZero())
2426 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
2450 assert(!isa<Constant>(V) &&
"Called for constant?");
2455 unsigned NumUsesExplored = 0;
2456 for (
const auto *U : V->users()) {
2464 if (
const auto *CB = dyn_cast<CallBase>(U))
2465 if (
auto *CalledFunc = CB->getCalledFunction())
2466 for (
const Argument &Arg : CalledFunc->args())
2467 if (CB->getArgOperand(Arg.getArgNo()) == V &&
2468 Arg.hasNonNullAttr(
false) &&
2476 V->getType()->getPointerAddressSpace()) &&
2494 NonNullIfTrue =
true;
2496 NonNullIfTrue =
false;
2502 for (
const auto *CmpU : U->users()) {
2504 if (Visited.
insert(CmpU).second)
2507 while (!WorkList.
empty()) {
2516 for (
const auto *CurrU : Curr->users())
2517 if (Visited.
insert(CurrU).second)
2522 if (
const BranchInst *BI = dyn_cast<BranchInst>(Curr)) {
2523 assert(BI->isConditional() &&
"uses a comparison!");
2526 BI->getSuccessor(NonNullIfTrue ? 0 : 1);
2530 }
else if (NonNullIfTrue &&
isGuard(Curr) &&
2531 DT->
dominates(cast<Instruction>(Curr), CtxI)) {
2545 const unsigned NumRanges = Ranges->getNumOperands() / 2;
2547 for (
unsigned i = 0; i < NumRanges; ++i) {
2549 mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 0));
2551 mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 1));
2563 Value *Start =
nullptr, *Step =
nullptr;
2564 const APInt *StartC, *StepC;
2570 case Instruction::Add:
2576 case Instruction::Mul:
2579 case Instruction::Shl:
2581 case Instruction::AShr:
2582 case Instruction::LShr:
2598 Value *
Y,
bool NSW,
bool NUW) {
2651 if (
auto *
C = dyn_cast<Constant>(
X))
2655 return ::isKnownNonEqual(
X,
Y, DemandedElts,
Depth, Q);
2660 Value *
Y,
bool NSW,
bool NUW) {
2689 auto ShiftOp = [&](
const APInt &Lhs,
const APInt &Rhs) {
2690 switch (
I->getOpcode()) {
2691 case Instruction::Shl:
2692 return Lhs.
shl(Rhs);
2693 case Instruction::LShr:
2694 return Lhs.
lshr(Rhs);
2695 case Instruction::AShr:
2696 return Lhs.
ashr(Rhs);
2702 auto InvShiftOp = [&](
const APInt &Lhs,
const APInt &Rhs) {
2703 switch (
I->getOpcode()) {
2704 case Instruction::Shl:
2705 return Lhs.
lshr(Rhs);
2706 case Instruction::LShr:
2707 case Instruction::AShr:
2708 return Lhs.
shl(Rhs);
2721 if (MaxShift.
uge(NumBits))
2724 if (!ShiftOp(KnownVal.
One, MaxShift).isZero())
2729 if (InvShiftOp(KnownVal.
Zero, NumBits - MaxShift)
2738 const APInt &DemandedElts,
2741 switch (
I->getOpcode()) {
2742 case Instruction::Alloca:
2744 return I->getType()->getPointerAddressSpace() == 0;
2745 case Instruction::GetElementPtr:
2746 if (
I->getType()->isPointerTy())
2749 case Instruction::BitCast: {
2777 Type *FromTy =
I->getOperand(0)->getType();
2782 case Instruction::IntToPtr:
2786 if (!isa<ScalableVectorType>(
I->getType()) &&
2791 case Instruction::PtrToInt:
2794 if (!isa<ScalableVectorType>(
I->getType()) &&
2799 case Instruction::Trunc:
2801 if (
auto *TI = dyn_cast<TruncInst>(
I))
2802 if (TI->hasNoSignedWrap() || TI->hasNoUnsignedWrap())
2806 case Instruction::Sub:
2809 case Instruction::Xor:
2814 case Instruction::Or:
2821 case Instruction::SExt:
2822 case Instruction::ZExt:
2826 case Instruction::Shl: {
2841 case Instruction::LShr:
2842 case Instruction::AShr: {
2857 case Instruction::UDiv:
2858 case Instruction::SDiv: {
2861 if (cast<PossiblyExactOperator>(
I)->isExact())
2873 if (
I->getOpcode() == Instruction::SDiv) {
2875 XKnown = XKnown.
abs(
false);
2876 YKnown = YKnown.
abs(
false);
2882 return XUgeY && *XUgeY;
2884 case Instruction::Add: {
2889 auto *BO = cast<OverflowingBinaryOperator>(
I);
2894 case Instruction::Mul: {
2900 case Instruction::Select: {
2907 auto SelectArmIsNonZero = [&](
bool IsTrueArm) {
2909 Op = IsTrueArm ?
I->getOperand(1) :
I->getOperand(2);
2922 Pred = ICmpInst::getInversePredicate(Pred);
2927 if (SelectArmIsNonZero(
true) &&
2928 SelectArmIsNonZero(
false))
2932 case Instruction::PHI: {
2933 auto *PN = cast<PHINode>(
I);
2943 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
2945 ICmpInst::Predicate Pred;
2947 BasicBlock *TrueSucc, *FalseSucc;
2948 if (match(RecQ.CxtI,
2949 m_Br(m_c_ICmp(Pred, m_Specific(U.get()), m_Value(X)),
2950 m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc)))) {
2952 if ((TrueSucc == PN->getParent()) != (FalseSucc == PN->getParent())) {
2954 if (FalseSucc == PN->getParent())
2955 Pred = CmpInst::getInversePredicate(Pred);
2956 if (cmpExcludesZero(Pred, X))
2964 case Instruction::InsertElement: {
2965 if (isa<ScalableVectorType>(
I->getType()))
2968 const Value *Vec =
I->getOperand(0);
2969 const Value *Elt =
I->getOperand(1);
2970 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
2973 APInt DemandedVecElts = DemandedElts;
2974 bool SkipElt =
false;
2976 if (CIdx && CIdx->getValue().ult(NumElts)) {
2977 DemandedVecElts.
clearBit(CIdx->getZExtValue());
2978 SkipElt = !DemandedElts[CIdx->getZExtValue()];
2984 (DemandedVecElts.
isZero() ||
2987 case Instruction::ExtractElement:
2988 if (
const auto *EEI = dyn_cast<ExtractElementInst>(
I)) {
2989 const Value *Vec = EEI->getVectorOperand();
2990 const Value *
Idx = EEI->getIndexOperand();
2991 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
2992 if (
auto *VecTy = dyn_cast<FixedVectorType>(Vec->
getType())) {
2993 unsigned NumElts = VecTy->getNumElements();
2995 if (CIdx && CIdx->getValue().ult(NumElts))
3001 case Instruction::ShuffleVector: {
3002 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
3005 APInt DemandedLHS, DemandedRHS;
3011 return (DemandedRHS.
isZero() ||
3016 case Instruction::Freeze:
3020 case Instruction::Load: {
3021 auto *LI = cast<LoadInst>(
I);
3024 if (
auto *PtrT = dyn_cast<PointerType>(
I->getType())) {
3037 case Instruction::ExtractValue: {
3043 case Instruction::Add:
3048 case Instruction::Sub:
3051 case Instruction::Mul:
3060 case Instruction::Call:
3061 case Instruction::Invoke: {
3062 const auto *Call = cast<CallBase>(
I);
3063 if (
I->getType()->isPointerTy()) {
3064 if (Call->isReturnNonNull())
3071 if (std::optional<ConstantRange>
Range = Call->getRange()) {
3076 if (
const Value *RV = Call->getReturnedArgOperand())
3081 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
3082 switch (
II->getIntrinsicID()) {
3083 case Intrinsic::sshl_sat:
3084 case Intrinsic::ushl_sat:
3085 case Intrinsic::abs:
3086 case Intrinsic::bitreverse:
3087 case Intrinsic::bswap:
3088 case Intrinsic::ctpop:
3092 case Intrinsic::ssub_sat:
3094 II->getArgOperand(0),
II->getArgOperand(1));
3095 case Intrinsic::sadd_sat:
3097 II->getArgOperand(0),
II->getArgOperand(1),
3100 case Intrinsic::vector_reverse:
3104 case Intrinsic::vector_reduce_or:
3105 case Intrinsic::vector_reduce_umax:
3106 case Intrinsic::vector_reduce_umin:
3107 case Intrinsic::vector_reduce_smax:
3108 case Intrinsic::vector_reduce_smin:
3110 case Intrinsic::umax:
3111 case Intrinsic::uadd_sat:
3119 case Intrinsic::smax: {
3122 auto IsNonZero = [&](
Value *
Op, std::optional<bool> &OpNonZero,
3124 if (!OpNonZero.has_value())
3125 OpNonZero = OpKnown.isNonZero() ||
3130 std::optional<bool> Op0NonZero, Op1NonZero;
3134 IsNonZero(
II->getArgOperand(1), Op1NonZero, Op1Known))
3139 IsNonZero(
II->getArgOperand(0), Op0NonZero, Op0Known))
3141 return IsNonZero(
II->getArgOperand(1), Op1NonZero, Op1Known) &&
3142 IsNonZero(
II->getArgOperand(0), Op0NonZero, Op0Known);
3144 case Intrinsic::smin: {
3160 case Intrinsic::umin:
3163 case Intrinsic::cttz:
3166 case Intrinsic::ctlz:
3169 case Intrinsic::fshr:
3170 case Intrinsic::fshl:
3172 if (
II->getArgOperand(0) ==
II->getArgOperand(1))
3175 case Intrinsic::vscale:
3177 case Intrinsic::experimental_get_vector_length:
3191 return Known.
One != 0;
3202 Type *Ty = V->getType();
3207 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3209 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3210 "DemandedElt width should equal the fixed vector number of elements");
3213 "DemandedElt width should be 1 for scalars");
3217 if (
auto *
C = dyn_cast<Constant>(V)) {
3218 if (
C->isNullValue())
3220 if (isa<ConstantInt>(
C))
3226 if (
auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
3227 for (
unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) {
3228 if (!DemandedElts[i])
3230 Constant *Elt =
C->getAggregateElement(i);
3233 if (!isa<PoisonValue>(Elt) && !isa<ConstantInt>(Elt))
3240 if (
auto *CPA = dyn_cast<ConstantPtrAuth>(V))
3246 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
3247 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
3248 GV->getType()->getAddressSpace() == 0)
3253 if (!isa<ConstantExpr>(V))
3257 if (
const auto *
A = dyn_cast<Argument>(V))
3258 if (std::optional<ConstantRange>
Range =
A->getRange()) {
3273 if (
PointerType *PtrTy = dyn_cast<PointerType>(Ty)) {
3276 if (
const Argument *
A = dyn_cast<Argument>(V)) {
3277 if (((
A->hasPassPointeeByValueCopyAttr() &&
3279 A->hasNonNullAttr()))
3284 if (
const auto *
I = dyn_cast<Operator>(V))
3288 if (!isa<Constant>(V) &&
3297 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
3298 APInt DemandedElts =
3300 return ::isKnownNonZero(V, DemandedElts, Q,
Depth);
3309static std::optional<std::pair<Value*, Value*>>
3313 return std::nullopt;
3322 case Instruction::Or:
3323 if (!cast<PossiblyDisjointInst>(Op1)->isDisjoint() ||
3324 !cast<PossiblyDisjointInst>(Op2)->isDisjoint())
3327 case Instruction::Xor:
3328 case Instruction::Add: {
3336 case Instruction::Sub:
3342 case Instruction::Mul: {
3346 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
3347 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
3348 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
3349 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
3355 !cast<ConstantInt>(Op1->
getOperand(1))->isZero())
3359 case Instruction::Shl: {
3362 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
3363 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
3364 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
3365 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
3372 case Instruction::AShr:
3373 case Instruction::LShr: {
3374 auto *PEO1 = cast<PossiblyExactOperator>(Op1);
3375 auto *PEO2 = cast<PossiblyExactOperator>(Op2);
3376 if (!PEO1->isExact() || !PEO2->isExact())
3383 case Instruction::SExt:
3384 case Instruction::ZExt:
3388 case Instruction::PHI: {
3389 const PHINode *PN1 = cast<PHINode>(Op1);
3390 const PHINode *PN2 = cast<PHINode>(Op2);
3396 Value *Start1 =
nullptr, *Step1 =
nullptr;
3398 Value *Start2 =
nullptr, *Step2 =
nullptr;
3405 cast<Operator>(BO2));
3414 if (Values->first != PN1 || Values->second != PN2)
3417 return std::make_pair(Start1, Start2);
3420 return std::nullopt;
3435 case Instruction::Or:
3436 if (!cast<PossiblyDisjointInst>(V1)->isDisjoint())
3439 case Instruction::Xor:
3440 case Instruction::Add:
3458 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) {
3461 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
3462 !
C->isZero() && !
C->isOne() &&
3473 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) {
3476 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
3490 bool UsedFullRecursion =
false;
3492 if (!VisitedBBs.
insert(IncomBB).second)
3496 const APInt *C1, *C2;
3501 if (UsedFullRecursion)
3505 RecQ.
CxtI = IncomBB->getTerminator();
3508 UsedFullRecursion =
true;
3516 const SelectInst *SI1 = dyn_cast<SelectInst>(V1);
3520 if (
const SelectInst *SI2 = dyn_cast<SelectInst>(V2)) {
3522 const Value *Cond2 = SI2->getCondition();
3525 DemandedElts,
Depth + 1, Q) &&
3527 DemandedElts,
Depth + 1, Q);
3540 if (!
A->getType()->isPointerTy() || !
B->getType()->isPointerTy())
3543 auto *GEPA = dyn_cast<GEPOperator>(
A);
3544 if (!GEPA || GEPA->getNumIndices() != 1 || !isa<Constant>(GEPA->idx_begin()))
3548 auto *PN = dyn_cast<PHINode>(GEPA->getPointerOperand());
3549 if (!PN || PN->getNumIncomingValues() != 2)
3554 Value *Start =
nullptr;
3556 if (PN->getIncomingValue(0) == Step)
3557 Start = PN->getIncomingValue(1);
3558 else if (PN->getIncomingValue(1) == Step)
3559 Start = PN->getIncomingValue(0);
3570 APInt StartOffset(IndexWidth, 0);
3571 Start = Start->stripAndAccumulateInBoundsConstantOffsets(Q.
DL, StartOffset);
3572 APInt StepOffset(IndexWidth, 0);
3578 APInt OffsetB(IndexWidth, 0);
3579 B =
B->stripAndAccumulateInBoundsConstantOffsets(Q.
DL, OffsetB);
3580 return Start ==
B &&
3591 if (V1->
getType() != V2->getType())
3601 auto *O1 = dyn_cast<Operator>(V1);
3602 auto *O2 = dyn_cast<Operator>(V2);
3603 if (O1 && O2 && O1->getOpcode() == O2->getOpcode()) {
3608 if (
const PHINode *PN1 = dyn_cast<PHINode>(V1)) {
3609 const PHINode *PN2 = cast<PHINode>(V2);
3665 "Input should be a Select!");
3675 const Value *LHS2 =
nullptr, *RHS2 =
nullptr;
3687 return CLow->
sle(*CHigh);
3692 const APInt *&CHigh) {
3693 assert((
II->getIntrinsicID() == Intrinsic::smin ||
3694 II->getIntrinsicID() == Intrinsic::smax) &&
"Must be smin/smax");
3697 auto *InnerII = dyn_cast<IntrinsicInst>(
II->getArgOperand(0));
3698 if (!InnerII || InnerII->getIntrinsicID() != InverseID ||
3703 if (
II->getIntrinsicID() == Intrinsic::smin)
3705 return CLow->
sle(*CHigh);
3713 const APInt &DemandedElts,
3715 const auto *CV = dyn_cast<Constant>(V);
3716 if (!CV || !isa<FixedVectorType>(CV->getType()))
3719 unsigned MinSignBits = TyBits;
3720 unsigned NumElts = cast<FixedVectorType>(CV->getType())->getNumElements();
3721 for (
unsigned i = 0; i != NumElts; ++i) {
3722 if (!DemandedElts[i])
3725 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
3729 MinSignBits = std::min(MinSignBits, Elt->getValue().getNumSignBits());
3736 const APInt &DemandedElts,
3742 assert(Result > 0 &&
"At least one sign bit needs to be present!");
3754 const APInt &DemandedElts,
3756 Type *Ty = V->getType();
3760 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3762 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3763 "DemandedElt width should equal the fixed vector number of elements");
3766 "DemandedElt width should be 1 for scalars");
3780 unsigned FirstAnswer = 1;
3788 if (
auto *U = dyn_cast<Operator>(V)) {
3791 case Instruction::SExt:
3792 Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
3796 case Instruction::SDiv: {
3797 const APInt *Denominator;
3810 return std::min(TyBits, NumBits + Denominator->
logBase2());
3815 case Instruction::SRem: {
3818 const APInt *Denominator;
3839 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
3840 Tmp = std::max(Tmp, ResBits);
3846 case Instruction::AShr: {
3851 if (ShAmt->
uge(TyBits))
3854 Tmp += ShAmtLimited;
3855 if (Tmp > TyBits) Tmp = TyBits;
3859 case Instruction::Shl: {
3864 if (ShAmt->
uge(TyBits))
3869 ShAmt->
uge(TyBits -
X->getType()->getScalarSizeInBits())) {
3871 Tmp += TyBits -
X->getType()->getScalarSizeInBits();
3875 if (ShAmt->
uge(Tmp))
3882 case Instruction::And:
3883 case Instruction::Or:
3884 case Instruction::Xor:
3889 FirstAnswer = std::min(Tmp, Tmp2);
3896 case Instruction::Select: {
3900 const APInt *CLow, *CHigh;
3908 return std::min(Tmp, Tmp2);
3911 case Instruction::Add:
3915 if (Tmp == 1)
break;
3918 if (
const auto *CRHS = dyn_cast<Constant>(U->getOperand(1)))
3919 if (CRHS->isAllOnesValue()) {
3925 if ((Known.
Zero | 1).isAllOnes())
3937 return std::min(Tmp, Tmp2) - 1;
3939 case Instruction::Sub:
3945 if (
const auto *CLHS = dyn_cast<Constant>(U->getOperand(0)))
3946 if (CLHS->isNullValue()) {
3951 if ((Known.
Zero | 1).isAllOnes())
3968 return std::min(Tmp, Tmp2) - 1;
3970 case Instruction::Mul: {
3973 unsigned SignBitsOp0 =
3975 if (SignBitsOp0 == 1)
3977 unsigned SignBitsOp1 =
3979 if (SignBitsOp1 == 1)
3981 unsigned OutValidBits =
3982 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
3983 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
3986 case Instruction::PHI: {
3987 const PHINode *PN = cast<PHINode>(U);
3990 if (NumIncomingValues > 4)
break;
3992 if (NumIncomingValues == 0)
break;
3998 for (
unsigned i = 0, e = NumIncomingValues; i != e; ++i) {
3999 if (Tmp == 1)
return Tmp;
4002 DemandedElts,
Depth + 1, RecQ));
4007 case Instruction::Trunc: {
4012 unsigned OperandTyBits = U->getOperand(0)->getType()->getScalarSizeInBits();
4013 if (Tmp > (OperandTyBits - TyBits))
4014 return Tmp - (OperandTyBits - TyBits);
4019 case Instruction::ExtractElement:
4026 case Instruction::ShuffleVector: {
4029 auto *Shuf = dyn_cast<ShuffleVectorInst>(U);
4034 APInt DemandedLHS, DemandedRHS;
4039 Tmp = std::numeric_limits<unsigned>::max();
4040 if (!!DemandedLHS) {
4041 const Value *
LHS = Shuf->getOperand(0);
4048 if (!!DemandedRHS) {
4049 const Value *
RHS = Shuf->getOperand(1);
4051 Tmp = std::min(Tmp, Tmp2);
4057 assert(Tmp <= TyBits &&
"Failed to determine minimum sign bits");
4060 case Instruction::Call: {
4061 if (
const auto *
II = dyn_cast<IntrinsicInst>(U)) {
4062 switch (
II->getIntrinsicID()) {
4065 case Intrinsic::abs:
4073 case Intrinsic::smin:
4074 case Intrinsic::smax: {
4075 const APInt *CLow, *CHigh;
4090 if (
unsigned VecSignBits =
4108 if (
F->isIntrinsic())
4109 return F->getIntrinsicID();
4115 if (
F->hasLocalLinkage() || !TLI || !TLI->
getLibFunc(CB, Func) ||
4125 return Intrinsic::sin;
4129 return Intrinsic::cos;
4133 return Intrinsic::tan;
4137 return Intrinsic::exp;
4141 return Intrinsic::exp2;
4145 return Intrinsic::log;
4147 case LibFunc_log10f:
4148 case LibFunc_log10l:
4149 return Intrinsic::log10;
4153 return Intrinsic::log2;
4157 return Intrinsic::fabs;
4161 return Intrinsic::minnum;
4165 return Intrinsic::maxnum;
4166 case LibFunc_copysign:
4167 case LibFunc_copysignf:
4168 case LibFunc_copysignl:
4169 return Intrinsic::copysign;
4171 case LibFunc_floorf:
4172 case LibFunc_floorl:
4173 return Intrinsic::floor;
4177 return Intrinsic::ceil;
4179 case LibFunc_truncf:
4180 case LibFunc_truncl:
4181 return Intrinsic::trunc;
4185 return Intrinsic::rint;
4186 case LibFunc_nearbyint:
4187 case LibFunc_nearbyintf:
4188 case LibFunc_nearbyintl:
4189 return Intrinsic::nearbyint;
4191 case LibFunc_roundf:
4192 case LibFunc_roundl:
4193 return Intrinsic::round;
4194 case LibFunc_roundeven:
4195 case LibFunc_roundevenf:
4196 case LibFunc_roundevenl:
4197 return Intrinsic::roundeven;
4201 return Intrinsic::pow;
4205 return Intrinsic::sqrt;
4253 switch (Mode.Input) {
4273 if (!Src.isKnownNeverPosZero() && !Src.isKnownNeverNegZero())
4277 if (Src.isKnownNeverSubnormal())
4307 bool &TrueIfSigned) {
4310 TrueIfSigned =
true;
4311 return RHS.isZero();
4313 TrueIfSigned =
true;
4314 return RHS.isAllOnes();
4316 TrueIfSigned =
false;
4317 return RHS.isAllOnes();
4319 TrueIfSigned =
false;
4320 return RHS.isZero();
4323 TrueIfSigned =
true;
4324 return RHS.isMaxSignedValue();
4327 TrueIfSigned =
true;
4328 return RHS.isMinSignedValue();
4331 TrueIfSigned =
false;
4332 return RHS.isMinSignedValue();
4335 TrueIfSigned =
false;
4336 return RHS.isMaxSignedValue();
4347 bool LookThroughSrc) {
4355std::pair<Value *, FPClassTest>
4357 const APFloat *ConstRHS,
bool LookThroughSrc) {
4359 auto [Src, ClassIfTrue, ClassIfFalse] =
4361 if (Src && ClassIfTrue == ~ClassIfFalse)
4362 return {Src, ClassIfTrue};
4373std::tuple<Value *, FPClassTest, FPClassTest>
4387 const bool IsNegativeRHS = (RHSClass &
fcNegative) == RHSClass;
4388 const bool IsPositiveRHS = (RHSClass &
fcPositive) == RHSClass;
4389 const bool IsNaN = (RHSClass & ~fcNan) ==
fcNone;
4409 const bool IsZero = (OrigClass &
fcZero) == OrigClass;