119 std::array<const Value *, MaxDepth> Excluded;
121 unsigned NumExcluded = 0;
125 : DL(DL), AC(AC), CxtI(CxtI), DT(DT), ORE(ORE) {}
128 : DL(Q.DL), AC(Q.AC), CxtI(Q.CxtI), DT(Q.DT), ORE(Q.ORE),
129 NumExcluded(Q.NumExcluded) {
130 Excluded = Q.Excluded;
131 Excluded[NumExcluded++] = NewExcl;
132 assert(NumExcluded <= Excluded.size());
136 if (NumExcluded == 0)
138 auto End = Excluded.begin() + NumExcluded;
139 return std::find(Excluded.begin(), End, Value) != End;
190 "LHS and RHS should have the same type");
192 "LHS and RHS should be integers");
206 return (LHSKnown.Zero | RHSKnown.Zero).isAllOnesValue();
211 if (
const ICmpInst *IC = dyn_cast<ICmpInst>(U))
212 if (IC->isEquality())
213 if (
Constant *
C = dyn_cast<Constant>(IC->getOperand(1)))
214 if (
C->isNullValue())
252 if (
auto *CI = dyn_cast<ConstantInt>(V))
253 return CI->getValue().isStrictlyPositive();
303 unsigned Depth,
const Query &Q) {
317 unsigned Depth,
const Query &Q) {
328 isKnownNonNegative =
true;
333 bool isKnownNegativeOp0 = Known2.
isNegative();
335 isKnownNonNegative = (isKnownNegativeOp1 && isKnownNegativeOp0) ||
336 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
339 if (!isKnownNonNegative)
340 isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
342 (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
351 BitWidth) - BitWidth;
352 LeadZ = std::min(LeadZ, BitWidth);
405 unsigned TrailZ = TrailZero0 + TrailZero1;
408 unsigned SmallestOperand = std::min(TrailBitsKnown0 - TrailZero0,
409 TrailBitsKnown1 - TrailZero1);
410 unsigned ResultBitsKnown = std::min(SmallestOperand + TrailZ, BitWidth);
417 Known.
Zero |= (~BottomKnown).getLoBits(ResultBitsKnown);
425 if (isKnownNonNegative && !Known.
isNegative())
440 for (
unsigned i = 0; i < NumRanges; ++i) {
442 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 0));
444 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 1));
448 unsigned CommonPrefixBits =
452 Known.
One &= Range.getUnsignedMax() &
Mask;
453 Known.
Zero &= ~Range.getUnsignedMax() &
Mask;
468 while (!WorkSet.
empty()) {
470 if (!Visited.
insert(V).second)
475 return EphValues.
count(U);
482 if (
const User *U = dyn_cast<User>(V))
495 if (
const CallInst *CI = dyn_cast<CallInst>(I))
496 if (
Function *
F = CI->getCalledFunction())
497 switch (
F->getIntrinsicID()) {
500 case Intrinsic::assume:
501 case Intrinsic::sideeffect:
502 case Intrinsic::dbg_declare:
503 case Intrinsic::dbg_value:
504 case Intrinsic::dbg_label:
505 case Intrinsic::invariant_start:
506 case Intrinsic::invariant_end:
507 case Intrinsic::lifetime_start:
508 case Intrinsic::lifetime_end:
509 case Intrinsic::objectsize:
510 case Intrinsic::ptr_annotation:
511 case Intrinsic::var_annotation:
566 unsigned Depth,
const Query &Q) {
569 if (!Q.AC || !Q.CxtI)
577 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
582 "Got assumption for the wrong function!");
591 "must be an assume intrinsic");
596 assert(BitWidth == 1 &&
"assume operand is not i1?");
602 assert(BitWidth == 1 &&
"assume operand is not i1?");
608 if (Depth == MaxDepth)
624 Known.
One |= RHSKnown.
One;
626 }
else if (
match(Arg,
638 Known.
One |= RHSKnown.
One & MaskKnown.
One;
654 }
else if (
match(Arg,
682 }
else if (
match(Arg,
728 Known.
One |= RHSKnown.
One;
744 }
else if (
match(Arg,
755 Known.
One |= RHSKnown.
One <<
C;
858 <<
"Detected conflicting code assumptions. Program may " 859 "have undefined behavior, or compiler may have " 875 unsigned Depth,
const Query &Q,
880 if (
auto *SA = dyn_cast<ConstantInt>(I->
getOperand(1))) {
881 unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
884 Known.
Zero = KZF(Known.
Zero, ShiftAmt);
885 Known.
One = KOF(Known.
One, ShiftAmt);
900 if ((~Known.
Zero).uge(BitWidth)) {
924 if (!*ShifterOperandIsNonZero)
932 for (
unsigned ShiftAmt = 0; ShiftAmt < BitWidth; ++ShiftAmt) {
935 if ((ShiftAmt & ~ShiftAmtKZ) != ShiftAmt)
937 if ((ShiftAmt | ShiftAmtKO) != ShiftAmt)
943 if (!ShifterOperandIsNonZero.
hasValue())
944 ShifterOperandIsNonZero =
946 if (*ShifterOperandIsNonZero)
950 Known.
Zero &= KZF(Known2.
Zero, ShiftAmt);
951 Known.
One &= KOF(Known2.
One, ShiftAmt);
961 unsigned Depth,
const Query &Q) {
971 case Instruction::And: {
986 Value *
X =
nullptr, *
Y =
nullptr;
987 if (!Known.
Zero[0] && !Known.
One[0] &&
996 case Instruction::Or:
1005 case Instruction::Xor: {
1013 Known.
Zero = std::move(KnownZeroOut);
1016 case Instruction::Mul: {
1017 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1022 case Instruction::UDiv: {
1032 if (RHSMaxLeadingZeros != BitWidth)
1033 LeadZ = std::min(BitWidth, LeadZ + BitWidth - RHSMaxLeadingZeros - 1);
1039 const Value *LHS, *RHS;
1049 unsigned MaxHighOnes = 0;
1050 unsigned MaxHighZeros = 0;
1085 if (cast<Instruction>(RHS)->hasNoSignedWrap())
1092 if (MaxHighOnes > 0)
1094 if (MaxHighZeros > 0)
1098 case Instruction::FPTrunc:
1099 case Instruction::FPExt:
1100 case Instruction::FPToUI:
1101 case Instruction::FPToSI:
1102 case Instruction::SIToFP:
1103 case Instruction::UIToFP:
1105 case Instruction::PtrToInt:
1106 case Instruction::IntToPtr:
1109 case Instruction::ZExt:
1110 case Instruction::Trunc: {
1113 unsigned SrcBitWidth;
1118 Q.DL.getIndexTypeSizeInBits(ScalarTy) :
1119 Q.DL.getTypeSizeInBits(ScalarTy);
1121 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1126 if (BitWidth > SrcBitWidth)
1130 case Instruction::BitCast: {
1141 case Instruction::SExt: {
1145 Known = Known.
trunc(SrcBitWidth);
1149 Known = Known.
sext(BitWidth);
1152 case Instruction::Shl: {
1154 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1155 auto KZF = [NSW](
const APInt &KnownZero,
unsigned ShiftAmt) {
1156 APInt KZResult = KnownZero << ShiftAmt;
1165 auto KOF = [NSW](
const APInt &KnownOne,
unsigned ShiftAmt) {
1166 APInt KOResult = KnownOne << ShiftAmt;
1175 case Instruction::LShr: {
1177 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1178 APInt KZResult = KnownZero.
lshr(ShiftAmt);
1184 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1185 return KnownOne.
lshr(ShiftAmt);
1191 case Instruction::AShr: {
1193 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1194 return KnownZero.
ashr(ShiftAmt);
1197 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1198 return KnownOne.
ashr(ShiftAmt);
1204 case Instruction::Sub: {
1205 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1207 Known, Known2,
Depth, Q);
1211 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1213 Known, Known2,
Depth, Q);
1216 case Instruction::SRem:
1218 APInt RA = Rem->getValue().abs();
1220 APInt LowBits = RA - 1;
1224 Known.
Zero = Known2.
Zero & LowBits;
1225 Known.
One = Known2.
One & LowBits;
1230 Known.
Zero |= ~LowBits;
1235 Known.
One |= ~LowBits;
1237 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1250 case Instruction::URem: {
1252 const APInt &
RA = Rem->getValue();
1254 APInt LowBits = (RA - 1);
1256 Known.
Zero |= ~LowBits;
1257 Known.
One &= LowBits;
1274 case Instruction::Alloca: {
1284 case Instruction::GetElementPtr: {
1292 for (
unsigned i = 1, e = I->
getNumOperands(); i != e; ++i, ++GTI) {
1305 unsigned Idx = cast<ConstantInt>(
Index)->getZExtValue();
1308 TrailZ = std::min<unsigned>(TrailZ,
1318 uint64_t TypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1319 LocalKnown.
Zero = LocalKnown.
One =
APInt(GEPOpiBits, 0);
1321 TrailZ = std::min(TrailZ,
1330 case Instruction::PHI: {
1336 for (
unsigned i = 0; i != 2; ++i) {
1347 Opcode == Instruction::Sub ||
1348 Opcode == Instruction::And ||
1349 Opcode == Instruction::Or ||
1350 Opcode == Instruction::Mul) {
1372 if (OverflowOp && OverflowOp->hasNoSignedWrap()) {
1391 else if (Opcode == Instruction::Sub && LL == I) {
1399 else if (Opcode == Instruction::Mul && Known2.
isNonNegative() &&
1415 if (Depth < MaxDepth - 1 && !Known.
Zero && !Known.
One) {
1424 if (IncValue == P)
continue;
1434 if (!Known.
Zero && !Known.
One)
1441 case Instruction::Invoke:
1453 switch (II->getIntrinsicID()) {
1455 case Intrinsic::bitreverse:
1460 case Intrinsic::bswap:
1465 case Intrinsic::ctlz: {
1471 PossibleLZ = std::min(PossibleLZ, BitWidth - 1);
1472 unsigned LowBits =
Log2_32(PossibleLZ)+1;
1476 case Intrinsic::cttz: {
1482 PossibleTZ = std::min(PossibleTZ, BitWidth - 1);
1483 unsigned LowBits =
Log2_32(PossibleTZ)+1;
1487 case Intrinsic::ctpop: {
1492 unsigned LowBits =
Log2_32(BitsPossiblySet)+1;
1498 case Intrinsic::x86_sse42_crc32_64_64:
1504 case Instruction::ExtractElement:
1511 case Instruction::ExtractValue:
1516 switch (II->getIntrinsicID()) {
1518 case Intrinsic::uadd_with_overflow:
1519 case Intrinsic::sadd_with_overflow:
1521 II->getArgOperand(1),
false, Known, Known2,
1524 case Intrinsic::usub_with_overflow:
1525 case Intrinsic::ssub_with_overflow:
1527 II->getArgOperand(1),
false, Known, Known2,
1530 case Intrinsic::umul_with_overflow:
1531 case Intrinsic::smul_with_overflow:
1533 Known, Known2,
Depth, Q);
1566 assert(V &&
"No Value?");
1567 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1572 "Not integer or pointer type!");
1575 unsigned ExpectedWidth = ScalarTy->
isPointerTy() ?
1576 Q.DL.getIndexTypeSizeInBits(ScalarTy) : Q.DL.getTypeSizeInBits(ScalarTy);
1577 assert(ExpectedWidth == BitWidth &&
"V and Known should have same BitWidth");
1579 (void)ExpectedWidth;
1589 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
1599 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1600 APInt Elt = CDS->getElementAsAPInt(i);
1607 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
1611 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
1613 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
1618 const APInt &Elt = ElementCI->getValue();
1629 if (isa<UndefValue>(V))
1634 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
1638 if (Depth == MaxDepth)
1643 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1644 if (!GA->isInterposable())
1649 if (
const Operator *I = dyn_cast<Operator>(V))
1665 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1674 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1693 if (Depth++ == MaxDepth)
1696 Value *
X =
nullptr, *
Y =
nullptr;
1703 if (
const ZExtInst *ZI = dyn_cast<ZExtInst>(V))
1744 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
1773 if (
const Instruction *I = dyn_cast<Instruction>(GEP))
1774 F = I->getFunction();
1792 GTI != GTE; ++GTI) {
1794 if (
StructType *STy = GTI.getStructTypeOrNull()) {
1795 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
1799 if (ElementOffset > 0)
1805 if (Q.DL.getTypeAllocSize(GTI.getIndexedType()) == 0)
1810 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
1821 if (Depth++ >= MaxDepth)
1835 assert(!isa<ConstantData>(V) &&
"Did not expect ConstantPointerNull");
1840 unsigned NumUsesExplored = 0;
1841 for (
auto *U : V->
users()) {
1850 if (
auto *CalledFunc = CS.getCalledFunction())
1852 if (CS.getArgOperand(
Arg.getArgNo()) == V &&
1853 Arg.hasNonNullAttr() && DT->
dominates(CS.getInstruction(), CtxI))
1858 if (!
match(const_cast<User *>(U),
1863 for (
auto *CmpU : U->users()) {
1864 if (
const BranchInst *BI = dyn_cast<BranchInst>(CmpU)) {
1865 assert(BI->isConditional() &&
"uses a comparison!");
1873 match(CmpU, m_Intrinsic<Intrinsic::experimental_guard>()) &&
1874 DT->
dominates(cast<Instruction>(CmpU), CtxI)) {
1889 for (
unsigned i = 0; i < NumRanges; ++i) {
1891 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 0));
1893 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 1));
1895 if (Range.contains(Value))
1908 if (
auto *
C = dyn_cast<Constant>(V)) {
1909 if (
C->isNullValue())
1911 if (isa<ConstantInt>(
C))
1917 if (
auto *VecTy = dyn_cast<VectorType>(
C->
getType())) {
1918 for (
unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) {
1919 Constant *Elt =
C->getAggregateElement(i);
1922 if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
1931 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1932 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
1933 GV->getType()->getAddressSpace() == 0)
1939 if (
auto *I = dyn_cast<Instruction>(V)) {
1943 if (
auto *Ty = dyn_cast<IntegerType>(V->
getType())) {
1944 const APInt ZeroValue(Ty->getBitWidth(), 0);
1952 if (Depth++ >= MaxDepth)
1958 if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0)
1962 if (
const Argument *A = dyn_cast<Argument>(V))
1963 if (A->hasByValOrInAllocaAttr() || A->hasNonNullAttr())
1967 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
1972 if (CS.isReturnNonNull())
1993 Value *
X =
nullptr, *
Y =
nullptr;
1998 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
1999 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), Depth, Q);
2030 auto ShiftVal = Shift->getLimitedValue(BitWidth - 1);
2086 else if (
const SelectInst *
SI = dyn_cast<SelectInst>(V)) {
2092 else if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
2095 if (PN->getNumIncomingValues() == 2) {
2096 Value *Start = PN->getIncomingValue(0);
2097 Value *Induction = PN->getIncomingValue(1);
2098 if (isa<ConstantInt>(Induction) && !isa<ConstantInt>(Start))
2101 if (!
C->isZero() && !
C->isNegative()) {
2112 return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZero();
2114 if (AllNonZeroConstants)
2120 return Known.
One != 0;
2184 if (!CV || !CV->getType()->isVectorTy())
2187 unsigned MinSignBits = TyBits;
2188 unsigned NumElts = CV->getType()->getVectorNumElements();
2189 for (
unsigned i = 0; i != NumElts; ++i) {
2191 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
2195 MinSignBits = std::min(MinSignBits, Elt->getValue().getNumSignBits());
2207 assert(Result > 0 &&
"At least one sign bit needs to be present!");
2219 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2227 Q.DL.getIndexTypeSizeInBits(ScalarTy) :
2228 Q.DL.getTypeSizeInBits(ScalarTy);
2231 unsigned FirstAnswer = 1;
2236 if (Depth == MaxDepth)
2242 case Instruction::SExt:
2246 case Instruction::SDiv: {
2247 const APInt *Denominator;
2259 return std::min(TyBits, NumBits + Denominator->
logBase2());
2264 case Instruction::SRem: {
2265 const APInt *Denominator;
2293 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
2294 return std::max(NumrBits, ResBits);
2299 case Instruction::AShr: {
2304 if (ShAmt->uge(TyBits))
2307 Tmp += ShAmtLimited;
2308 if (Tmp > TyBits) Tmp = TyBits;
2312 case Instruction::Shl: {
2317 if (ShAmt->
uge(TyBits) ||
2318 ShAmt->
uge(Tmp))
break;
2324 case Instruction::And:
2325 case Instruction::Or:
2326 case Instruction::Xor:
2331 FirstAnswer = std::min(Tmp, Tmp2);
2340 if (Tmp == 1)
break;
2342 return std::min(Tmp, Tmp2);
2348 if (Tmp == 1)
break;
2351 if (
const auto *CRHS = dyn_cast<Constant>(U->
getOperand(1)))
2352 if (CRHS->isAllOnesValue()) {
2358 if ((Known.
Zero | 1).isAllOnesValue())
2368 if (Tmp2 == 1)
break;
2369 return std::min(Tmp, Tmp2)-1;
2371 case Instruction::Sub:
2373 if (Tmp2 == 1)
break;
2376 if (
const auto *CLHS = dyn_cast<Constant>(U->
getOperand(0)))
2377 if (CLHS->isNullValue()) {
2382 if ((Known.
Zero | 1).isAllOnesValue())
2396 if (Tmp == 1)
break;
2397 return std::min(Tmp, Tmp2)-1;
2399 case Instruction::Mul: {
2402 if (SignBitsOp0 == 1)
break;
2404 if (SignBitsOp1 == 1)
break;
2405 unsigned OutValidBits =
2406 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
2407 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
2410 case Instruction::PHI: {
2411 const PHINode *PN = cast<PHINode>(U);
2414 if (NumIncomingValues > 4)
break;
2416 if (NumIncomingValues == 0)
break;
2421 for (
unsigned i = 1, e = NumIncomingValues; i != e; ++i) {
2422 if (Tmp == 1)
return Tmp;
2429 case Instruction::Trunc:
2434 case Instruction::ExtractElement:
2463 bool LookThroughSExt,
unsigned Depth) {
2464 const unsigned MaxDepth = 6;
2466 assert(V &&
"No Value?");
2467 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2484 if (CO && CO == BaseVal) {
2495 if (Depth == MaxDepth)
return false;
2498 if (!I)
return false;
2502 case Instruction::SExt:
2503 if (!LookThroughSExt)
return false;
2506 case Instruction::ZExt:
2508 LookThroughSExt, Depth+1);
2509 case Instruction::Shl:
2510 case Instruction::Mul: {
2514 if (I->
getOpcode() == Instruction::Shl) {
2516 if (!Op1CI)
return false;
2525 Value *Mul0 =
nullptr;
2527 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
2528 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
2529 if (Op1C->getType()->getPrimitiveSizeInBits() <
2530 MulC->getType()->getPrimitiveSizeInBits())
2532 if (Op1C->getType()->getPrimitiveSizeInBits() >
2533 MulC->getType()->getPrimitiveSizeInBits())
2541 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
2542 if (Mul0CI->getValue() == 1) {
2549 Value *Mul1 =
nullptr;
2551 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
2552 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
2553 if (Op0C->getType()->getPrimitiveSizeInBits() <
2554 MulC->getType()->getPrimitiveSizeInBits())
2556 if (Op0C->getType()->getPrimitiveSizeInBits() >
2557 MulC->getType()->getPrimitiveSizeInBits())
2565 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
2566 if (Mul1CI->getValue() == 1) {
2609 return Intrinsic::sin;
2613 return Intrinsic::cos;
2617 return Intrinsic::exp;
2621 return Intrinsic::exp2;
2625 return Intrinsic::log;
2627 case LibFunc_log10f:
2628 case LibFunc_log10l:
2629 return Intrinsic::log10;
2637 return Intrinsic::fabs;
2646 case LibFunc_copysign:
2647 case LibFunc_copysignf:
2648 case LibFunc_copysignl:
2649 return Intrinsic::copysign;
2651 case LibFunc_floorf:
2652 case LibFunc_floorl:
2653 return Intrinsic::floor;
2657 return Intrinsic::ceil;
2659 case LibFunc_truncf:
2660 case LibFunc_truncl:
2661 return Intrinsic::trunc;
2665 return Intrinsic::rint;
2666 case LibFunc_nearbyint:
2667 case LibFunc_nearbyintf:
2668 case LibFunc_nearbyintl:
2669 return Intrinsic::nearbyint;
2671 case LibFunc_roundf:
2672 case LibFunc_roundl:
2677 return Intrinsic::pow;
2681 return Intrinsic::sqrt;
2694 if (
auto *CFP = dyn_cast<ConstantFP>(V))
2695 return !CFP->getValueAPF().isNegZero();
2698 if (Depth == MaxDepth)
2706 if (
auto *FPO = dyn_cast<FPMathOperator>(
Op))
2707 if (FPO->hasNoSignedZeros())
2715 if (isa<SIToFPInst>(
Op) || isa<UIToFPInst>(
Op))
2718 if (
auto *Call = dyn_cast<CallInst>(
Op)) {
2724 case Intrinsic::sqrt:
2727 case Intrinsic::fabs:
2747 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2748 return !CFP->getValueAPF().isNegative() ||
2749 (!SignBitOnly && CFP->getValueAPF().isZero());
2753 if (
auto *CV = dyn_cast<Constant>(V)) {
2754 if (CV->getType()->isVectorTy()) {
2755 unsigned NumElts = CV->getType()->getVectorNumElements();
2756 for (
unsigned i = 0; i != NumElts; ++i) {
2757 auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
2760 if (CFP->getValueAPF().isNegative() &&
2761 (SignBitOnly || !CFP->getValueAPF().isZero()))
2770 if (Depth == MaxDepth)
2781 case Instruction::UIToFP:
2783 case Instruction::FMul:
2786 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()))
2790 case Instruction::FAdd:
2791 case Instruction::FDiv:
2792 case Instruction::FRem:
2802 case Instruction::FPExt:
2803 case Instruction::FPTrunc:
2807 case Instruction::ExtractElement:
2814 const auto *CI = cast<CallInst>(
I);
2822 SignBitOnly, Depth + 1)) ||
2825 SignBitOnly, Depth + 1));
2832 case Intrinsic::exp:
2833 case Intrinsic::exp2:
2834 case Intrinsic::fabs:
2837 case Intrinsic::sqrt:
2841 return CI->hasNoNaNs() && (CI->hasNoSignedZeros() ||
2844 case Intrinsic::powi:
2866 case Intrinsic::fma:
2867 case Intrinsic::fmuladd:
2870 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()) &&
2892 if (
auto *FPMathOp = dyn_cast<FPMathOperator>(V))
2893 if (FPMathOp->hasNoNaNs())
2900 if (
auto *CFP = dyn_cast<ConstantFP>(V))
2901 return !CFP->isNaN();
2909 for (
unsigned i = 0; i != NumElts; ++i) {
2910 Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
2913 if (isa<UndefValue>(Elt))
2916 if (!CElt || CElt->isNaN())
2933 if (
Constant *
C = dyn_cast<Constant>(V))
2934 if (
C->isNullValue())
2939 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2940 if (CFP->getType()->isFloatTy())
2942 if (CFP->getType()->isDoubleTy())
2949 if (CI->getBitWidth() % 8 == 0) {
2950 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
2952 if (!CI->getValue().isSplat(8))
2961 Value *Elt = CA->getElementAsConstant(0);
2966 for (
unsigned I = 1,
E = CA->getNumElements(); I !=
E; ++
I)
2967 if (CA->getElementAsConstant(I) != Elt)
3006 while (PrevTo != OrigTo) {
3032 "tmp", InsertBefore);
3049 assert(InsertBefore &&
"Must have someplace to insert!");
3054 unsigned IdxSkip = Idxs.
size();
3069 if (idx_range.
empty())
3073 "Not looking at a struct or array?");
3075 "Invalid indices for type?");
3077 if (
Constant *
C = dyn_cast<Constant>(V)) {
3078 C =
C->getAggregateElement(idx_range[0]);
3079 if (!
C)
return nullptr;
3086 const unsigned *req_idx = idx_range.
begin();
3087 for (
const unsigned *i = I->idx_begin(), *e = I->idx_end();
3088 i != e; ++i, ++req_idx) {
3089 if (req_idx == idx_range.
end()) {
3129 unsigned size = I->getNumIndices() + idx_range.
size();
3134 Idxs.
append(I->idx_begin(), I->idx_end());
3140 &&
"Number of indices added not correct?");
3154 APInt ByteOffset(BitWidth, 0);
3160 while (Visited.
insert(Ptr).second) {
3172 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
3177 Ptr =
GEP->getPointerOperand();
3180 Ptr = cast<Operator>(Ptr)->getOperand(0);
3181 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
3182 if (GA->isInterposable())
3184 Ptr = GA->getAliasee();
3194 unsigned CharSize) {
3208 if (!FirstIdx || !FirstIdx->
isZero())
3216 unsigned ElementSize, uint64_t
Offset) {
3233 uint64_t StartIdx = 0;
3234 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
GEP->getOperand(2)))
3235 StartIdx = CI->getZExtValue();
3246 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
3251 if (GV->getInitializer()->isNullValue()) {
3252 Type *GVTy = GV->getValueType();
3253 if ( (ArrayTy = dyn_cast<ArrayType>(GVTy)) ) {
3257 const DataLayout &DL = GV->getParent()->getDataLayout();
3259 uint64_t Length = SizeInBytes / (ElementSize / 8);
3260 if (Length <= Offset)
3263 Slice.
Array =
nullptr;
3279 if (Offset > NumElts)
3282 Slice.
Array = Array;
3292 uint64_t
Offset,
bool TrimAtNul) {
3297 if (Slice.
Array ==
nullptr) {
3333 unsigned CharSize) {
3339 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
3340 if (!PHIs.
insert(PN).second)
3344 uint64_t LenSoFar = ~0ULL;
3345 for (
Value *IncValue : PN->incoming_values()) {
3347 if (Len == 0)
return 0;
3349 if (Len == ~0ULL)
continue;
3351 if (Len != LenSoFar && LenSoFar != ~0ULL)
3363 if (Len1 == 0)
return 0;
3365 if (Len2 == 0)
return 0;
3366 if (Len1 == ~0ULL)
return Len2;
3367 if (Len2 == ~0ULL)
return Len1;
3368 if (Len1 != Len2)
return 0;
3377 if (Slice.
Array ==
nullptr)
3381 unsigned NullIndex = 0;
3382 for (
unsigned E = Slice.
Length; NullIndex <
E; ++NullIndex) {
3387 return NullIndex + 1;
3400 return Len == ~0ULL ? 1 : Len;
3405 "getArgumentAliasingToReturnedPointer only works on nonnull CallSite");
3416 return CS.
getIntrinsicID() == Intrinsic::launder_invariant_group ||
3431 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3433 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3441 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
3448 unsigned MaxLookup) {
3451 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
3453 V =
GEP->getPointerOperand();
3456 V = cast<Operator>(V)->getOperand(0);
3457 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
3458 if (GA->isInterposable())
3460 V = GA->getAliasee();
3461 }
else if (isa<AllocaInst>(V)) {
3498 unsigned MaxLookup) {
3506 if (!Visited.
insert(P).second)
3515 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
3528 for (
Value *IncValue : PN->incoming_values())
3534 }
while (!Worklist.
empty());
3541 if (
const Operator *U = dyn_cast<Operator>(V)) {
3544 if (U->getOpcode() == Instruction::PtrToInt)
3545 return U->getOperand(0);
3553 (!isa<ConstantInt>(U->getOperand(1)) &&
3555 !isa<PHINode>(U->getOperand(1))))
3557 V = U->getOperand(0);
3579 for (
Value *V : Objs) {
3580 if (!Visited.
insert(V).second)
3596 Objects.
push_back(const_cast<Value *>(V));
3598 }
while (!Working.
empty());
3606 if (!II)
return false;
3630 case Instruction::UDiv:
3631 case Instruction::URem: {
3638 case Instruction::SDiv:
3639 case Instruction::SRem: {
3641 const APInt *Numerator, *Denominator;
3645 if (*Denominator == 0)
3648 if (*Denominator != -1)
3658 const LoadInst *LI = cast<LoadInst>(Inst);
3671 auto *CI = cast<const CallInst>(Inst);
3676 return Callee && Callee->isSpeculatable();
3678 case Instruction::VAArg:
3679 case Instruction::Alloca:
3680 case Instruction::Invoke:
3681 case Instruction::PHI:
3684 case Instruction::Br:
3685 case Instruction::IndirectBr:
3686 case Instruction::Switch:
3687 case Instruction::Unreachable:
3688 case Instruction::Fence:
3689 case Instruction::AtomicRMW:
3690 case Instruction::AtomicCmpXchg:
3691 case Instruction::LandingPad:
3692 case Instruction::Resume:
3693 case Instruction::CatchSwitch:
3694 case Instruction::CatchPad:
3695 case Instruction::CatchRet:
3696 case Instruction::CleanupPad:
3697 case Instruction::CleanupRet:
3729 if (ZeroBits >= BitWidth)
3739 (void)LHSMax.
umul_ov(RHSMax, MaxOverflow);
3774 if (SignBits > BitWidth + 1)
3782 if (SignBits == BitWidth + 1) {
3842 APInt Result = std::move(MaxLHS) + std::move(MaxRHS);
3856 APInt Result = std::move(MinLHS) + std::move(MinRHS);
3909 bool LHSOrRHSKnownNonNegative =
3911 bool LHSOrRHSKnownNegative =
3913 if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) {
3915 if ((AddKnown.
isNonNegative() && LHSOrRHSKnownNonNegative) ||
3916 (AddKnown.
isNegative() && LHSOrRHSKnownNegative)) {
3969 assert((IID == Intrinsic::sadd_with_overflow ||
3970 IID == Intrinsic::uadd_with_overflow ||
3971 IID == Intrinsic::ssub_with_overflow ||
3972 IID == Intrinsic::usub_with_overflow ||
3973 IID == Intrinsic::smul_with_overflow ||
3974 IID == Intrinsic::umul_with_overflow) &&
3975 "Not an overflow intrinsic!");
3982 if (
const auto *EVI = dyn_cast<ExtractValueInst>(U)) {
3983 assert(EVI->getNumIndices() == 1 &&
"Obvious from CI's type");
3985 if (EVI->getIndices()[0] == 0)
3988 assert(EVI->getIndices()[0] == 1 &&
"Obvious from CI's type");
3990 for (
const auto *U : EVI->users())
3991 if (
const auto *
B = dyn_cast<BranchInst>(U)) {
3992 assert(
B->isConditional() &&
"How else is it using an i1?");
4003 auto AllUsesGuardedByBranch = [&](
const BranchInst *BI) {
4005 if (!NoWrapEdge.isSingleEdge())
4009 for (
const auto *
Result : Results) {
4015 for (
auto &RU :
Result->uses())
4023 return llvm::any_of(GuardingBranches, AllUsesGuardedByBranch);
4033 Add, DL, AC, CxtI, DT);
4052 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
4053 return !LI->isVolatile();
4055 return !
SI->isVolatile();
4057 return !CXI->isVolatile();
4059 return !RMWI->isVolatile();
4060 if (
const MemIntrinsic *MII = dyn_cast<MemIntrinsic>(I))
4061 return !MII->isVolatile();
4064 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(I))
4065 return !CRI->unwindsToCaller();
4066 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I))
4067 return !CatchSwitch->unwindsToCaller();
4068 if (isa<ResumeInst>(I))
4070 if (isa<ReturnInst>(I))
4072 if (isa<UnreachableInst>(I))
4078 if (!CS.doesNotThrow())
4097 return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory() ||
4098 match(I, m_Intrinsic<Intrinsic::assume>()) ||
4099 match(I, m_Intrinsic<Intrinsic::sideeffect>());
4109 for (
auto I = BB->
begin(),
E = BB->
end(); I !=
E; ++
I)
4124 if (&LI == I)
return true;
4127 llvm_unreachable(
"Instruction not contained in its own parent basic block.");
4133 case Instruction::Sub:
4134 case Instruction::Xor:
4135 case Instruction::Trunc:
4136 case Instruction::BitCast:
4137 case Instruction::AddrSpaceCast:
4138 case Instruction::Mul:
4139 case Instruction::Shl:
4140 case Instruction::GetElementPtr:
4146 case Instruction::AShr:
4147 case Instruction::SExt:
4152 case Instruction::ICmp:
4170 case Instruction::AtomicCmpXchg:
4173 case Instruction::AtomicRMW:
4176 case Instruction::UDiv:
4177 case Instruction::SDiv:
4178 case Instruction::URem:
4179 case Instruction::SRem:
4201 YieldsPoison.
insert(PoisonI);
4207 while (Iter++ < MaxDepth) {
4209 if (&I != PoisonI) {
4211 if (NotPoison !=
nullptr && YieldsPoison.
count(NotPoison))
4218 if (YieldsPoison.
count(&I)) {
4228 if (Visited.
insert(NextBB).second) {
4245 if (
auto *
C = dyn_cast<ConstantFP>(V))
4251 if (
auto *
C = dyn_cast<ConstantFP>(V))
4252 return !
C->isZero();
4270 if (CmpRHS == FalseVal) {
4292 FC1->
compare(*FC2) == APFloat::cmpResult::cmpLessThan)
4302 FC1->
compare(*FC2) == APFloat::cmpResult::cmpGreaterThan)
4318 if (CmpRHS != TrueVal) {
4484 if ((CmpLHS == TrueVal &&
match(FalseVal,
m_APInt(C2))) ||
4518 assert(X && Y &&
"Invalid operand");
4563 bool Ordered =
false;
4574 if (LHSSafe && RHSSafe) {
4604 if (TrueVal == CmpRHS && FalseVal == CmpLHS) {
4615 if (TrueVal == CmpLHS && FalseVal == CmpRHS) {
4640 auto MaybeSExtCmpLHS =
4644 if (
match(TrueVal, MaybeSExtCmpLHS)) {
4662 else if (
match(FalseVal, MaybeSExtCmpLHS)) {
4683 return matchMinMax(Pred, CmpLHS, CmpRHS, TrueVal, FalseVal, LHS, RHS, Depth);
4717 Type *SrcTy = Cast1->getSrcTy();
4718 if (
auto *Cast2 = dyn_cast<CastInst>(V2)) {
4720 if (*CastOp == Cast2->getOpcode() && SrcTy == Cast2->getSrcTy())
4721 return Cast2->getOperand(0);
4731 case Instruction::ZExt:
4735 case Instruction::SExt:
4739 case Instruction::Trunc:
4742 CmpConst->
getType() == SrcTy) {
4764 CastedTo = CmpConst;
4769 case Instruction::FPTrunc:
4772 case Instruction::FPExt:
4775 case Instruction::FPToUI:
4778 case Instruction::FPToSI:
4781 case Instruction::UIToFP:
4784 case Instruction::SIToFP:
4797 if (CastedBack !=
C)
4806 if (Depth >= MaxDepth)
4821 if (isa<FPMathOperator>(CmpI))
4833 if (*CastOp == Instruction::FPToSI || *CastOp == Instruction::FPToUI)
4836 cast<CastInst>(TrueVal)->getOperand(0),
C,
4842 if (*CastOp == Instruction::FPToSI || *CastOp == Instruction::FPToUI)
4845 C, cast<CastInst>(FalseVal)->getOperand(0),
4906 auto MatchNUWAddsToSameValue = [&](
const Value *A,
const Value *
B,
4919 if (CA->isSubsetOf(Known.
Zero) && CB->isSubsetOf(Known.
Zero))
4927 const APInt *CLHS, *CRHS;
4928 if (MatchNUWAddsToSameValue(LHS, RHS, X, CLHS, CRHS))
4929 return CLHS->
ule(*CRHS);
4966 bool &IsSwappedOps) {
4968 bool IsMatchingOps = (ALHS == BLHS && ARHS ==
BRHS);
4969 IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
4970 return IsMatchingOps || IsSwappedOps;
4982 bool IsSwappedOps) {
5004 assert(ALHS == BLHS &&
"LHS operands must match.");
5011 if (Intersection.isEmptySet())
5039 APred, ALHS, ARHS, BPred, BLHS, BRHS, IsSwappedOps))
5048 if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
5050 APred, ALHS, cast<ConstantInt>(ARHS), BPred, BLHS,
5051 cast<ConstantInt>(BRHS)))
5073 "Expected LHS to be 'and' or 'or'.");
5075 assert(Depth <= MaxDepth &&
"Hit recursion limit");
5099 if (Depth == MaxDepth)
5123 if (LHSCmp && RHSCmp)
5129 if (LHSBO && RHSCmp) {
5130 if ((LHSBO->
getOpcode() == Instruction::And ||
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
bool isFPPredicate() const
const Value * getGuaranteedNonFullPoisonOp(const Instruction *I)
Return either nullptr or an operand of I such that I will trigger undefined behavior if I is executed...
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool isAddOfNonZero(const Value *V1, const Value *V2, const Query &Q)
Return true if V2 == V1 + X, where X is known non-zero.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to have exactly one bit set when defined. ...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
void setSignBit()
Set the sign bit to 1.
This class is the base class for the comparison instructions.
static bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth, const Query &Q)
Return true if the given value is known to have exactly one bit set when defined. ...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool hasLocalLinkage() const
static void computeKnownBits(const Value *V, KnownBits &Known, unsigned Depth, const Query &Q)
Determine which bits of V are known to be either zero or one and return them in the Known bit set...
uint64_t getZExtValue() const
Get zero extended value.
Value * getPointerOperand(Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
static unsigned ComputeNumSignBits(const Value *V, unsigned Depth, const Query &Q)
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Value * getAggregateOperand()
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
static bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth, const Query &Q)
Return true if 'V & Mask' is known to be zero.
Compute iterated dominance frontiers using a linear time algorithm.
BinaryOps getOpcode() const
Value * isBytewiseValue(Value *V)
If the specified value can be set by repeating the same byte in memory, return the i8 value that it i...
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
Type * getElementType(unsigned N) const
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static bool isKnownNonEqual(const Value *V1, const Value *V2, const Query &Q)
Return true if it is known that V1 != V2.
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
bool hasConflict() const
Returns true if there is conflicting information.
static const Value * getUnderlyingObjectFromInt(const Value *V)
This is the function that does the work of looking through basic ptrtoint+arithmetic+inttoptr sequenc...
This class represents zero extension of integer types.
unsigned getNumElements() const
Random access to the elements.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
bool slt(const APInt &RHS) const
Signed less than comparison.
This class represents a function call, abstracting a target machine's calling convention.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
static uint64_t round(uint64_t Acc, uint64_t Input)
gep_type_iterator gep_type_end(const User *GEP)
const Value * getTrueValue() const
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
An efficient, type-erasing, non-owning reference to a callable.
A cache of @llvm.assume calls within a function.
0 1 0 0 True if ordered and less than
Function Alias Analysis Results
LLVMContext & getContext() const
All values hold a context through their type.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
static bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
void setAllBits()
Set every bit to 1.
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr)
Return true if it is valid to use the assumptions provided by an assume intrinsic, I, at the point in the control-flow identified by the context instruction, CxtI.
SelectPatternFlavor getInverseMinMaxFlavor(SelectPatternFlavor SPF)
Return the inverse minimum/maximum flavor of the specified flavor.
const MDOperand & getOperand(unsigned I) const
An instruction for reading from memory.
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
static IntegerType * getInt64Ty(LLVMContext &C)
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
bool isVectorTy() const
True if this is an instance of VectorType.
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
bool isGEPBasedOnPointerToString(const GEPOperator *GEP, unsigned CharSize=8)
Returns true if the GEP is based on a pointer to a string (array of.
void reserve(size_type N)
uint64_t Offset
Slice starts at this Offset.
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
unsigned getBitWidth() const
Get the bit width of this value.
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
void setAllZero()
Make all bits known to be zero and discard any previous information.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
static void computeKnownBitsFromShiftOperator(const Operator *I, KnownBits &Known, KnownBits &Known2, unsigned Depth, const Query &Q, function_ref< APInt(const APInt &, unsigned)> KZF, function_ref< APInt(const APInt &, unsigned)> KOF)
Compute known bits from a shift operator, including those with a non-constant shift amount...
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const AddOperator *Add, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool propagatesFullPoison(const Instruction *I)
Return true if this function can prove that I is guaranteed to yield full-poison (all bits poison) if...
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Intrinsic::ID getIntrinsicForCallSite(ImmutableCallSite ICS, const TargetLibraryInfo *TLI)
Map a call instruction to an intrinsic ID.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
iterator begin()
Instruction iterator methods.
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
SI optimize exec mask operations pre RA
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static bool isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is false when two compares have matching operands.
bool match(Val *V, const Pattern &P)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
static SelectPatternResult matchMinMaxOfMinMax(CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TVal, Value *FVal, unsigned Depth)
Recognize variations of: a < c ? min(a,b) : min(b,c) ==> min(min(a,b),min(b,c))
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
void setBit(unsigned BitPosition)
Set a given bit to 1.
This class represents the LLVM 'select' instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
This is the base class for all instructions that perform data casts.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS, KnownBits RHS)
Compute known bits resulting from adding LHS and RHS.
Exact_match< T > m_Exact(const T &SubPattern)
uint64_t getArrayNumElements() const
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
Class to represent struct types.
static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS, const Value *RHS, const DataLayout &DL, unsigned Depth)
Return true if "icmp Pred LHS RHS" is always true.
A Use represents the edge between a Value definition and its users.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
static unsigned ComputeNumSignBitsImpl(const Value *V, unsigned Depth, const Query &Q)
Return the number of times the sign bit of the register is replicated into the other bits...
bool isIntegerTy() const
True if this is an instance of IntegerType.
static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is true when two compares have matching operands.
0 1 0 1 True if ordered and less than or equal
This file contains the simple types necessary to represent the attributes associated with functions a...
NaN behavior not applicable.
static Optional< bool > isImpliedCondICmps(const ICmpInst *LHS, const ICmpInst *RHS, const DataLayout &DL, bool LHSIsTrue, unsigned Depth)
Return true if LHS implies RHS is true.
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
This file implements a class to represent arbitrary precision integral constant values and operations...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
BlockT * getHeader() const
bool programUndefinedIfFullPoison(const Instruction *PoisonI)
Return true if this function can prove that if PoisonI is executed and yields a full-poison value (al...
static bool isEphemeralValueOf(const Instruction *I, const Value *E)
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
A constant value that is initialized with an expression using other constant values.
int64_t getSExtValue() const
Get sign extended value.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getType() const
All values are typed, get the type of this value.
bool getBoolValue() const
Convert APInt to a boolean value.
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
const ConstantDataArray * Array
ConstantDataArray pointer.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
ValTy * getArgOperand(unsigned i) const
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
Class to represent array types.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of the intrinsic called by this CallSite, or Intrinsic::not_intrinsic if the ...
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW, KnownBits &Known, KnownBits &Known2, unsigned Depth, const Query &Q)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
const APInt & getValue() const
Return the constant as an APInt value reference.
KnownBits zextOrTrunc(unsigned BitWidth)
Zero extends or truncates the underlying known Zero and One bits.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
An instruction for storing to memory.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool haveNoCommonBitsSet(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if LHS and RHS have no common bits set.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known, unsigned Depth, const Query &Q)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
amdgpu Simplify well known AMD library false Value * Callee
APInt reverseBits() const
Value * getOperand(unsigned i) const
bool CannotBeNegativeZero(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if we can prove that the specified FP value is never equal to -0.0.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static bool isKnownNonNaN(const Value *V, FastMathFlags FMF)
bool isNegative() const
Returns true if this value is known to be negative.
bool isZeroValue() const
Return true if the value is negative zero or null value.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
bool getConstantDataArrayInfo(const Value *V, ConstantDataArraySlice &Slice, unsigned ElementSize, uint64_t Offset=0)
Returns true if the value V is a pointer into a ConstantDataArray.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isNegative() const
Determine sign of this APInt.
static SelectPatternResult matchFastFloatClamp(CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS)
Match clamp pattern for float types without care about NaNs or signed zeros.
initializer< Ty > init(const Ty &Val)
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
static bool isSameUnderlyingObjectInLoop(const PHINode *PN, const LoopInfo *LI)
PN defines a loop-variant pointer to an object.
bool isAllOnesValue() const
Determine if all bits are set.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
void setNoSignedZeros(bool B=true)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW=false)
Return true if the two given values are negation.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double, and whose elements are just simple data values (i.e.
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
static SelectPatternResult matchSelectPattern(CmpInst::Predicate Pred, FastMathFlags FMF, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, unsigned Depth)
Conditional or Unconditional Branch instruction.
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the give value is known to be non-negative.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
size_t size() const
size - Get the array size.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
void resetAll()
Resets the known state of all bits.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool onlyUsedByLifetimeMarkers(const Value *V)
Return true if the only users of this pointer are lifetime markers.
bool isPointerTy() const
True if this is an instance of PointerType.
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if 'V & Mask' is known to be zero.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool getUnderlyingObjectsForCodeGen(const Value *V, SmallVectorImpl< Value *> &Objects, const DataLayout &DL)
This is a wrapper around GetUnderlyingObjects and adds support for basic ptrtoint+arithmetic+inttoptr...
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
bool isOverflowIntrinsicNoWrap(const IntrinsicInst *II, const DominatorTree &DT)
Returns true if the arithmetic part of the II 's result is used only along the paths control dependen...
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
A udiv or sdiv instruction, which can be marked as "exact", indicating that no bits are destroyed...
static bool isGEPKnownNonNull(const GEPOperator *GEP, unsigned Depth, const Query &Q)
Test whether a GEP's result is known to be non-null.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
static uint64_t GetStringLengthH(const Value *V, SmallPtrSetImpl< const PHINode *> &PHIs, unsigned CharSize)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
KnownBits trunc(unsigned BitWidth)
Truncate the underlying known Zero and One bits.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl...
static bool isKnownNonNullFromDominatingCondition(const Value *V, const Instruction *CtxI, const DominatorTree *DT)
bool isAllOnes() const
Returns true if value is all one bits.
Value * getPointerOperand()
Value * getPointerOperand()
CmpInst::Predicate getMinMaxPred(SelectPatternFlavor SPF, bool Ordered=false)
Return the canonical comparison predicate for the specified minimum/maximum flavor.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
Class to represent integer types.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
SelectPatternNaNBehavior
Behavior when a floating point min/max is given one NaN and one non-NaN as input. ...
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
Represents offset+length into a ConstantDataArray.
CmpInst::Predicate getInverseMinMaxPred(SelectPatternFlavor SPF)
Return the canonical inverse comparison predicate for the specified minimum/maximum flavor...
static Optional< bool > isImpliedCondAndOr(const BinaryOperator *LHS, const ICmpInst *RHS, const DataLayout &DL, bool LHSIsTrue, unsigned Depth)
Return true if LHS implies RHS is true.
const Function * getFunction() const
Return the function this instruction belongs to.
void clearSignBit()
Set the sign bit to 0.
static double log2(double V)
const Value * getCondition() const
bool isZero() const
Returns true if value is all zero.
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
Type * getIndexedType() const
bool isAssumeLikeIntrinsic(const Instruction *I)
Return true if it is an intrinsic that cannot be speculated but also cannot trap. ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
unsigned ceilLogBase2() const
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static Value * BuildSubAggregate(Value *From, Value *To, Type *IndexedType, SmallVectorImpl< unsigned > &Idxs, unsigned IdxSkip, Instruction *InsertBefore)
Constant * getSplatValue() const
If this is a splat vector constant, meaning that all of the elements have the same value...
1 1 0 1 True if unordered, less than, or equal
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
Value * FindInsertedValue(Value *V, ArrayRef< unsigned > idx_range, Instruction *InsertBefore=nullptr)
Given an aggregrate and an sequence of indices, see if the scalar value indexed is already around as ...
bool isKnownNeverNaN(const Value *V)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
static unsigned computeNumSignBitsVectorConstant(const Value *V, unsigned TyBits)
For vector constants, loop over the elements and find the constant with the minimum number of sign bi...
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
void makeNonNegative()
Make this value non-negative.
bool isEmptySet() const
Return true if this set contains no members.
Given one NaN input, returns the non-NaN.
0 0 1 0 True if ordered and greater than
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value, otherwise return null.
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
This is the common base class for memset/memcpy/memmove.
Iterator for intrusive lists based on ilist_node.
StructType * getStructTypeOrNull() const
unsigned getNumOperands() const
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool isMaxSignedValue() const
Determine if this is the largest signed value.
This is the shared class of boolean and integer constants.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
SelectPatternFlavor Flavor
static SelectPatternResult matchMinMax(CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, unsigned Depth)
Match non-obvious integer minimum and maximum sequences.
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return the number of times the sign bit of the register is replicated into the other bits...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
1 1 0 0 True if unordered or less than
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
This is a utility class that provides an abstraction for the common functionality between Instruction...
Module.h This file contains the declarations for the Module class.
uint64_t Length
Length of the slice.
SelectPatternFlavor
Specific patterns of select instructions we can match.
Provides information about what library functions are available for the current target.
static SelectPatternResult matchClamp(CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal)
Recognize variations of: CLAMP(v,l,h) ==> ((v) < (l) ? (l) : ((v) > (h) ? (h) : (v))) ...
static Optional< bool > isImpliedCondMatchingImmOperands(CmpInst::Predicate APred, const Value *ALHS, const ConstantInt *C1, CmpInst::Predicate BPred, const Value *BLHS, const ConstantInt *C2)
Return true if "icmp1 APred ALHS C1" implies "icmp2 BPred BLHS C2" is true.
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
This class represents a range of values.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
static bool checkRippleForSignedAdd(const KnownBits &LHSKnown, const KnownBits &RHSKnown)
Return true if we can prove that adding the two values of the knownbits will not overflow.
LLVM_NODISCARD T pop_back_val()
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
static ConstantInt * getTrue(LLVMContext &Context)
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
unsigned logBase2() const
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
bool isIntPredicate() const
bool isTrueWhenEqual() const
This is just a convenience.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static cl::opt< unsigned > DomConditionsMaxUses("dom-conditions-max-uses", cl::Hidden, cl::init(20))
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
iterator_range< user_iterator > users()
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property...
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
const Value * getArgumentAliasingToReturnedPointer(ImmutableCallSite CS)
This function returns call pointer argument that is considered the same by aliasing rules...
bool isLoopHeader(const BlockT *BB) const
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
const Value * getFalseValue() const
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static void computeKnownBitsFromOperator(const Operator *I, KnownBits &Known, unsigned Depth, const Query &Q)
amdgpu Simplify well known AMD library false Value Value * Arg
static Value * lookThroughCast(CmpInst *CmpI, Value *V1, Value *V2, Instruction::CastOps *CastOp)
Helps to match a select pattern in case of a type mismatch.
bool isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the given value is known be negative (i.e.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
Predicate getPredicate() const
Return the predicate for this instruction.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
bool mayBeMemoryDependent(const Instruction &I)
Returns true if the result or effects of the given instructions I depend on or influence global memor...
static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1, bool NSW, KnownBits &KnownOut, KnownBits &Known2, unsigned Depth, const Query &Q)
uint64_t getElementOffset(unsigned Idx) const
unsigned getAlignment() const
Return the alignment of the access that is being performed.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(ImmutableCallSite CS)
LLVM_NODISCARD bool empty() const
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
unsigned greater or equal
Represents a single loop in the control flow graph.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Establish a view to a call site for examination.
const Function * getParent() const
Return the enclosing method, or null if none.
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value's sign bit is 0.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool ComputeMultiple(Value *V, unsigned Base, Value *&Multiple, bool LookThroughSExt=false, unsigned Depth=0)
This function computes the integer multiple of Base that equals V.
static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isGuaranteedToExecuteForEveryIteration(const Instruction *I, const Loop *L)
Return true if this function can prove that the instruction I is executed for every iteration of the ...
1 0 1 0 True if unordered or greater than
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given values are known to be non-equal when defined.
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
APInt umul_ov(const APInt &RHS, bool &Overflow) const
Optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsTrue=true, unsigned Depth=0)
Return true if RHS is known to be implied true by LHS.
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
This function computes the length of a null-terminated C string pointed to by V.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
void GetUnderlyingObjects(Value *V, SmallVectorImpl< Value *> &Objects, const DataLayout &DL, LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to GetUnderlyingObject except that it can look through phi and select instruct...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Given one NaN input, returns the NaN.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
static bool cannotBeOrderedLessThanZeroImpl(const Value *V, const TargetLibraryInfo *TLI, bool SignBitOnly, unsigned Depth)
If SignBitOnly is true, test for a known 0 sign bit rather than a standard ordered compare...
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
LLVM Value Representation.
bool isEquality() const
This is just a convenience that dispatches to the subclasses.
1 0 1 1 True if unordered, greater than, or equal
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
static const Instruction * safeCxtI(const Value *V, const Instruction *CxtI)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
void setAllOnes()
Make all bits known to be one and discard any previous information.
static bool isKnownNonZero(const Value *V, unsigned Depth, const Query &Q)
Return true if the given value is known to be non-zero when defined.
KnownBits sext(unsigned BitWidth)
Sign extends the underlying known Zero and One bits.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the given value is known be positive (i.e.
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool isMatchingOps(const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS, bool &IsSwappedOps)
Return true if the operands of the two compares match.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to be non-zero when defined.
Type * getElementType() const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Type * getSourceElementType() const
bool isNonNegative() const
Returns true if this value is known to be non-negative.
static Optional< bool > isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS, const DataLayout &DL, unsigned Depth)
Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred ALHS ARHS" is true.
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool CannotBeOrderedLessThanZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value is either NaN or never less than -0...
bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
unsigned getNumOperands() const
Return number of MDNode operands.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
op_range incoming_values()
ValTy * getReturnedArgOperand() const
0 0 1 1 True if ordered and greater than or equal
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
static IntegerType * getInt8Ty(LLVMContext &C)
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
static Optional< bool > isImpliedCondMatchingOperands(CmpInst::Predicate APred, const Value *ALHS, const Value *ARHS, CmpInst::Predicate BPred, const Value *BLHS, const Value *BRHS, bool IsSwappedOps)
Return true if "icmp1 APred ALHS ARHS" implies "icmp2 BPred BLHS BRHS" is true.
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
bool isNullValue() const
Determine if all bits are clear.
bool isStructTy() const
True if this is an instance of StructType.
bool empty() const
empty - Check if the array is empty.
cmpResult compare(const APFloat &RHS) const
bool isArrayTy() const
True if this is an instance of ArrayType.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
A wrapper class for inspecting calls to intrinsic functions.
bool noSignedZeros() const
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
gep_type_iterator gep_type_begin(const User *GEP)
void makeNegative()
Make this value negative.
static bool rangeMetadataExcludesValue(const MDNode *Ranges, const APInt &Value)
Does the 'Range' metadata (which must be a valid MD_range operand list) ensure that the value it's at...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.