57#include "llvm/IR/IntrinsicsAArch64.h"
58#include "llvm/IR/IntrinsicsAMDGPU.h"
59#include "llvm/IR/IntrinsicsRISCV.h"
60#include "llvm/IR/IntrinsicsX86.h"
97 return DL.getPointerTypeSizeInBits(Ty);
109 CxtI = dyn_cast<Instruction>(V);
123 CxtI = dyn_cast<Instruction>(V1);
127 CxtI = dyn_cast<Instruction>(V2);
135 const APInt &DemandedElts,
137 if (isa<ScalableVectorType>(Shuf->
getType())) {
139 DemandedLHS = DemandedRHS = DemandedElts;
146 DemandedElts, DemandedLHS, DemandedRHS);
158 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
186 V, DemandedElts,
Depth,
242 "LHS and RHS should have the same type");
244 "LHS and RHS should be integers");
255 return !
I->user_empty() &&
all_of(
I->users(), [](
const User *U) {
256 return match(U, m_ICmp(m_Value(), m_Zero()));
261 return !
I->user_empty() &&
all_of(
I->users(), [](
const User *U) {
263 return match(U, m_ICmp(P, m_Value(), m_Zero())) && ICmpInst::isEquality(P);
268 bool OrZero,
unsigned Depth,
271 return ::isKnownToBeAPowerOfTwo(
286 if (
auto *CI = dyn_cast<ConstantInt>(V))
287 return CI->getValue().isStrictlyPositive();
310 if (V1 == V2 || V1->
getType() != V2->getType())
312 auto *FVTy = dyn_cast<FixedVectorType>(V1->
getType());
315 return ::isKnownNonEqual(
316 V1, V2, DemandedElts, 0,
324 return Mask.isSubsetOf(Known.
Zero);
332 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
342 return ::ComputeNumSignBits(
351 return V->getType()->getScalarSizeInBits() - SignBits + 1;
356 const APInt &DemandedElts,
363 if (KnownOut.
isUnknown() && !NSW && !NUW)
371 bool NUW,
const APInt &DemandedElts,
388 bool isKnownNegativeOp0 = Known2.
isNegative();
391 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
403 (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
405 (isKnownNegativeOp0 && isKnownNonNegativeOp1 && Known.
isNonZero());
409 bool SelfMultiply = Op0 == Op1;
429 unsigned NumRanges = Ranges.getNumOperands() / 2;
435 for (
unsigned i = 0; i < NumRanges; ++i) {
437 mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 0));
439 mdconst::extract<ConstantInt>(Ranges.getOperand(2 * i + 1));
443 unsigned CommonPrefixBits =
447 Known.
One &= UnsignedMax & Mask;
448 Known.
Zero &= ~UnsignedMax & Mask;
463 while (!WorkSet.
empty()) {
465 if (!Visited.
insert(V).second)
470 return EphValues.count(U);
475 if (V ==
I || (isa<Instruction>(V) &&
477 !cast<Instruction>(V)->isTerminator())) {
479 if (
const User *U = dyn_cast<User>(V))
491 return CI->isAssumeLikeIntrinsic();
499 bool AllowEphemerals) {
517 if (!AllowEphemerals && Inv == CxtI)
553 if (Pred == ICmpInst::ICMP_UGT)
557 if (Pred == ICmpInst::ICMP_NE)
568 auto *VC = dyn_cast<ConstantDataVector>(
RHS);
572 for (
unsigned ElemIdx = 0, NElem = VC->getNumElements(); ElemIdx < NElem;
575 Pred, VC->getElementAsAPInt(ElemIdx));
594 "Got assumption for the wrong function!");
597 if (!V->getType()->isPointerTy())
600 *
I,
I->bundle_op_info_begin()[Elem.Index])) {
602 (RK.AttrKind == Attribute::NonNull ||
603 (RK.AttrKind == Attribute::Dereferenceable &&
605 V->getType()->getPointerAddressSpace()))) &&
637 case ICmpInst::ICMP_EQ:
640 case ICmpInst::ICMP_SGE:
641 case ICmpInst::ICMP_SGT:
644 case ICmpInst::ICMP_SLT:
662 case ICmpInst::ICMP_EQ:
672 Known.
Zero |= ~*
C & *Mask;
678 Known.
One |= *
C & ~*Mask;
699 Known.
Zero |= RHSKnown.
Zero << ShAmt;
700 Known.
One |= RHSKnown.
One << ShAmt;
703 case ICmpInst::ICMP_NE: {
719 if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE) {
725 (*
C + (Pred == ICmpInst::ICMP_UGT)).countLeadingOnes());
727 if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_ULE) {
733 (*
C - (Pred == ICmpInst::ICMP_ULT)).countLeadingZeros());
745 Invert ? Cmp->getInversePredicate() : Cmp->getPredicate();
778 if (
auto *Cmp = dyn_cast<ICmpInst>(
Cond))
823 "Got assumption for the wrong function!");
826 if (!V->getType()->isPointerTy())
829 *
I,
I->bundle_op_info_begin()[Elem.Index])) {
833 if (RK.WasOn == V && RK.AttrKind == Attribute::Alignment &&
845 Value *Arg =
I->getArgOperand(0);
865 ICmpInst *Cmp = dyn_cast<ICmpInst>(Arg);
901 Known = KF(Known2, Known, ShAmtNonZero);
912 Value *
X =
nullptr, *
Y =
nullptr;
914 switch (
I->getOpcode()) {
915 case Instruction::And:
916 KnownOut = KnownLHS & KnownRHS;
926 KnownOut = KnownLHS.
blsi();
928 KnownOut = KnownRHS.
blsi();
931 case Instruction::Or:
932 KnownOut = KnownLHS | KnownRHS;
934 case Instruction::Xor:
935 KnownOut = KnownLHS ^ KnownRHS;
945 const KnownBits &XBits =
I->getOperand(0) ==
X ? KnownLHS : KnownRHS;
946 KnownOut = XBits.
blsmsk();
959 if (!KnownOut.
Zero[0] && !KnownOut.
One[0] &&
980 APInt DemandedEltsLHS, DemandedEltsRHS;
982 DemandedElts, DemandedEltsLHS,
985 const auto ComputeForSingleOpFunc =
987 return KnownBitsFunc(
992 if (DemandedEltsRHS.
isZero())
993 return ComputeForSingleOpFunc(
I->getOperand(0), DemandedEltsLHS);
994 if (DemandedEltsLHS.
isZero())
995 return ComputeForSingleOpFunc(
I->getOperand(1), DemandedEltsRHS);
997 return ComputeForSingleOpFunc(
I->getOperand(0), DemandedEltsLHS)
998 .intersectWith(ComputeForSingleOpFunc(
I->getOperand(1), DemandedEltsRHS));
1007 auto *FVTy = dyn_cast<FixedVectorType>(
I->getType());
1008 APInt DemandedElts =
1016 Attribute Attr =
F->getFnAttribute(Attribute::VScaleRange);
1024 return ConstantRange::getEmpty(
BitWidth);
1069 const APInt &DemandedElts,
1075 switch (
I->getOpcode()) {
1077 case Instruction::Load:
1082 case Instruction::And:
1088 case Instruction::Or:
1094 case Instruction::Xor:
1100 case Instruction::Mul: {
1104 DemandedElts, Known, Known2,
Depth, Q);
1107 case Instruction::UDiv: {
1114 case Instruction::SDiv: {
1121 case Instruction::Select: {
1122 auto ComputeForArm = [&](
Value *Arm,
bool Invert) {
1130 ComputeForArm(
I->getOperand(1),
false)
1134 case Instruction::FPTrunc:
1135 case Instruction::FPExt:
1136 case Instruction::FPToUI:
1137 case Instruction::FPToSI:
1138 case Instruction::SIToFP:
1139 case Instruction::UIToFP:
1141 case Instruction::PtrToInt:
1142 case Instruction::IntToPtr:
1145 case Instruction::ZExt:
1146 case Instruction::Trunc: {
1147 Type *SrcTy =
I->getOperand(0)->getType();
1149 unsigned SrcBitWidth;
1157 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1160 if (
auto *Inst = dyn_cast<PossiblyNonNegInst>(
I);
1161 Inst && Inst->hasNonNeg() && !Known.
isNegative())
1166 case Instruction::BitCast: {
1167 Type *SrcTy =
I->getOperand(0)->getType();
1171 !
I->getType()->isVectorTy()) {
1179 V->getType()->isFPOrFPVectorTy()) {
1180 Type *FPType = V->getType()->getScalarType();
1193 if (FPClasses &
fcInf)
1205 if (Result.SignBit) {
1206 if (*Result.SignBit)
1216 auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcTy);
1217 if (!SrcVecTy || !SrcVecTy->getElementType()->isIntegerTy() ||
1218 !
I->getType()->isIntOrIntVectorTy() ||
1219 isa<ScalableVectorType>(
I->getType()))
1224 unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits();
1241 unsigned SubScale =
BitWidth / SubBitWidth;
1243 for (
unsigned i = 0; i != NumElts; ++i) {
1244 if (DemandedElts[i])
1245 SubDemandedElts.
setBit(i * SubScale);
1249 for (
unsigned i = 0; i != SubScale; ++i) {
1253 Known.
insertBits(KnownSrc, ShiftElt * SubBitWidth);
1258 case Instruction::SExt: {
1260 unsigned SrcBitWidth =
I->getOperand(0)->getType()->getScalarSizeInBits();
1262 Known = Known.
trunc(SrcBitWidth);
1269 case Instruction::Shl: {
1273 bool ShAmtNonZero) {
1274 return KnownBits::shl(KnownVal, KnownAmt, NUW, NSW, ShAmtNonZero);
1284 case Instruction::LShr: {
1285 bool Exact = Q.
IIQ.
isExact(cast<BinaryOperator>(
I));
1287 bool ShAmtNonZero) {
1298 case Instruction::AShr: {
1299 bool Exact = Q.
IIQ.
isExact(cast<BinaryOperator>(
I));
1301 bool ShAmtNonZero) {
1308 case Instruction::Sub: {
1312 DemandedElts, Known, Known2,
Depth, Q);
1315 case Instruction::Add: {
1319 DemandedElts, Known, Known2,
Depth, Q);
1322 case Instruction::SRem:
1328 case Instruction::URem:
1333 case Instruction::Alloca:
1336 case Instruction::GetElementPtr: {
1345 for (
unsigned i = 1, e =
I->getNumOperands(); i != e; ++i, ++GTI) {
1350 Value *Index =
I->getOperand(i);
1353 Constant *CIndex = dyn_cast<Constant>(Index);
1361 "Access to structure field must be known at compile time");
1366 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
1369 AccConstIndices +=
Offset;
1380 unsigned IndexBitWidth = Index->getType()->getScalarSizeInBits();
1394 APInt ScalingFactor(IndexBitWidth, TypeSizeInBytes);
1395 IndexConst *= ScalingFactor;
1419 case Instruction::PHI: {
1422 Value *R =
nullptr, *L =
nullptr;
1435 case Instruction::LShr:
1436 case Instruction::AShr:
1437 case Instruction::Shl:
1438 case Instruction::UDiv:
1445 case Instruction::URem: {
1458 case Instruction::Shl:
1462 case Instruction::LShr:
1463 case Instruction::UDiv:
1464 case Instruction::URem:
1469 case Instruction::AShr:
1481 case Instruction::Add:
1482 case Instruction::Sub:
1483 case Instruction::And:
1484 case Instruction::Or:
1485 case Instruction::Mul: {
1492 unsigned OpNum =
P->getOperand(0) == R ? 0 : 1;
1493 Instruction *RInst =
P->getIncomingBlock(OpNum)->getTerminator();
1494 Instruction *LInst =
P->getIncomingBlock(1 - OpNum)->getTerminator();
1509 auto *OverflowOp = dyn_cast<OverflowingBinaryOperator>(BO);
1523 case Instruction::Add: {
1533 case Instruction::Sub: {
1544 case Instruction::Mul:
1561 if (
P->getNumIncomingValues() == 0)
1568 if (isa_and_nonnull<UndefValue>(
P->hasConstantValue()))
1573 for (
unsigned u = 0, e =
P->getNumIncomingValues(); u < e; ++u) {
1574 Value *IncValue =
P->getIncomingValue(u);
1576 if (IncValue ==
P)
continue;
1580 if (
auto *SI = dyn_cast<SelectInst>(IncValue)) {
1581 if (SI->getTrueValue() ==
P || SI->getFalseValue() ==
P)
1582 IncValue = SI->getTrueValue() ==
P ? SI->getFalseValue()
1583 : SI->getTrueValue();
1591 RecQ.
CxtI =
P->getIncomingBlock(u)->getTerminator();
1613 if ((TrueSucc ==
P->getParent()) != (FalseSucc ==
P->getParent())) {
1615 if (FalseSucc ==
P->getParent())
1629 Known2 = KnownUnion;
1643 case Instruction::Call:
1644 case Instruction::Invoke: {
1652 const auto *CB = cast<CallBase>(
I);
1654 if (std::optional<ConstantRange>
Range = CB->getRange())
1657 if (
const Value *RV = CB->getReturnedArgOperand()) {
1658 if (RV->getType() ==
I->getType()) {
1670 switch (
II->getIntrinsicID()) {
1673 case Intrinsic::abs: {
1675 bool IntMinIsPoison =
match(
II->getArgOperand(1),
m_One());
1676 Known = Known2.
abs(IntMinIsPoison);
1679 case Intrinsic::bitreverse:
1684 case Intrinsic::bswap:
1689 case Intrinsic::ctlz: {
1695 PossibleLZ = std::min(PossibleLZ,
BitWidth - 1);
1700 case Intrinsic::cttz: {
1706 PossibleTZ = std::min(PossibleTZ,
BitWidth - 1);
1711 case Intrinsic::ctpop: {
1722 case Intrinsic::fshr:
1723 case Intrinsic::fshl: {
1730 if (
II->getIntrinsicID() == Intrinsic::fshr)
1743 case Intrinsic::uadd_sat:
1748 case Intrinsic::usub_sat:
1753 case Intrinsic::sadd_sat:
1758 case Intrinsic::ssub_sat:
1764 case Intrinsic::vector_reverse:
1770 case Intrinsic::vector_reduce_and:
1771 case Intrinsic::vector_reduce_or:
1772 case Intrinsic::vector_reduce_umax:
1773 case Intrinsic::vector_reduce_umin:
1774 case Intrinsic::vector_reduce_smax:
1775 case Intrinsic::vector_reduce_smin:
1778 case Intrinsic::vector_reduce_xor: {
1783 auto *VecTy = cast<VectorType>(
I->getOperand(0)->getType());
1785 bool EvenCnt = VecTy->getElementCount().isKnownEven();
1789 if (VecTy->isScalableTy() || EvenCnt)
1793 case Intrinsic::umin:
1798 case Intrinsic::umax:
1803 case Intrinsic::smin:
1808 case Intrinsic::smax:
1813 case Intrinsic::ptrmask: {
1816 const Value *Mask =
I->getOperand(1);
1817 Known2 =
KnownBits(Mask->getType()->getScalarSizeInBits());
1823 case Intrinsic::x86_sse2_pmulh_w:
1824 case Intrinsic::x86_avx2_pmulh_w:
1825 case Intrinsic::x86_avx512_pmulh_w_512:
1830 case Intrinsic::x86_sse2_pmulhu_w:
1831 case Intrinsic::x86_avx2_pmulhu_w:
1832 case Intrinsic::x86_avx512_pmulhu_w_512:
1837 case Intrinsic::x86_sse42_crc32_64_64:
1840 case Intrinsic::x86_ssse3_phadd_d_128:
1841 case Intrinsic::x86_ssse3_phadd_w_128:
1842 case Intrinsic::x86_avx2_phadd_d:
1843 case Intrinsic::x86_avx2_phadd_w: {
1845 I, DemandedElts,
Depth, Q,
1851 case Intrinsic::x86_ssse3_phadd_sw_128:
1852 case Intrinsic::x86_avx2_phadd_sw: {
1857 case Intrinsic::x86_ssse3_phsub_d_128:
1858 case Intrinsic::x86_ssse3_phsub_w_128:
1859 case Intrinsic::x86_avx2_phsub_d:
1860 case Intrinsic::x86_avx2_phsub_w: {
1862 I, DemandedElts,
Depth, Q,
1868 case Intrinsic::x86_ssse3_phsub_sw_128:
1869 case Intrinsic::x86_avx2_phsub_sw: {
1874 case Intrinsic::riscv_vsetvli:
1875 case Intrinsic::riscv_vsetvlimax: {
1876 bool HasAVL =
II->getIntrinsicID() == Intrinsic::riscv_vsetvli;
1879 cast<ConstantInt>(
II->getArgOperand(HasAVL))->getZExtValue());
1881 cast<ConstantInt>(
II->getArgOperand(1 + HasAVL))->getZExtValue());
1888 if (
auto *CI = dyn_cast<ConstantInt>(
II->getArgOperand(0)))
1889 MaxVL = std::min(MaxVL, CI->getZExtValue());
1891 unsigned KnownZeroFirstBit =
Log2_32(MaxVL) + 1;
1896 case Intrinsic::vscale: {
1897 if (!
II->getParent() || !
II->getFunction())
1907 case Instruction::ShuffleVector: {
1908 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
1916 APInt DemandedLHS, DemandedRHS;
1923 if (!!DemandedLHS) {
1924 const Value *
LHS = Shuf->getOperand(0);
1930 if (!!DemandedRHS) {
1931 const Value *
RHS = Shuf->getOperand(1);
1937 case Instruction::InsertElement: {
1938 if (isa<ScalableVectorType>(
I->getType())) {
1942 const Value *Vec =
I->getOperand(0);
1943 const Value *Elt =
I->getOperand(1);
1944 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
1946 APInt DemandedVecElts = DemandedElts;
1947 bool NeedsElt =
true;
1949 if (CIdx && CIdx->getValue().ult(NumElts)) {
1950 DemandedVecElts.
clearBit(CIdx->getZExtValue());
1951 NeedsElt = DemandedElts[CIdx->getZExtValue()];
1963 if (!DemandedVecElts.
isZero()) {
1969 case Instruction::ExtractElement: {
1972 const Value *Vec =
I->getOperand(0);
1974 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
1975 if (isa<ScalableVectorType>(Vec->
getType())) {
1980 unsigned NumElts = cast<FixedVectorType>(Vec->
getType())->getNumElements();
1982 if (CIdx && CIdx->getValue().ult(NumElts))
1987 case Instruction::ExtractValue:
1992 switch (
II->getIntrinsicID()) {
1994 case Intrinsic::uadd_with_overflow:
1995 case Intrinsic::sadd_with_overflow:
1997 true,
II->getArgOperand(0),
II->getArgOperand(1),
false,
1998 false, DemandedElts, Known, Known2,
Depth, Q);
2000 case Intrinsic::usub_with_overflow:
2001 case Intrinsic::ssub_with_overflow:
2003 false,
II->getArgOperand(0),
II->getArgOperand(1),
false,
2004 false, DemandedElts, Known, Known2,
Depth, Q);
2006 case Intrinsic::umul_with_overflow:
2007 case Intrinsic::smul_with_overflow:
2009 false, DemandedElts, Known, Known2,
Depth, Q);
2015 case Instruction::Freeze:
2059 if (!DemandedElts) {
2065 assert(V &&
"No Value?");
2069 Type *Ty = V->getType();
2073 "Not integer or pointer type!");
2075 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
2077 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
2078 "DemandedElt width should equal the fixed vector number of elements");
2081 "DemandedElt width should be 1 for scalars or scalable vectors");
2087 "V and Known should have same BitWidth");
2090 "V and Known should have same BitWidth");
2101 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
2108 assert(!isa<ScalableVectorType>(V->getType()));
2112 for (
unsigned i = 0, e = CDV->getNumElements(); i != e; ++i) {
2113 if (!DemandedElts[i])
2115 APInt Elt = CDV->getElementAsAPInt(i);
2124 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
2125 assert(!isa<ScalableVectorType>(V->getType()));
2129 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
2130 if (!DemandedElts[i])
2133 if (isa<PoisonValue>(Element))
2135 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
2140 const APInt &Elt = ElementCI->getValue();
2153 if (isa<UndefValue>(V))
2158 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
2160 if (
const auto *
A = dyn_cast<Argument>(V))
2161 if (std::optional<ConstantRange>
Range =
A->getRange())
2170 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
2171 if (!GA->isInterposable())
2176 if (
const Operator *
I = dyn_cast<Operator>(V))
2178 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2179 if (std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange())
2180 Known = CR->toKnownBits();
2184 if (isa<PointerType>(V->getType())) {
2185 Align Alignment = V->getPointerAlignment(Q.
DL);
2201 Value *Start =
nullptr, *Step =
nullptr;
2207 if (U.get() == Start) {
2223 case Instruction::Mul:
2228 case Instruction::SDiv:
2234 case Instruction::UDiv:
2240 case Instruction::Shl:
2242 case Instruction::AShr:
2246 case Instruction::LShr:
2264 Pred = ICmpInst::getInversePredicate(Pred);
2266 if (OrZero && Pred == ICmpInst::ICMP_ULT && *RHSC == 2)
2269 return Pred == ICmpInst::ICMP_EQ && *RHSC == 1;
2280 if (isa<Constant>(V))
2284 if (OrZero && V->getType()->getScalarSizeInBits() == 1)
2319 auto *
I = dyn_cast<Instruction>(V);
2326 return F->hasFnAttribute(Attribute::VScaleRange);
2343 switch (
I->getOpcode()) {
2344 case Instruction::ZExt:
2346 case Instruction::Trunc:
2348 case Instruction::Shl:
2352 case Instruction::LShr:
2353 if (OrZero || Q.
IIQ.
isExact(cast<BinaryOperator>(
I)))
2356 case Instruction::UDiv:
2360 case Instruction::Mul:
2364 case Instruction::And:
2375 case Instruction::Add: {
2381 if (
match(
I->getOperand(0),
2385 if (
match(
I->getOperand(1),
2390 unsigned BitWidth = V->getType()->getScalarSizeInBits();
2399 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
2412 case Instruction::Select:
2415 case Instruction::PHI: {
2419 auto *PN = cast<PHINode>(
I);
2436 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
2437 return isKnownToBeAPowerOfTwo(U.get(), OrZero, NewDepth, RecQ);
2440 case Instruction::Invoke:
2441 case Instruction::Call: {
2442 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
2443 switch (
II->getIntrinsicID()) {
2444 case Intrinsic::umax:
2445 case Intrinsic::smax:
2446 case Intrinsic::umin:
2447 case Intrinsic::smin:
2452 case Intrinsic::bitreverse:
2453 case Intrinsic::bswap:
2455 case Intrinsic::fshr:
2456 case Intrinsic::fshl:
2458 if (
II->getArgOperand(0) ==
II->getArgOperand(1))
2482 F =
I->getFunction();
2486 if (!
GEP->hasNoUnsignedWrap() &&
2487 !(
GEP->isInBounds() &&
2492 assert(
GEP->getType()->isPointerTy() &&
"We only support plain pointer GEP");
2503 GTI != GTE; ++GTI) {
2505 if (
StructType *STy = GTI.getStructTypeOrNull()) {
2506 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
2510 if (ElementOffset > 0)
2516 if (GTI.getSequentialElementStride(Q.
DL).isZero())
2521 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
2545 assert(!isa<Constant>(V) &&
"Called for constant?");
2550 unsigned NumUsesExplored = 0;
2551 for (
const auto *U : V->users()) {
2559 if (
const auto *CB = dyn_cast<CallBase>(U))
2560 if (
auto *CalledFunc = CB->getCalledFunction())
2561 for (
const Argument &Arg : CalledFunc->args())
2562 if (CB->getArgOperand(Arg.getArgNo()) == V &&
2563 Arg.hasNonNullAttr(
false) &&
2571 V->getType()->getPointerAddressSpace()) &&
2589 NonNullIfTrue =
true;
2591 NonNullIfTrue =
false;
2597 for (
const auto *CmpU : U->users()) {
2599 if (Visited.
insert(CmpU).second)
2602 while (!WorkList.
empty()) {
2611 for (
const auto *CurrU : Curr->users())
2612 if (Visited.
insert(CurrU).second)
2617 if (
const BranchInst *BI = dyn_cast<BranchInst>(Curr)) {
2618 assert(BI->isConditional() &&
"uses a comparison!");
2621 BI->getSuccessor(NonNullIfTrue ? 0 : 1);
2625 }
else if (NonNullIfTrue &&
isGuard(Curr) &&
2626 DT->
dominates(cast<Instruction>(Curr), CtxI)) {
2640 const unsigned NumRanges = Ranges->getNumOperands() / 2;
2642 for (
unsigned i = 0; i < NumRanges; ++i) {
2644 mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 0));
2646 mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 1));
2658 Value *Start =
nullptr, *Step =
nullptr;
2659 const APInt *StartC, *StepC;
2665 case Instruction::Add:
2671 case Instruction::Mul:
2674 case Instruction::Shl:
2676 case Instruction::AShr:
2677 case Instruction::LShr:
2693 Value *
Y,
bool NSW,
bool NUW) {
2746 if (
auto *
C = dyn_cast<Constant>(
X))
2750 return ::isKnownNonEqual(
X,
Y, DemandedElts,
Depth, Q);
2755 Value *
Y,
bool NSW,
bool NUW) {
2784 auto ShiftOp = [&](
const APInt &Lhs,
const APInt &Rhs) {
2785 switch (
I->getOpcode()) {
2786 case Instruction::Shl:
2787 return Lhs.
shl(Rhs);
2788 case Instruction::LShr:
2789 return Lhs.
lshr(Rhs);
2790 case Instruction::AShr:
2791 return Lhs.
ashr(Rhs);
2797 auto InvShiftOp = [&](
const APInt &Lhs,
const APInt &Rhs) {
2798 switch (
I->getOpcode()) {
2799 case Instruction::Shl:
2800 return Lhs.
lshr(Rhs);
2801 case Instruction::LShr:
2802 case Instruction::AShr:
2803 return Lhs.
shl(Rhs);
2816 if (MaxShift.
uge(NumBits))
2819 if (!ShiftOp(KnownVal.
One, MaxShift).isZero())
2824 if (InvShiftOp(KnownVal.
Zero, NumBits - MaxShift)
2833 const APInt &DemandedElts,
2836 switch (
I->getOpcode()) {
2837 case Instruction::Alloca:
2839 return I->getType()->getPointerAddressSpace() == 0;
2840 case Instruction::GetElementPtr:
2841 if (
I->getType()->isPointerTy())
2844 case Instruction::BitCast: {
2872 Type *FromTy =
I->getOperand(0)->getType();
2877 case Instruction::IntToPtr:
2881 if (!isa<ScalableVectorType>(
I->getType()) &&
2886 case Instruction::PtrToInt:
2889 if (!isa<ScalableVectorType>(
I->getType()) &&
2894 case Instruction::Trunc:
2896 if (
auto *TI = dyn_cast<TruncInst>(
I))
2897 if (TI->hasNoSignedWrap() || TI->hasNoUnsignedWrap())
2901 case Instruction::Sub:
2904 case Instruction::Xor:
2909 case Instruction::Or:
2916 case Instruction::SExt:
2917 case Instruction::ZExt:
2921 case Instruction::Shl: {
2936 case Instruction::LShr:
2937 case Instruction::AShr: {
2952 case Instruction::UDiv:
2953 case Instruction::SDiv: {
2956 if (cast<PossiblyExactOperator>(
I)->isExact())
2968 if (
I->getOpcode() == Instruction::SDiv) {
2970 XKnown = XKnown.
abs(
false);
2971 YKnown = YKnown.
abs(
false);
2977 return XUgeY && *XUgeY;
2979 case Instruction::Add: {
2984 auto *BO = cast<OverflowingBinaryOperator>(
I);
2989 case Instruction::Mul: {
2995 case Instruction::Select: {
3002 auto SelectArmIsNonZero = [&](
bool IsTrueArm) {
3004 Op = IsTrueArm ?
I->getOperand(1) :
I->getOperand(2);
3017 Pred = ICmpInst::getInversePredicate(Pred);
3022 if (SelectArmIsNonZero(
true) &&
3023 SelectArmIsNonZero(
false))
3027 case Instruction::PHI: {
3028 auto *PN = cast<PHINode>(
I);
3038 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
3042 BasicBlock *TrueSucc, *FalseSucc;
3043 if (match(RecQ.CxtI,
3044 m_Br(m_c_ICmp(Pred, m_Specific(U.get()), m_Value(X)),
3045 m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc)))) {
3047 if ((TrueSucc == PN->getParent()) != (FalseSucc == PN->getParent())) {
3049 if (FalseSucc == PN->getParent())
3050 Pred = CmpInst::getInversePredicate(Pred);
3051 if (cmpExcludesZero(Pred, X))
3059 case Instruction::InsertElement: {
3060 if (isa<ScalableVectorType>(
I->getType()))
3063 const Value *Vec =
I->getOperand(0);
3064 const Value *Elt =
I->getOperand(1);
3065 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
3068 APInt DemandedVecElts = DemandedElts;
3069 bool SkipElt =
false;
3071 if (CIdx && CIdx->getValue().ult(NumElts)) {
3072 DemandedVecElts.
clearBit(CIdx->getZExtValue());
3073 SkipElt = !DemandedElts[CIdx->getZExtValue()];
3079 (DemandedVecElts.
isZero() ||
3082 case Instruction::ExtractElement:
3083 if (
const auto *EEI = dyn_cast<ExtractElementInst>(
I)) {
3084 const Value *Vec = EEI->getVectorOperand();
3085 const Value *
Idx = EEI->getIndexOperand();
3086 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
3087 if (
auto *VecTy = dyn_cast<FixedVectorType>(Vec->
getType())) {
3088 unsigned NumElts = VecTy->getNumElements();
3090 if (CIdx && CIdx->getValue().ult(NumElts))
3096 case Instruction::ShuffleVector: {
3097 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
3100 APInt DemandedLHS, DemandedRHS;
3106 return (DemandedRHS.
isZero() ||
3111 case Instruction::Freeze:
3115 case Instruction::Load: {
3116 auto *LI = cast<LoadInst>(
I);
3119 if (
auto *PtrT = dyn_cast<PointerType>(
I->getType())) {
3132 case Instruction::ExtractValue: {
3138 case Instruction::Add:
3143 case Instruction::Sub:
3146 case Instruction::Mul:
3155 case Instruction::Call:
3156 case Instruction::Invoke: {
3157 const auto *Call = cast<CallBase>(
I);
3158 if (
I->getType()->isPointerTy()) {
3159 if (Call->isReturnNonNull())
3166 if (std::optional<ConstantRange>
Range = Call->getRange()) {
3171 if (
const Value *RV = Call->getReturnedArgOperand())
3176 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
3177 switch (
II->getIntrinsicID()) {
3178 case Intrinsic::sshl_sat:
3179 case Intrinsic::ushl_sat:
3180 case Intrinsic::abs:
3181 case Intrinsic::bitreverse:
3182 case Intrinsic::bswap:
3183 case Intrinsic::ctpop:
3187 case Intrinsic::ssub_sat:
3189 II->getArgOperand(0),
II->getArgOperand(1));
3190 case Intrinsic::sadd_sat:
3192 II->getArgOperand(0),
II->getArgOperand(1),
3195 case Intrinsic::vector_reverse:
3199 case Intrinsic::vector_reduce_or:
3200 case Intrinsic::vector_reduce_umax:
3201 case Intrinsic::vector_reduce_umin:
3202 case Intrinsic::vector_reduce_smax:
3203 case Intrinsic::vector_reduce_smin:
3205 case Intrinsic::umax:
3206 case Intrinsic::uadd_sat:
3214 case Intrinsic::smax: {
3217 auto IsNonZero = [&](
Value *
Op, std::optional<bool> &OpNonZero,
3219 if (!OpNonZero.has_value())
3220 OpNonZero = OpKnown.isNonZero() ||
3225 std::optional<bool> Op0NonZero, Op1NonZero;
3229 IsNonZero(
II->getArgOperand(1), Op1NonZero, Op1Known))
3234 IsNonZero(
II->getArgOperand(0), Op0NonZero, Op0Known))
3236 return IsNonZero(
II->getArgOperand(1), Op1NonZero, Op1Known) &&
3237 IsNonZero(
II->getArgOperand(0), Op0NonZero, Op0Known);
3239 case Intrinsic::smin: {
3255 case Intrinsic::umin:
3258 case Intrinsic::cttz:
3261 case Intrinsic::ctlz:
3264 case Intrinsic::fshr:
3265 case Intrinsic::fshl:
3267 if (
II->getArgOperand(0) ==
II->getArgOperand(1))
3270 case Intrinsic::vscale:
3272 case Intrinsic::experimental_get_vector_length:
3286 return Known.
One != 0;
3297 Type *Ty = V->getType();
3302 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3304 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3305 "DemandedElt width should equal the fixed vector number of elements");
3308 "DemandedElt width should be 1 for scalars");
3312 if (
auto *
C = dyn_cast<Constant>(V)) {
3313 if (
C->isNullValue())
3315 if (isa<ConstantInt>(
C))
3321 if (
auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
3322 for (
unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) {
3323 if (!DemandedElts[i])
3325 Constant *Elt =
C->getAggregateElement(i);
3328 if (!isa<PoisonValue>(Elt) && !isa<ConstantInt>(Elt))
3335 if (
auto *CPA = dyn_cast<ConstantPtrAuth>(V))
3341 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
3342 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
3343 GV->getType()->getAddressSpace() == 0)
3348 if (!isa<ConstantExpr>(V))
3352 if (
const auto *
A = dyn_cast<Argument>(V))
3353 if (std::optional<ConstantRange>
Range =
A->getRange()) {
3368 if (
PointerType *PtrTy = dyn_cast<PointerType>(Ty)) {
3371 if (
const Argument *
A = dyn_cast<Argument>(V)) {
3372 if (((
A->hasPassPointeeByValueCopyAttr() &&
3374 A->hasNonNullAttr()))
3379 if (
const auto *
I = dyn_cast<Operator>(V))
3383 if (!isa<Constant>(V) &&
3392 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
3393 APInt DemandedElts =
3395 return ::isKnownNonZero(V, DemandedElts, Q,
Depth);
3404static std::optional<std::pair<Value*, Value*>>
3408 return std::nullopt;
3417 case Instruction::Or:
3418 if (!cast<PossiblyDisjointInst>(Op1)->isDisjoint() ||
3419 !cast<PossiblyDisjointInst>(Op2)->isDisjoint())
3422 case Instruction::Xor:
3423 case Instruction::Add: {
3431 case Instruction::Sub:
3437 case Instruction::Mul: {
3441 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
3442 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
3443 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
3444 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
3450 !cast<ConstantInt>(Op1->
getOperand(1))->isZero())
3454 case Instruction::Shl: {
3457 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
3458 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
3459 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
3460 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
3467 case Instruction::AShr:
3468 case Instruction::LShr: {
3469 auto *PEO1 = cast<PossiblyExactOperator>(Op1);
3470 auto *PEO2 = cast<PossiblyExactOperator>(Op2);
3471 if (!PEO1->isExact() || !PEO2->isExact())
3478 case Instruction::SExt:
3479 case Instruction::ZExt:
3483 case Instruction::PHI: {
3484 const PHINode *PN1 = cast<PHINode>(Op1);
3485 const PHINode *PN2 = cast<PHINode>(Op2);
3491 Value *Start1 =
nullptr, *Step1 =
nullptr;
3493 Value *Start2 =
nullptr, *Step2 =
nullptr;
3500 cast<Operator>(BO2));
3509 if (Values->first != PN1 || Values->second != PN2)
3512 return std::make_pair(Start1, Start2);
3515 return std::nullopt;
3530 case Instruction::Or:
3531 if (!cast<PossiblyDisjointInst>(V1)->isDisjoint())
3534 case Instruction::Xor:
3535 case Instruction::Add:
3553 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) {
3556 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
3557 !
C->isZero() && !
C->isOne() &&
3568 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) {
3571 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
3585 bool UsedFullRecursion =
false;
3587 if (!VisitedBBs.
insert(IncomBB).second)
3591 const APInt *C1, *C2;
3596 if (UsedFullRecursion)
3600 RecQ.
CxtI = IncomBB->getTerminator();
3603 UsedFullRecursion =
true;
3611 const SelectInst *SI1 = dyn_cast<SelectInst>(V1);
3615 if (
const SelectInst *SI2 = dyn_cast<SelectInst>(V2)) {
3617 const Value *Cond2 = SI2->getCondition();
3620 DemandedElts,
Depth + 1, Q) &&
3622 DemandedElts,
Depth + 1, Q);
3635 if (!
A->getType()->isPointerTy() || !
B->getType()->isPointerTy())
3638 auto *GEPA = dyn_cast<GEPOperator>(
A);
3639 if (!GEPA || GEPA->getNumIndices() != 1 || !isa<Constant>(GEPA->idx_begin()))
3643 auto *PN = dyn_cast<PHINode>(GEPA->getPointerOperand());
3644 if (!PN || PN->getNumIncomingValues() != 2)
3649 Value *Start =
nullptr;
3651 if (PN->getIncomingValue(0) == Step)
3652 Start = PN->getIncomingValue(1);
3653 else if (PN->getIncomingValue(1) == Step)
3654 Start = PN->getIncomingValue(0);
3665 APInt StartOffset(IndexWidth, 0);
3666 Start = Start->stripAndAccumulateInBoundsConstantOffsets(Q.
DL, StartOffset);
3667 APInt StepOffset(IndexWidth, 0);
3673 APInt OffsetB(IndexWidth, 0);
3674 B =
B->stripAndAccumulateInBoundsConstantOffsets(Q.
DL, OffsetB);
3675 return Start ==
B &&
3686 if (V1->
getType() != V2->getType())
3696 auto *O1 = dyn_cast<Operator>(V1);
3697 auto *O2 = dyn_cast<Operator>(V2);
3698 if (O1 && O2 && O1->getOpcode() == O2->getOpcode()) {
3703 if (
const PHINode *PN1 = dyn_cast<PHINode>(V1)) {
3704 const PHINode *PN2 = cast<PHINode>(V2);
3760 "Input should be a Select!");
3770 const Value *LHS2 =
nullptr, *RHS2 =
nullptr;
3782 return CLow->
sle(*CHigh);
3787 const APInt *&CHigh) {
3788 assert((
II->getIntrinsicID() == Intrinsic::smin ||
3789 II->getIntrinsicID() == Intrinsic::smax) &&
"Must be smin/smax");
3792 auto *InnerII = dyn_cast<IntrinsicInst>(
II->getArgOperand(0));
3793 if (!InnerII || InnerII->getIntrinsicID() != InverseID ||
3798 if (
II->getIntrinsicID() == Intrinsic::smin)
3800 return CLow->
sle(*CHigh);
3808 const APInt &DemandedElts,
3810 const auto *CV = dyn_cast<Constant>(V);
3811 if (!CV || !isa<FixedVectorType>(CV->getType()))
3814 unsigned MinSignBits = TyBits;
3815 unsigned NumElts = cast<FixedVectorType>(CV->getType())->getNumElements();
3816 for (
unsigned i = 0; i != NumElts; ++i) {
3817 if (!DemandedElts[i])
3820 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
3824 MinSignBits = std::min(MinSignBits, Elt->getValue().getNumSignBits());
3831 const APInt &DemandedElts,
3837 assert(Result > 0 &&
"At least one sign bit needs to be present!");
3849 const APInt &DemandedElts,
3851 Type *Ty = V->getType();
3855 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3857 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3858 "DemandedElt width should equal the fixed vector number of elements");
3861 "DemandedElt width should be 1 for scalars");
3875 unsigned FirstAnswer = 1;
3883 if (
auto *U = dyn_cast<Operator>(V)) {
3886 case Instruction::SExt:
3887 Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
3891 case Instruction::SDiv: {
3892 const APInt *Denominator;
3905 return std::min(TyBits, NumBits + Denominator->
logBase2());
3910 case Instruction::SRem: {
3913 const APInt *Denominator;
3934 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
3935 Tmp = std::max(Tmp, ResBits);
3941 case Instruction::AShr: {
3946 if (ShAmt->
uge(TyBits))
3949 Tmp += ShAmtLimited;
3950 if (Tmp > TyBits) Tmp = TyBits;
3954 case Instruction::Shl: {
3959 if (ShAmt->
uge(TyBits))
3964 ShAmt->
uge(TyBits -
X->getType()->getScalarSizeInBits())) {
3966 Tmp += TyBits -
X->getType()->getScalarSizeInBits();
3970 if (ShAmt->
uge(Tmp))
3977 case Instruction::And:
3978 case Instruction::Or:
3979 case Instruction::Xor:
3984 FirstAnswer = std::min(Tmp, Tmp2);
3991 case Instruction::Select: {
3995 const APInt *CLow, *CHigh;
4003 return std::min(Tmp, Tmp2);
4006 case Instruction::Add:
4010 if (Tmp == 1)
break;
4013 if (
const auto *CRHS = dyn_cast<Constant>(U->getOperand(1)))
4014 if (CRHS->isAllOnesValue()) {
4020 if ((Known.
Zero | 1).isAllOnes())
4032 return std::min(Tmp, Tmp2) - 1;
4034 case Instruction::Sub:
4040 if (
const auto *CLHS = dyn_cast<Constant>(U->getOperand(0)))
4041 if (CLHS->isNullValue()) {
4046 if ((Known.
Zero | 1).isAllOnes())
4063 return std::min(Tmp, Tmp2) - 1;
4065 case Instruction::Mul: {
4068 unsigned SignBitsOp0 =
4070 if (SignBitsOp0 == 1)
4072 unsigned SignBitsOp1 =
4074 if (SignBitsOp1 == 1)
4076 unsigned OutValidBits =
4077 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
4078 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
4081 case Instruction::PHI: {
4082 const PHINode *PN = cast<PHINode>(U);
4085 if (NumIncomingValues > 4)
break;
4087 if (NumIncomingValues == 0)
break;
4093 for (
unsigned i = 0, e = NumIncomingValues; i != e; ++i) {
4094 if (Tmp == 1)
return Tmp;
4097 DemandedElts,
Depth + 1, RecQ));
4102 case Instruction::Trunc: {
4107 unsigned OperandTyBits = U->getOperand(0)->getType()->getScalarSizeInBits();
4108 if (Tmp > (OperandTyBits - TyBits))
4109 return Tmp - (OperandTyBits - TyBits);
4114 case Instruction::ExtractElement:
4121 case Instruction::ShuffleVector: {
4124 auto *Shuf = dyn_cast<ShuffleVectorInst>(U);
4129 APInt DemandedLHS, DemandedRHS;
4134 Tmp = std::numeric_limits<unsigned>::max();
4135 if (!!DemandedLHS) {
4136 const Value *
LHS = Shuf->getOperand(0);
4143 if (!!DemandedRHS) {
4144 const Value *
RHS = Shuf->getOperand(1);
4146 Tmp = std::min(Tmp, Tmp2);
4152 assert(Tmp <= TyBits &&
"Failed to determine minimum sign bits");
4155 case Instruction::Call: {
4156 if (
const auto *
II = dyn_cast<IntrinsicInst>(U)) {
4157 switch (
II->getIntrinsicID()) {
4160 case Intrinsic::abs:
4168 case Intrinsic::smin:
4169 case Intrinsic::smax: {
4170 const APInt *CLow, *CHigh;
4185 if (
unsigned VecSignBits =
4203 if (
F->isIntrinsic())
4204 return F->getIntrinsicID();
4210 if (
F->hasLocalLinkage() || !TLI || !TLI->
getLibFunc(CB, Func) ||
4220 return Intrinsic::sin;
4224 return Intrinsic::cos;
4228 return Intrinsic::tan;
4232 return Intrinsic::asin;
4236 return Intrinsic::acos;
4240 return Intrinsic::atan;
4242 case LibFunc_atan2f:
4243 case LibFunc_atan2l:
4244 return Intrinsic::atan2;
4248 return Intrinsic::sinh;
4252 return Intrinsic::cosh;
4256 return Intrinsic::tanh;
4260 return Intrinsic::exp;
4264 return Intrinsic::exp2;
4266 case LibFunc_exp10f:
4267 case LibFunc_exp10l:
4268 return Intrinsic::exp10;
4272 return Intrinsic::log;
4274 case LibFunc_log10f:
4275 case LibFunc_log10l:
4276 return Intrinsic::log10;
4280 return Intrinsic::log2;
4284 return Intrinsic::fabs;
4288 return Intrinsic::minnum;
4292 return Intrinsic::maxnum;
4293 case LibFunc_copysign:
4294 case LibFunc_copysignf:
4295 case LibFunc_copysignl:
4296 return Intrinsic::copysign;
4298 case LibFunc_floorf:
4299 case LibFunc_floorl:
4300 return Intrinsic::floor;
4304 return Intrinsic::ceil;
4306 case LibFunc_truncf:
4307 case LibFunc_truncl:
4308 return Intrinsic::trunc;
4312 return Intrinsic::rint;
4313 case LibFunc_nearbyint:
4314 case LibFunc_nearbyintf:
4315 case LibFunc_nearbyintl:
4316 return Intrinsic::nearbyint;
4318 case LibFunc_roundf:
4319 case LibFunc_roundl:
4320 return Intrinsic::round;
4321 case LibFunc_roundeven:
4322 case LibFunc_roundevenf:
4323 case LibFunc_roundevenl:
4324 return Intrinsic::roundeven;
4328 return Intrinsic::pow;
4332 return Intrinsic::sqrt;
4380 switch (Mode.Input) {
4400 if (!Src.isKnownNeverPosZero() && !Src.isKnownNeverNegZero())
4404 if (Src.isKnownNeverSubnormal())
4434 bool &TrueIfSigned) {
4437 TrueIfSigned =
true;
4438 return RHS.isZero();
4440 TrueIfSigned =
true;
4441 return RHS.isAllOnes();
4443 TrueIfSigned =
false;
4444 return RHS.isAllOnes();
4446 TrueIfSigned =
false;
4447 return RHS.isZero();
4450 TrueIfSigned =
true;
4451 return RHS.isMaxSignedValue();
4454 TrueIfSigned =
true;
4455 return RHS.isMinSignedValue();
4458 TrueIfSigned =
false;
4459 return RHS.isMinSignedValue();
4462 TrueIfSigned =
false;
4463 return RHS.isMaxSignedValue();
4474 bool LookThroughSrc) {