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);
1074 "Input should be a Select!");
1084 const Value *LHS2 =
nullptr, *RHS2 =
nullptr;
1096 return CLow->
sle(*CHigh);
1101 const APInt *&CHigh) {
1102 assert((
II->getIntrinsicID() == Intrinsic::smin ||
1103 II->getIntrinsicID() == Intrinsic::smax) &&
1104 "Must be smin/smax");
1107 auto *InnerII = dyn_cast<IntrinsicInst>(
II->getArgOperand(0));
1108 if (!InnerII || InnerII->getIntrinsicID() != InverseID ||
1113 if (
II->getIntrinsicID() == Intrinsic::smin)
1115 return CLow->
sle(*CHigh);
1120 const APInt *CLow, *CHigh;
1127 const APInt &DemandedElts,
1133 switch (
I->getOpcode()) {
1135 case Instruction::Load:
1140 case Instruction::And:
1146 case Instruction::Or:
1152 case Instruction::Xor:
1158 case Instruction::Mul: {
1162 DemandedElts, Known, Known2,
Depth, Q);
1165 case Instruction::UDiv: {
1172 case Instruction::SDiv: {
1179 case Instruction::Select: {
1180 auto ComputeForArm = [&](
Value *Arm,
bool Invert) {
1188 ComputeForArm(
I->getOperand(1),
false)
1192 case Instruction::FPTrunc:
1193 case Instruction::FPExt:
1194 case Instruction::FPToUI:
1195 case Instruction::FPToSI:
1196 case Instruction::SIToFP:
1197 case Instruction::UIToFP:
1199 case Instruction::PtrToInt:
1200 case Instruction::IntToPtr:
1203 case Instruction::ZExt:
1204 case Instruction::Trunc: {
1205 Type *SrcTy =
I->getOperand(0)->getType();
1207 unsigned SrcBitWidth;
1215 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1218 if (
auto *Inst = dyn_cast<PossiblyNonNegInst>(
I);
1219 Inst && Inst->hasNonNeg() && !Known.
isNegative())
1224 case Instruction::BitCast: {
1225 Type *SrcTy =
I->getOperand(0)->getType();
1229 !
I->getType()->isVectorTy()) {
1237 V->getType()->isFPOrFPVectorTy()) {
1238 Type *FPType = V->getType()->getScalarType();
1251 if (FPClasses &
fcInf)
1263 if (Result.SignBit) {
1264 if (*Result.SignBit)
1274 auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcTy);
1275 if (!SrcVecTy || !SrcVecTy->getElementType()->isIntegerTy() ||
1276 !
I->getType()->isIntOrIntVectorTy() ||
1277 isa<ScalableVectorType>(
I->getType()))
1282 unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits();
1299 unsigned SubScale =
BitWidth / SubBitWidth;
1301 for (
unsigned i = 0; i != NumElts; ++i) {
1302 if (DemandedElts[i])
1303 SubDemandedElts.
setBit(i * SubScale);
1307 for (
unsigned i = 0; i != SubScale; ++i) {
1311 Known.
insertBits(KnownSrc, ShiftElt * SubBitWidth);
1316 case Instruction::SExt: {
1318 unsigned SrcBitWidth =
I->getOperand(0)->getType()->getScalarSizeInBits();
1320 Known = Known.
trunc(SrcBitWidth);
1327 case Instruction::Shl: {
1331 bool ShAmtNonZero) {
1332 return KnownBits::shl(KnownVal, KnownAmt, NUW, NSW, ShAmtNonZero);
1342 case Instruction::LShr: {
1343 bool Exact = Q.
IIQ.
isExact(cast<BinaryOperator>(
I));
1345 bool ShAmtNonZero) {
1356 case Instruction::AShr: {
1357 bool Exact = Q.
IIQ.
isExact(cast<BinaryOperator>(
I));
1359 bool ShAmtNonZero) {
1366 case Instruction::Sub: {
1370 DemandedElts, Known, Known2,
Depth, Q);
1373 case Instruction::Add: {
1377 DemandedElts, Known, Known2,
Depth, Q);
1380 case Instruction::SRem:
1386 case Instruction::URem:
1391 case Instruction::Alloca:
1394 case Instruction::GetElementPtr: {
1403 for (
unsigned i = 1, e =
I->getNumOperands(); i != e; ++i, ++GTI) {
1408 Value *Index =
I->getOperand(i);
1411 Constant *CIndex = dyn_cast<Constant>(Index);
1419 "Access to structure field must be known at compile time");
1424 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
1427 AccConstIndices +=
Offset;
1438 unsigned IndexBitWidth = Index->getType()->getScalarSizeInBits();
1452 APInt ScalingFactor(IndexBitWidth, TypeSizeInBytes);
1453 IndexConst *= ScalingFactor;
1477 case Instruction::PHI: {
1480 Value *R =
nullptr, *L =
nullptr;
1493 case Instruction::LShr:
1494 case Instruction::AShr:
1495 case Instruction::Shl:
1496 case Instruction::UDiv:
1503 case Instruction::URem: {
1516 case Instruction::Shl:
1520 case Instruction::LShr:
1521 case Instruction::UDiv:
1522 case Instruction::URem:
1527 case Instruction::AShr:
1539 case Instruction::Add:
1540 case Instruction::Sub:
1541 case Instruction::And:
1542 case Instruction::Or:
1543 case Instruction::Mul: {
1550 unsigned OpNum =
P->getOperand(0) == R ? 0 : 1;
1551 Instruction *RInst =
P->getIncomingBlock(OpNum)->getTerminator();
1552 Instruction *LInst =
P->getIncomingBlock(1 - OpNum)->getTerminator();
1567 auto *OverflowOp = dyn_cast<OverflowingBinaryOperator>(BO);
1581 case Instruction::Add: {
1591 case Instruction::Sub: {
1602 case Instruction::Mul:
1619 if (
P->getNumIncomingValues() == 0)
1626 if (isa_and_nonnull<UndefValue>(
P->hasConstantValue()))
1631 for (
unsigned u = 0, e =
P->getNumIncomingValues(); u < e; ++u) {
1632 Value *IncValue =
P->getIncomingValue(u);
1634 if (IncValue ==
P)
continue;
1638 if (
auto *SI = dyn_cast<SelectInst>(IncValue)) {
1639 if (SI->getTrueValue() ==
P || SI->getFalseValue() ==
P)
1640 IncValue = SI->getTrueValue() ==
P ? SI->getFalseValue()
1641 : SI->getTrueValue();
1649 RecQ.
CxtI =
P->getIncomingBlock(u)->getTerminator();
1671 if ((TrueSucc ==
P->getParent()) != (FalseSucc ==
P->getParent())) {
1673 if (FalseSucc ==
P->getParent())
1687 Known2 = KnownUnion;
1701 case Instruction::Call:
1702 case Instruction::Invoke: {
1710 const auto *CB = cast<CallBase>(
I);
1712 if (std::optional<ConstantRange>
Range = CB->getRange())
1715 if (
const Value *RV = CB->getReturnedArgOperand()) {
1716 if (RV->getType() ==
I->getType()) {
1728 switch (
II->getIntrinsicID()) {
1731 case Intrinsic::abs: {
1733 bool IntMinIsPoison =
match(
II->getArgOperand(1),
m_One());
1734 Known = Known2.
abs(IntMinIsPoison);
1737 case Intrinsic::bitreverse:
1742 case Intrinsic::bswap:
1747 case Intrinsic::ctlz: {
1753 PossibleLZ = std::min(PossibleLZ,
BitWidth - 1);
1758 case Intrinsic::cttz: {
1764 PossibleTZ = std::min(PossibleTZ,
BitWidth - 1);
1769 case Intrinsic::ctpop: {
1780 case Intrinsic::fshr:
1781 case Intrinsic::fshl: {
1788 if (
II->getIntrinsicID() == Intrinsic::fshr)
1801 case Intrinsic::uadd_sat:
1806 case Intrinsic::usub_sat:
1811 case Intrinsic::sadd_sat:
1816 case Intrinsic::ssub_sat:
1822 case Intrinsic::vector_reverse:
1828 case Intrinsic::vector_reduce_and:
1829 case Intrinsic::vector_reduce_or:
1830 case Intrinsic::vector_reduce_umax:
1831 case Intrinsic::vector_reduce_umin:
1832 case Intrinsic::vector_reduce_smax:
1833 case Intrinsic::vector_reduce_smin:
1836 case Intrinsic::vector_reduce_xor: {
1841 auto *VecTy = cast<VectorType>(
I->getOperand(0)->getType());
1843 bool EvenCnt = VecTy->getElementCount().isKnownEven();
1847 if (VecTy->isScalableTy() || EvenCnt)
1851 case Intrinsic::umin:
1856 case Intrinsic::umax:
1861 case Intrinsic::smin:
1867 case Intrinsic::smax:
1873 case Intrinsic::ptrmask: {
1876 const Value *Mask =
I->getOperand(1);
1877 Known2 =
KnownBits(Mask->getType()->getScalarSizeInBits());
1883 case Intrinsic::x86_sse2_pmulh_w:
1884 case Intrinsic::x86_avx2_pmulh_w:
1885 case Intrinsic::x86_avx512_pmulh_w_512:
1890 case Intrinsic::x86_sse2_pmulhu_w:
1891 case Intrinsic::x86_avx2_pmulhu_w:
1892 case Intrinsic::x86_avx512_pmulhu_w_512:
1897 case Intrinsic::x86_sse42_crc32_64_64:
1900 case Intrinsic::x86_ssse3_phadd_d_128:
1901 case Intrinsic::x86_ssse3_phadd_w_128:
1902 case Intrinsic::x86_avx2_phadd_d:
1903 case Intrinsic::x86_avx2_phadd_w: {
1905 I, DemandedElts,
Depth, Q,
1911 case Intrinsic::x86_ssse3_phadd_sw_128:
1912 case Intrinsic::x86_avx2_phadd_sw: {
1917 case Intrinsic::x86_ssse3_phsub_d_128:
1918 case Intrinsic::x86_ssse3_phsub_w_128:
1919 case Intrinsic::x86_avx2_phsub_d:
1920 case Intrinsic::x86_avx2_phsub_w: {
1922 I, DemandedElts,
Depth, Q,
1928 case Intrinsic::x86_ssse3_phsub_sw_128:
1929 case Intrinsic::x86_avx2_phsub_sw: {
1934 case Intrinsic::riscv_vsetvli:
1935 case Intrinsic::riscv_vsetvlimax: {
1936 bool HasAVL =
II->getIntrinsicID() == Intrinsic::riscv_vsetvli;
1939 cast<ConstantInt>(
II->getArgOperand(HasAVL))->getZExtValue());
1941 cast<ConstantInt>(
II->getArgOperand(1 + HasAVL))->getZExtValue());
1948 if (
auto *CI = dyn_cast<ConstantInt>(
II->getArgOperand(0)))
1949 MaxVL = std::min(MaxVL, CI->getZExtValue());
1951 unsigned KnownZeroFirstBit =
Log2_32(MaxVL) + 1;
1956 case Intrinsic::vscale: {
1957 if (!
II->getParent() || !
II->getFunction())
1967 case Instruction::ShuffleVector: {
1968 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
1976 APInt DemandedLHS, DemandedRHS;
1983 if (!!DemandedLHS) {
1984 const Value *
LHS = Shuf->getOperand(0);
1990 if (!!DemandedRHS) {
1991 const Value *
RHS = Shuf->getOperand(1);
1997 case Instruction::InsertElement: {
1998 if (isa<ScalableVectorType>(
I->getType())) {
2002 const Value *Vec =
I->getOperand(0);
2003 const Value *Elt =
I->getOperand(1);
2004 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
2006 APInt DemandedVecElts = DemandedElts;
2007 bool NeedsElt =
true;
2009 if (CIdx && CIdx->getValue().ult(NumElts)) {
2010 DemandedVecElts.
clearBit(CIdx->getZExtValue());
2011 NeedsElt = DemandedElts[CIdx->getZExtValue()];
2023 if (!DemandedVecElts.
isZero()) {
2029 case Instruction::ExtractElement: {
2032 const Value *Vec =
I->getOperand(0);
2034 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
2035 if (isa<ScalableVectorType>(Vec->
getType())) {
2040 unsigned NumElts = cast<FixedVectorType>(Vec->
getType())->getNumElements();
2042 if (CIdx && CIdx->getValue().ult(NumElts))
2047 case Instruction::ExtractValue:
2052 switch (
II->getIntrinsicID()) {
2054 case Intrinsic::uadd_with_overflow:
2055 case Intrinsic::sadd_with_overflow:
2057 true,
II->getArgOperand(0),
II->getArgOperand(1),
false,
2058 false, DemandedElts, Known, Known2,
Depth, Q);
2060 case Intrinsic::usub_with_overflow:
2061 case Intrinsic::ssub_with_overflow:
2063 false,
II->getArgOperand(0),
II->getArgOperand(1),
false,
2064 false, DemandedElts, Known, Known2,
Depth, Q);
2066 case Intrinsic::umul_with_overflow:
2067 case Intrinsic::smul_with_overflow:
2069 false, DemandedElts, Known, Known2,
Depth, Q);
2075 case Instruction::Freeze:
2119 if (!DemandedElts) {
2125 assert(V &&
"No Value?");
2129 Type *Ty = V->getType();
2133 "Not integer or pointer type!");
2135 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
2137 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
2138 "DemandedElt width should equal the fixed vector number of elements");
2141 "DemandedElt width should be 1 for scalars or scalable vectors");
2147 "V and Known should have same BitWidth");
2150 "V and Known should have same BitWidth");
2161 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
2168 assert(!isa<ScalableVectorType>(V->getType()));
2172 for (
unsigned i = 0, e = CDV->getNumElements(); i != e; ++i) {
2173 if (!DemandedElts[i])
2175 APInt Elt = CDV->getElementAsAPInt(i);
2184 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
2185 assert(!isa<ScalableVectorType>(V->getType()));
2189 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
2190 if (!DemandedElts[i])
2193 if (isa<PoisonValue>(Element))
2195 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
2200 const APInt &Elt = ElementCI->getValue();
2213 if (isa<UndefValue>(V))
2218 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
2220 if (
const auto *
A = dyn_cast<Argument>(V))
2221 if (std::optional<ConstantRange>
Range =
A->getRange())
2230 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
2231 if (!GA->isInterposable())
2236 if (
const Operator *
I = dyn_cast<Operator>(V))
2238 else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2239 if (std::optional<ConstantRange> CR = GV->getAbsoluteSymbolRange())
2240 Known = CR->toKnownBits();
2244 if (isa<PointerType>(V->getType())) {
2245 Align Alignment = V->getPointerAlignment(Q.
DL);
2261 Value *Start =
nullptr, *Step =
nullptr;
2267 if (U.get() == Start) {
2283 case Instruction::Mul:
2288 case Instruction::SDiv:
2294 case Instruction::UDiv:
2300 case Instruction::Shl:
2302 case Instruction::AShr:
2306 case Instruction::LShr:
2324 Pred = ICmpInst::getInversePredicate(Pred);
2326 if (OrZero && Pred == ICmpInst::ICMP_ULT && *RHSC == 2)
2329 return Pred == ICmpInst::ICMP_EQ && *RHSC == 1;
2340 if (isa<Constant>(V))
2344 if (OrZero && V->getType()->getScalarSizeInBits() == 1)
2379 auto *
I = dyn_cast<Instruction>(V);
2386 return F->hasFnAttribute(Attribute::VScaleRange);
2403 switch (
I->getOpcode()) {
2404 case Instruction::ZExt:
2406 case Instruction::Trunc:
2408 case Instruction::Shl:
2412 case Instruction::LShr:
2413 if (OrZero || Q.
IIQ.
isExact(cast<BinaryOperator>(
I)))
2416 case Instruction::UDiv:
2420 case Instruction::Mul:
2424 case Instruction::And:
2435 case Instruction::Add: {
2441 if (
match(
I->getOperand(0),
2445 if (
match(
I->getOperand(1),
2450 unsigned BitWidth = V->getType()->getScalarSizeInBits();
2459 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
2472 case Instruction::Select:
2475 case Instruction::PHI: {
2479 auto *PN = cast<PHINode>(
I);
2496 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
2497 return isKnownToBeAPowerOfTwo(U.get(), OrZero, NewDepth, RecQ);
2500 case Instruction::Invoke:
2501 case Instruction::Call: {
2502 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
2503 switch (
II->getIntrinsicID()) {
2504 case Intrinsic::umax:
2505 case Intrinsic::smax:
2506 case Intrinsic::umin:
2507 case Intrinsic::smin:
2512 case Intrinsic::bitreverse:
2513 case Intrinsic::bswap:
2515 case Intrinsic::fshr:
2516 case Intrinsic::fshl:
2518 if (
II->getArgOperand(0) ==
II->getArgOperand(1))
2542 F =
I->getFunction();
2546 if (!
GEP->hasNoUnsignedWrap() &&
2547 !(
GEP->isInBounds() &&
2552 assert(
GEP->getType()->isPointerTy() &&
"We only support plain pointer GEP");
2563 GTI != GTE; ++GTI) {
2565 if (
StructType *STy = GTI.getStructTypeOrNull()) {
2566 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
2570 if (ElementOffset > 0)
2576 if (GTI.getSequentialElementStride(Q.
DL).isZero())
2581 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
2605 assert(!isa<Constant>(V) &&
"Called for constant?");
2610 unsigned NumUsesExplored = 0;
2611 for (
const auto *U : V->users()) {
2619 if (
const auto *CB = dyn_cast<CallBase>(U))
2620 if (
auto *CalledFunc = CB->getCalledFunction())
2621 for (
const Argument &Arg : CalledFunc->args())
2622 if (CB->getArgOperand(Arg.getArgNo()) == V &&
2623 Arg.hasNonNullAttr(
false) &&
2631 V->getType()->getPointerAddressSpace()) &&
2649 NonNullIfTrue =
true;
2651 NonNullIfTrue =
false;
2657 for (
const auto *CmpU : U->users()) {
2659 if (Visited.
insert(CmpU).second)
2662 while (!WorkList.
empty()) {
2671 for (
const auto *CurrU : Curr->users())
2672 if (Visited.
insert(CurrU).second)
2677 if (
const BranchInst *BI = dyn_cast<BranchInst>(Curr)) {
2678 assert(BI->isConditional() &&
"uses a comparison!");
2681 BI->getSuccessor(NonNullIfTrue ? 0 : 1);
2685 }
else if (NonNullIfTrue &&
isGuard(Curr) &&
2686 DT->
dominates(cast<Instruction>(Curr), CtxI)) {
2700 const unsigned NumRanges = Ranges->getNumOperands() / 2;
2702 for (
unsigned i = 0; i < NumRanges; ++i) {
2704 mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 0));
2706 mdconst::extract<ConstantInt>(Ranges->getOperand(2 * i + 1));
2718 Value *Start =
nullptr, *Step =
nullptr;
2719 const APInt *StartC, *StepC;
2725 case Instruction::Add:
2731 case Instruction::Mul:
2734 case Instruction::Shl:
2736 case Instruction::AShr:
2737 case Instruction::LShr:
2753 Value *
Y,
bool NSW,
bool NUW) {
2806 if (
auto *
C = dyn_cast<Constant>(
X))
2810 return ::isKnownNonEqual(
X,
Y, DemandedElts,
Depth, Q);
2815 Value *
Y,
bool NSW,
bool NUW) {
2844 auto ShiftOp = [&](
const APInt &Lhs,
const APInt &Rhs) {
2845 switch (
I->getOpcode()) {
2846 case Instruction::Shl:
2847 return Lhs.
shl(Rhs);
2848 case Instruction::LShr:
2849 return Lhs.
lshr(Rhs);
2850 case Instruction::AShr:
2851 return Lhs.
ashr(Rhs);
2857 auto InvShiftOp = [&](
const APInt &Lhs,
const APInt &Rhs) {
2858 switch (
I->getOpcode()) {
2859 case Instruction::Shl:
2860 return Lhs.
lshr(Rhs);
2861 case Instruction::LShr:
2862 case Instruction::AShr:
2863 return Lhs.
shl(Rhs);
2876 if (MaxShift.
uge(NumBits))
2879 if (!ShiftOp(KnownVal.
One, MaxShift).isZero())
2884 if (InvShiftOp(KnownVal.
Zero, NumBits - MaxShift)
2893 const APInt &DemandedElts,
2896 switch (
I->getOpcode()) {
2897 case Instruction::Alloca:
2899 return I->getType()->getPointerAddressSpace() == 0;
2900 case Instruction::GetElementPtr:
2901 if (
I->getType()->isPointerTy())
2904 case Instruction::BitCast: {
2932 Type *FromTy =
I->getOperand(0)->getType();
2937 case Instruction::IntToPtr:
2941 if (!isa<ScalableVectorType>(
I->getType()) &&
2946 case Instruction::PtrToInt:
2949 if (!isa<ScalableVectorType>(
I->getType()) &&
2954 case Instruction::Trunc:
2956 if (
auto *TI = dyn_cast<TruncInst>(
I))
2957 if (TI->hasNoSignedWrap() || TI->hasNoUnsignedWrap())
2961 case Instruction::Sub:
2964 case Instruction::Xor:
2969 case Instruction::Or:
2976 case Instruction::SExt:
2977 case Instruction::ZExt:
2981 case Instruction::Shl: {
2996 case Instruction::LShr:
2997 case Instruction::AShr: {
3012 case Instruction::UDiv:
3013 case Instruction::SDiv: {
3016 if (cast<PossiblyExactOperator>(
I)->isExact())
3028 if (
I->getOpcode() == Instruction::SDiv) {
3030 XKnown = XKnown.
abs(
false);
3031 YKnown = YKnown.
abs(
false);
3037 return XUgeY && *XUgeY;
3039 case Instruction::Add: {
3044 auto *BO = cast<OverflowingBinaryOperator>(
I);
3049 case Instruction::Mul: {
3055 case Instruction::Select: {
3062 auto SelectArmIsNonZero = [&](
bool IsTrueArm) {
3064 Op = IsTrueArm ?
I->getOperand(1) :
I->getOperand(2);
3077 Pred = ICmpInst::getInversePredicate(Pred);
3082 if (SelectArmIsNonZero(
true) &&
3083 SelectArmIsNonZero(
false))
3087 case Instruction::PHI: {
3088 auto *PN = cast<PHINode>(
I);
3098 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
3102 BasicBlock *TrueSucc, *FalseSucc;
3103 if (match(RecQ.CxtI,
3104 m_Br(m_c_ICmp(Pred, m_Specific(U.get()), m_Value(X)),
3105 m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc)))) {
3107 if ((TrueSucc == PN->getParent()) != (FalseSucc == PN->getParent())) {
3109 if (FalseSucc == PN->getParent())
3110 Pred = CmpInst::getInversePredicate(Pred);
3111 if (cmpExcludesZero(Pred, X))
3119 case Instruction::InsertElement: {
3120 if (isa<ScalableVectorType>(
I->getType()))
3123 const Value *Vec =
I->getOperand(0);
3124 const Value *Elt =
I->getOperand(1);
3125 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
3128 APInt DemandedVecElts = DemandedElts;
3129 bool SkipElt =
false;
3131 if (CIdx && CIdx->getValue().ult(NumElts)) {
3132 DemandedVecElts.
clearBit(CIdx->getZExtValue());
3133 SkipElt = !DemandedElts[CIdx->getZExtValue()];
3139 (DemandedVecElts.
isZero() ||
3142 case Instruction::ExtractElement:
3143 if (
const auto *EEI = dyn_cast<ExtractElementInst>(
I)) {
3144 const Value *Vec = EEI->getVectorOperand();
3145 const Value *
Idx = EEI->getIndexOperand();
3146 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
3147 if (
auto *VecTy = dyn_cast<FixedVectorType>(Vec->
getType())) {
3148 unsigned NumElts = VecTy->getNumElements();
3150 if (CIdx && CIdx->getValue().ult(NumElts))
3156 case Instruction::ShuffleVector: {
3157 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
3160 APInt DemandedLHS, DemandedRHS;
3166 return (DemandedRHS.
isZero() ||
3171 case Instruction::Freeze:
3175 case Instruction::Load: {
3176 auto *LI = cast<LoadInst>(
I);
3179 if (
auto *PtrT = dyn_cast<PointerType>(
I->getType())) {
3192 case Instruction::ExtractValue: {
3198 case Instruction::Add:
3203 case Instruction::Sub:
3206 case Instruction::Mul:
3215 case Instruction::Call:
3216 case Instruction::Invoke: {
3217 const auto *Call = cast<CallBase>(
I);
3218 if (
I->getType()->isPointerTy()) {
3219 if (Call->isReturnNonNull())
3226 if (std::optional<ConstantRange>
Range = Call->getRange()) {
3231 if (
const Value *RV = Call->getReturnedArgOperand())
3236 if (
auto *
II = dyn_cast<IntrinsicInst>(
I)) {
3237 switch (
II->getIntrinsicID()) {
3238 case Intrinsic::sshl_sat:
3239 case Intrinsic::ushl_sat:
3240 case Intrinsic::abs:
3241 case Intrinsic::bitreverse:
3242 case Intrinsic::bswap:
3243 case Intrinsic::ctpop:
3247 case Intrinsic::ssub_sat:
3249 II->getArgOperand(0),
II->getArgOperand(1));
3250 case Intrinsic::sadd_sat:
3252 II->getArgOperand(0),
II->getArgOperand(1),
3255 case Intrinsic::vector_reverse:
3259 case Intrinsic::vector_reduce_or:
3260 case Intrinsic::vector_reduce_umax:
3261 case Intrinsic::vector_reduce_umin:
3262 case Intrinsic::vector_reduce_smax:
3263 case Intrinsic::vector_reduce_smin:
3265 case Intrinsic::umax:
3266 case Intrinsic::uadd_sat:
3274 case Intrinsic::smax: {
3277 auto IsNonZero = [&](
Value *
Op, std::optional<bool> &OpNonZero,
3279 if (!OpNonZero.has_value())
3280 OpNonZero = OpKnown.isNonZero() ||
3285 std::optional<bool> Op0NonZero, Op1NonZero;
3289 IsNonZero(
II->getArgOperand(1), Op1NonZero, Op1Known))
3294 IsNonZero(
II->getArgOperand(0), Op0NonZero, Op0Known))
3296 return IsNonZero(
II->getArgOperand(1), Op1NonZero, Op1Known) &&
3297 IsNonZero(
II->getArgOperand(0), Op0NonZero, Op0Known);
3299 case Intrinsic::smin: {
3315 case Intrinsic::umin:
3318 case Intrinsic::cttz:
3321 case Intrinsic::ctlz:
3324 case Intrinsic::fshr:
3325 case Intrinsic::fshl:
3327 if (
II->getArgOperand(0) ==
II->getArgOperand(1))
3330 case Intrinsic::vscale:
3332 case Intrinsic::experimental_get_vector_length:
3346 return Known.
One != 0;
3357 Type *Ty = V->getType();
3362 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3364 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3365 "DemandedElt width should equal the fixed vector number of elements");
3368 "DemandedElt width should be 1 for scalars");
3372 if (
auto *
C = dyn_cast<Constant>(V)) {
3373 if (
C->isNullValue())
3375 if (isa<ConstantInt>(
C))
3381 if (
auto *VecTy = dyn_cast<FixedVectorType>(Ty)) {
3382 for (
unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) {
3383 if (!DemandedElts[i])
3385 Constant *Elt =
C->getAggregateElement(i);
3388 if (!isa<PoisonValue>(Elt) && !isa<ConstantInt>(Elt))
3395 if (
auto *CPA = dyn_cast<ConstantPtrAuth>(V))
3401 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
3402 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
3403 GV->getType()->getAddressSpace() == 0)
3408 if (!isa<ConstantExpr>(V))
3412 if (
const auto *
A = dyn_cast<Argument>(V))
3413 if (std::optional<ConstantRange>
Range =
A->getRange()) {
3428 if (
PointerType *PtrTy = dyn_cast<PointerType>(Ty)) {
3431 if (
const Argument *
A = dyn_cast<Argument>(V)) {
3432 if (((
A->hasPassPointeeByValueCopyAttr() &&
3434 A->hasNonNullAttr()))
3439 if (
const auto *
I = dyn_cast<Operator>(V))
3443 if (!isa<Constant>(V) &&
3452 auto *FVTy = dyn_cast<FixedVectorType>(V->getType());
3453 APInt DemandedElts =
3455 return ::isKnownNonZero(V, DemandedElts, Q,
Depth);
3464static std::optional<std::pair<Value*, Value*>>
3468 return std::nullopt;
3477 case Instruction::Or:
3478 if (!cast<PossiblyDisjointInst>(Op1)->isDisjoint() ||
3479 !cast<PossiblyDisjointInst>(Op2)->isDisjoint())
3482 case Instruction::Xor:
3483 case Instruction::Add: {
3491 case Instruction::Sub:
3497 case Instruction::Mul: {
3501 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
3502 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
3503 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
3504 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
3510 !cast<ConstantInt>(Op1->
getOperand(1))->isZero())
3514 case Instruction::Shl: {
3517 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
3518 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
3519 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
3520 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
3527 case Instruction::AShr:
3528 case Instruction::LShr: {
3529 auto *PEO1 = cast<PossiblyExactOperator>(Op1);
3530 auto *PEO2 = cast<PossiblyExactOperator>(Op2);
3531 if (!PEO1->isExact() || !PEO2->isExact())
3538 case Instruction::SExt:
3539 case Instruction::ZExt:
3543 case Instruction::PHI: {
3544 const PHINode *PN1 = cast<PHINode>(Op1);
3545 const PHINode *PN2 = cast<PHINode>(Op2);
3551 Value *Start1 =
nullptr, *Step1 =
nullptr;
3553 Value *Start2 =
nullptr, *Step2 =
nullptr;
3560 cast<Operator>(BO2));
3569 if (Values->first != PN1 || Values->second != PN2)
3572 return std::make_pair(Start1, Start2);
3575 return std::nullopt;
3590 case Instruction::Or:
3591 if (!cast<PossiblyDisjointInst>(V1)->isDisjoint())
3594 case Instruction::Xor:
3595 case Instruction::Add:
3613 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) {
3616 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
3617 !
C->isZero() && !
C->isOne() &&
3628 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) {
3631 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
3645 bool UsedFullRecursion =
false;
3647 if (!VisitedBBs.
insert(IncomBB).second)
3651 const APInt *C1, *C2;
3656 if (UsedFullRecursion)
3660 RecQ.
CxtI = IncomBB->getTerminator();
3663 UsedFullRecursion =
true;
3671 const SelectInst *SI1 = dyn_cast<SelectInst>(V1);
3675 if (
const SelectInst *SI2 = dyn_cast<SelectInst>(V2)) {
3677 const Value *Cond2 = SI2->getCondition();
3680 DemandedElts,
Depth + 1, Q) &&
3682 DemandedElts,
Depth + 1, Q);
3695 if (!
A->getType()->isPointerTy() || !
B->getType()->isPointerTy())
3698 auto *GEPA = dyn_cast<GEPOperator>(
A);
3699 if (!GEPA || GEPA->getNumIndices() != 1 || !isa<Constant>(GEPA->idx_begin()))
3703 auto *PN = dyn_cast<PHINode>(GEPA->getPointerOperand());
3704 if (!PN || PN->getNumIncomingValues() != 2)
3709 Value *Start =
nullptr;
3711 if (PN->getIncomingValue(0) == Step)
3712 Start = PN->getIncomingValue(1);
3713 else if (PN->getIncomingValue(1) == Step)
3714 Start = PN->getIncomingValue(0);
3725 APInt StartOffset(IndexWidth, 0);
3726 Start = Start->stripAndAccumulateInBoundsConstantOffsets(Q.
DL, StartOffset);
3727 APInt StepOffset(IndexWidth, 0);
3733 APInt OffsetB(IndexWidth, 0);
3734 B =
B->stripAndAccumulateInBoundsConstantOffsets(Q.
DL, OffsetB);
3735 return Start ==
B &&
3746 if (V1->
getType() != V2->getType())
3756 auto *O1 = dyn_cast<Operator>(V1);
3757 auto *O2 = dyn_cast<Operator>(V2);
3758 if (O1 && O2 && O1->getOpcode() == O2->getOpcode()) {
3763 if (
const PHINode *PN1 = dyn_cast<PHINode>(V1)) {
3764 const PHINode *PN2 = cast<PHINode>(V2);
3819 const APInt &DemandedElts,
3821 const auto *CV = dyn_cast<Constant>(V);
3822 if (!CV || !isa<FixedVectorType>(CV->getType()))
3825 unsigned MinSignBits = TyBits;
3826 unsigned NumElts = cast<FixedVectorType>(CV->getType())->getNumElements();
3827 for (
unsigned i = 0; i != NumElts; ++i) {
3828 if (!DemandedElts[i])
3831 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
3835 MinSignBits = std::min(MinSignBits, Elt->getValue().getNumSignBits());
3842 const APInt &DemandedElts,
3848 assert(Result > 0 &&
"At least one sign bit needs to be present!");
3860 const APInt &DemandedElts,
3862 Type *Ty = V->getType();
3866 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3868 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3869 "DemandedElt width should equal the fixed vector number of elements");
3872 "DemandedElt width should be 1 for scalars");
3886 unsigned FirstAnswer = 1;
3894 if (
auto *U = dyn_cast<Operator>(V)) {
3897 case Instruction::SExt:
3898 Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
3902 case Instruction::SDiv: {
3903 const APInt *Denominator;
3916 return std::min(TyBits, NumBits + Denominator->
logBase2());
3921 case Instruction::SRem: {
3924 const APInt *Denominator;
3945 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
3946 Tmp = std::max(Tmp, ResBits);
3952 case Instruction::AShr: {
3957 if (ShAmt->
uge(TyBits))
3960 Tmp += ShAmtLimited;
3961 if (Tmp > TyBits) Tmp = TyBits;
3965 case Instruction::Shl: {
3970 if (ShAmt->
uge(TyBits))
3975 ShAmt->
uge(TyBits -
X->getType()->getScalarSizeInBits())) {
3977 Tmp += TyBits -
X->getType()->getScalarSizeInBits();
3981 if (ShAmt->
uge(Tmp))
3988 case Instruction::And:
3989 case Instruction::Or:
3990 case Instruction::Xor:
3995 FirstAnswer = std::min(Tmp, Tmp2);
4002 case Instruction::Select: {
4006 const APInt *CLow, *CHigh;
4014 return std::min(Tmp, Tmp2);
4017 case Instruction::Add:
4021 if (Tmp == 1)
break;
4024 if (
const auto *CRHS = dyn_cast<Constant>(U->getOperand(1)))
4025 if (CRHS->isAllOnesValue()) {
4031 if ((Known.
Zero | 1).isAllOnes())
4043 return std::min(Tmp, Tmp2) - 1;
4045 case Instruction::Sub:
4051 if (
const auto *CLHS = dyn_cast<Constant>(U->getOperand(0)))
4052 if (CLHS->isNullValue()) {
4057 if ((Known.
Zero | 1).isAllOnes())
4074 return std::min(Tmp, Tmp2) - 1;
4076 case Instruction::Mul: {
4079 unsigned SignBitsOp0 =
4081 if (SignBitsOp0 == 1)
4083 unsigned SignBitsOp1 =
4085 if (SignBitsOp1 == 1)
4087 unsigned OutValidBits =
4088 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
4089 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
4092 case Instruction::PHI: {
4093 const PHINode *PN = cast<PHINode>(U);
4096 if (NumIncomingValues > 4)
break;
4098 if (NumIncomingValues == 0)
break;
4104 for (
unsigned i = 0, e = NumIncomingValues; i != e; ++i) {
4105 if (Tmp == 1)
return Tmp;
4108 DemandedElts,
Depth + 1, RecQ));
4113 case Instruction::Trunc: {
4118 unsigned OperandTyBits = U->getOperand(0)->getType()->getScalarSizeInBits();
4119 if (Tmp > (OperandTyBits - TyBits))
4120 return Tmp - (OperandTyBits - TyBits);
4125 case Instruction::ExtractElement:
4132 case Instruction::ShuffleVector: {
4135 auto *Shuf = dyn_cast<ShuffleVectorInst>(U);
4140 APInt DemandedLHS, DemandedRHS;
4145 Tmp = std::numeric_limits<unsigned>::max();
4146 if (!!DemandedLHS) {
4147 const Value *
LHS = Shuf->getOperand(0);
4154 if (!!DemandedRHS) {
4155 const Value *
RHS = Shuf->getOperand(1);
4157 Tmp = std::min(Tmp, Tmp2);
4163 assert(Tmp <= TyBits &&
"Failed to determine minimum sign bits");
4166 case Instruction::Call: {
4167 if (
const auto *
II = dyn_cast<IntrinsicInst>(U)) {
4168 switch (
II->getIntrinsicID()) {
4171 case Intrinsic::abs:
4179 case Intrinsic::smin:
4180 case Intrinsic::smax: {
4181 const APInt *CLow, *CHigh;
4196 if (
unsigned VecSignBits =
4214 if (
F->isIntrinsic())
4215 return F->getIntrinsicID();
4221 if (
F->hasLocalLinkage() || !TLI || !TLI->
getLibFunc(CB, Func) ||
4231 return Intrinsic::sin;
4235 return Intrinsic::cos;
4239 return Intrinsic::tan;
4243 return Intrinsic::asin;
4247 return Intrinsic::acos;
4251 return Intrinsic::atan;
4253 case LibFunc_atan2f:
4254 case LibFunc_atan2l:
4255 return Intrinsic::atan2;
4259 return Intrinsic::sinh;
4263 return Intrinsic::cosh;
4267 return Intrinsic::tanh;
4271 return Intrinsic::exp;
4275 return Intrinsic::exp2;
4277 case LibFunc_exp10f:
4278 case LibFunc_exp10l:
4279 return Intrinsic::exp10;
4283 return Intrinsic::log;
4285 case LibFunc_log10f:
4286 case LibFunc_log10l:
4287 return Intrinsic::log10;
4291 return Intrinsic::log2;
4295 return Intrinsic::fabs;
4299 return Intrinsic::minnum;
4303 return Intrinsic::maxnum;
4304 case LibFunc_copysign:
4305 case LibFunc_copysignf:
4306 case LibFunc_copysignl:
4307 return Intrinsic::copysign;
4309 case LibFunc_floorf:
4310 case LibFunc_floorl:
4311 return Intrinsic::floor;
4315 return Intrinsic::ceil;
4317 case LibFunc_truncf:
4318 case LibFunc_truncl:
4319 return Intrinsic::trunc;
4323 return Intrinsic::rint;
4324 case LibFunc_nearbyint:
4325 case LibFunc_nearbyintf:
4326 case LibFunc_nearbyintl:
4327 return Intrinsic::nearbyint;
4329 case LibFunc_roundf:
4330 case LibFunc_roundl:
4331 return Intrinsic::round;
4332 case LibFunc_roundeven:
4333 case LibFunc_roundevenf:
4334 case LibFunc_roundevenl:
4335 return Intrinsic::roundeven;
4339 return Intrinsic::pow;
4343 return Intrinsic::sqrt;
4391 switch (Mode.Input) {
4411 if (!Src.isKnownNeverPosZero() && !Src.isKnownNeverNegZero())
4415 if (Src.isKnownNeverSubnormal())
4445 bool &TrueIfSigned) {
4448 TrueIfSigned =
true;
4449 return RHS.isZero();
4451 TrueIfSigned =
true;
4452 return RHS.isAllOnes();
4454 TrueIfSigned =
false;
4455 return RHS.isAllOnes();
4457 TrueIfSigned =
false;
4458 return RHS.isZero();
4461 TrueIfSigned =
true;
4462 return RHS.isMaxSignedValue();
4465 TrueIfSigned =
true;
4466 return RHS.isMinSignedValue();
4469 TrueIfSigned =
false;
4470 return RHS.isMinSignedValue();
4473 TrueIfSigned =
false;
4474 return RHS.isMaxSignedValue();