120 std::array<const Value *, MaxDepth> Excluded;
125 unsigned NumExcluded = 0;
130 : DL(DL), AC(AC), CxtI(CxtI), DT(DT), ORE(ORE), IIQ(UseInstrInfo) {}
133 : DL(Q.DL), AC(Q.AC), CxtI(Q.CxtI), DT(Q.DT), ORE(Q.ORE), IIQ(Q.IIQ),
134 NumExcluded(Q.NumExcluded) {
135 Excluded = Q.Excluded;
136 Excluded[NumExcluded++] = NewExcl;
137 assert(NumExcluded <= Excluded.size());
141 if (NumExcluded == 0)
143 auto End = Excluded.begin() + NumExcluded;
144 return std::find(Excluded.begin(), End, Value) != End;
188 V, Depth,
Query(DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo, ORE));
196 "LHS and RHS should have the same type");
198 "LHS and RHS should be integers");
210 computeKnownBits(LHS, LHSKnown, DL, 0, AC, CxtI, DT,
nullptr, UseInstrInfo);
211 computeKnownBits(RHS, RHSKnown, DL, 0, AC, CxtI, DT,
nullptr, UseInstrInfo);
212 return (LHSKnown.Zero | RHSKnown.Zero).isAllOnesValue();
217 if (
const ICmpInst *IC = dyn_cast<ICmpInst>(U))
218 if (IC->isEquality())
219 if (
Constant *
C = dyn_cast<Constant>(IC->getOperand(1)))
220 if (
C->isNullValue())
231 bool OrZero,
unsigned Depth,
235 V, OrZero, Depth,
Query(DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo));
259 if (
auto *CI = dyn_cast<ConstantInt>(V))
260 return CI->getValue().isStrictlyPositive();
284 UseInstrInfo,
nullptr));
295 V, Mask, Depth,
Query(DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo));
306 V, Depth,
Query(DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo));
312 unsigned Depth,
const Query &Q) {
326 unsigned Depth,
const Query &Q) {
337 isKnownNonNegative =
true;
342 bool isKnownNegativeOp0 = Known2.
isNegative();
344 isKnownNonNegative = (isKnownNegativeOp1 && isKnownNegativeOp0) ||
345 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
348 if (!isKnownNonNegative)
349 isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
351 (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
360 BitWidth) - BitWidth;
361 LeadZ = std::min(LeadZ, BitWidth);
414 unsigned TrailZ = TrailZero0 + TrailZero1;
417 unsigned SmallestOperand = std::min(TrailBitsKnown0 - TrailZero0,
418 TrailBitsKnown1 - TrailZero1);
419 unsigned ResultBitsKnown = std::min(SmallestOperand + TrailZ, BitWidth);
426 Known.
Zero |= (~BottomKnown).getLoBits(ResultBitsKnown);
434 if (isKnownNonNegative && !Known.
isNegative())
449 for (
unsigned i = 0; i < NumRanges; ++i) {
451 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 0));
453 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 1));
457 unsigned CommonPrefixBits =
461 Known.
One &= Range.getUnsignedMax() &
Mask;
462 Known.
Zero &= ~Range.getUnsignedMax() &
Mask;
477 while (!WorkSet.
empty()) {
479 if (!Visited.
insert(V).second)
484 return EphValues.
count(U);
491 if (
const User *U = dyn_cast<User>(V))
504 if (
const CallInst *CI = dyn_cast<CallInst>(I))
505 if (
Function *
F = CI->getCalledFunction())
506 switch (
F->getIntrinsicID()) {
575 unsigned Depth,
const Query &Q) {
578 if (!Q.AC || !Q.CxtI)
586 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
591 "Got assumption for the wrong function!");
600 "must be an assume intrinsic");
605 assert(BitWidth == 1 &&
"assume operand is not i1?");
611 assert(BitWidth == 1 &&
"assume operand is not i1?");
617 if (Depth == MaxDepth)
633 Known.
One |= RHSKnown.
One;
635 }
else if (
match(Arg,
647 Known.
One |= RHSKnown.
One & MaskKnown.
One;
663 }
else if (
match(Arg,
691 }
else if (
match(Arg,
737 Known.
One |= RHSKnown.
One;
753 }
else if (
match(Arg,
764 Known.
One |= RHSKnown.
One <<
C;
867 <<
"Detected conflicting code assumptions. Program may " 868 "have undefined behavior, or compiler may have " 884 unsigned Depth,
const Query &Q,
889 if (
auto *SA = dyn_cast<ConstantInt>(I->
getOperand(1))) {
890 unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
893 Known.
Zero = KZF(Known.
Zero, ShiftAmt);
894 Known.
One = KOF(Known.
One, ShiftAmt);
909 if ((~Known.
Zero).uge(BitWidth)) {
933 if (!*ShifterOperandIsNonZero)
941 for (
unsigned ShiftAmt = 0; ShiftAmt < BitWidth; ++ShiftAmt) {
944 if ((ShiftAmt & ~ShiftAmtKZ) != ShiftAmt)
946 if ((ShiftAmt | ShiftAmtKO) != ShiftAmt)
952 if (!ShifterOperandIsNonZero.
hasValue())
953 ShifterOperandIsNonZero =
955 if (*ShifterOperandIsNonZero)
959 Known.
Zero &= KZF(Known2.
Zero, ShiftAmt);
960 Known.
One &= KOF(Known2.
One, ShiftAmt);
970 unsigned Depth,
const Query &Q) {
981 case Instruction::And: {
996 Value *
X =
nullptr, *
Y =
nullptr;
997 if (!Known.
Zero[0] && !Known.
One[0] &&
1006 case Instruction::Or:
1015 case Instruction::Xor: {
1023 Known.
Zero = std::move(KnownZeroOut);
1026 case Instruction::Mul: {
1027 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1032 case Instruction::UDiv: {
1042 if (RHSMaxLeadingZeros != BitWidth)
1043 LeadZ = std::min(BitWidth, LeadZ + BitWidth - RHSMaxLeadingZeros - 1);
1049 const Value *LHS, *RHS;
1059 unsigned MaxHighOnes = 0;
1060 unsigned MaxHighZeros = 0;
1095 if (Q.IIQ.hasNoSignedWrap(cast<Instruction>(RHS)))
1102 if (MaxHighOnes > 0)
1104 if (MaxHighZeros > 0)
1108 case Instruction::FPTrunc:
1109 case Instruction::FPExt:
1110 case Instruction::FPToUI:
1111 case Instruction::FPToSI:
1112 case Instruction::SIToFP:
1113 case Instruction::UIToFP:
1115 case Instruction::PtrToInt:
1116 case Instruction::IntToPtr:
1119 case Instruction::ZExt:
1120 case Instruction::Trunc: {
1123 unsigned SrcBitWidth;
1128 Q.DL.getIndexTypeSizeInBits(ScalarTy) :
1129 Q.DL.getTypeSizeInBits(ScalarTy);
1131 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1136 if (BitWidth > SrcBitWidth)
1140 case Instruction::BitCast: {
1151 case Instruction::SExt: {
1155 Known = Known.
trunc(SrcBitWidth);
1159 Known = Known.
sext(BitWidth);
1162 case Instruction::Shl: {
1164 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1165 auto KZF = [NSW](
const APInt &KnownZero,
unsigned ShiftAmt) {
1166 APInt KZResult = KnownZero << ShiftAmt;
1175 auto KOF = [NSW](
const APInt &KnownOne,
unsigned ShiftAmt) {
1176 APInt KOResult = KnownOne << ShiftAmt;
1185 case Instruction::LShr: {
1187 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1188 APInt KZResult = KnownZero.
lshr(ShiftAmt);
1194 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1195 return KnownOne.
lshr(ShiftAmt);
1201 case Instruction::AShr: {
1203 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1204 return KnownZero.
ashr(ShiftAmt);
1207 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1208 return KnownOne.
ashr(ShiftAmt);
1214 case Instruction::Sub: {
1215 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1217 Known, Known2,
Depth, Q);
1221 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1223 Known, Known2,
Depth, Q);
1226 case Instruction::SRem:
1228 APInt RA = Rem->getValue().abs();
1230 APInt LowBits = RA - 1;
1234 Known.
Zero = Known2.
Zero & LowBits;
1235 Known.
One = Known2.
One & LowBits;
1240 Known.
Zero |= ~LowBits;
1245 Known.
One |= ~LowBits;
1247 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1260 case Instruction::URem: {
1262 const APInt &
RA = Rem->getValue();
1264 APInt LowBits = (RA - 1);
1266 Known.
Zero |= ~LowBits;
1267 Known.
One &= LowBits;
1284 case Instruction::Alloca: {
1294 case Instruction::GetElementPtr: {
1302 for (
unsigned i = 1, e = I->
getNumOperands(); i != e; ++i, ++GTI) {
1315 unsigned Idx = cast<ConstantInt>(
Index)->getZExtValue();
1318 TrailZ = std::min<unsigned>(TrailZ,
1328 uint64_t TypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1329 LocalKnown.
Zero = LocalKnown.
One =
APInt(GEPOpiBits, 0);
1331 TrailZ = std::min(TrailZ,
1340 case Instruction::PHI: {
1346 for (
unsigned i = 0; i != 2; ++i) {
1357 Opcode == Instruction::Sub ||
1358 Opcode == Instruction::And ||
1359 Opcode == Instruction::Or ||
1360 Opcode == Instruction::Mul) {
1382 if (OverflowOp && Q.IIQ.hasNoSignedWrap(OverflowOp)) {
1401 else if (Opcode == Instruction::Sub && LL == I) {
1409 else if (Opcode == Instruction::Mul && Known2.
isNonNegative() &&
1425 if (Depth < MaxDepth - 1 && !Known.
Zero && !Known.
One) {
1434 if (IncValue == P)
continue;
1444 if (!Known.
Zero && !Known.
One)
1451 case Instruction::Invoke:
1464 switch (II->getIntrinsicID()) {
1482 PossibleLZ = std::min(PossibleLZ, BitWidth - 1);
1483 unsigned LowBits =
Log2_32(PossibleLZ)+1;
1493 PossibleTZ = std::min(PossibleTZ, BitWidth - 1);
1494 unsigned LowBits =
Log2_32(PossibleTZ)+1;
1503 unsigned LowBits =
Log2_32(BitsPossiblySet)+1;
1516 uint64_t ShiftAmt = SA->
urem(BitWidth);
1518 ShiftAmt = BitWidth - ShiftAmt;
1527 Known2.
One.
shl(ShiftAmt) | Known3.
One.
lshr(BitWidth - ShiftAmt);
1536 case Instruction::ExtractElement:
1543 case Instruction::ExtractValue:
1548 switch (II->getIntrinsicID()) {
1553 II->getArgOperand(1),
false, Known, Known2,
1559 II->getArgOperand(1),
false, Known, Known2,
1565 Known, Known2,
Depth, Q);
1598 assert(V &&
"No Value?");
1599 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1604 "Not integer or pointer type!");
1607 unsigned ExpectedWidth = ScalarTy->
isPointerTy() ?
1608 Q.DL.getIndexTypeSizeInBits(ScalarTy) : Q.DL.getTypeSizeInBits(ScalarTy);
1609 assert(ExpectedWidth == BitWidth &&
"V and Known should have same BitWidth");
1611 (void)ExpectedWidth;
1621 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
1631 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1632 APInt Elt = CDS->getElementAsAPInt(i);
1639 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
1643 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
1645 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
1650 const APInt &Elt = ElementCI->getValue();
1661 if (isa<UndefValue>(V))
1666 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
1670 if (Depth == MaxDepth)
1675 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1676 if (!GA->isInterposable())
1681 if (
const Operator *I = dyn_cast<Operator>(V))
1697 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1706 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1725 if (Depth++ == MaxDepth)
1728 Value *
X =
nullptr, *
Y =
nullptr;
1735 if (
const ZExtInst *ZI = dyn_cast<ZExtInst>(V))
1757 if (OrZero || Q.IIQ.hasNoUnsignedWrap(VOBO) ||
1758 Q.IIQ.hasNoSignedWrap(VOBO)) {
1777 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
1806 if (
const Instruction *I = dyn_cast<Instruction>(GEP))
1807 F = I->getFunction();
1825 GTI != GTE; ++GTI) {
1827 if (
StructType *STy = GTI.getStructTypeOrNull()) {
1828 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
1832 if (ElementOffset > 0)
1838 if (Q.DL.getTypeAllocSize(GTI.getIndexedType()) == 0)
1843 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
1854 if (Depth++ >= MaxDepth)
1868 assert(!isa<ConstantData>(V) &&
"Did not expect ConstantPointerNull");
1873 unsigned NumUsesExplored = 0;
1874 for (
auto *U : V->
users()) {
1883 if (
auto *CalledFunc = CS.getCalledFunction())
1885 if (CS.getArgOperand(
Arg.getArgNo()) == V &&
1886 Arg.hasNonNullAttr() && DT->
dominates(CS.getInstruction(), CtxI))
1891 if (!
match(const_cast<User *>(U),
1898 for (
auto *CmpU : U->users()) {
1900 if (Visited.
insert(CmpU).second)
1903 while (!WorkList.
empty()) {
1911 if (
auto *BO = dyn_cast<BinaryOperator>(Curr))
1912 if (BO->getOpcode() == Instruction::And) {
1913 for (
auto *BOU : BO->users())
1914 if (Visited.
insert(BOU).second)
1919 if (
const BranchInst *BI = dyn_cast<BranchInst>(Curr)) {
1920 assert(BI->isConditional() &&
"uses a comparison!");
1928 DT->
dominates(cast<Instruction>(Curr), CtxI)) {
1944 for (
unsigned i = 0; i < NumRanges; ++i) {
1946 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 0));
1948 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 1));
1950 if (Range.contains(Value))
1963 if (
auto *
C = dyn_cast<Constant>(V)) {
1964 if (
C->isNullValue())
1966 if (isa<ConstantInt>(
C))
1972 if (
auto *VecTy = dyn_cast<VectorType>(
C->
getType())) {
1973 for (
unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) {
1974 Constant *Elt =
C->getAggregateElement(i);
1977 if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
1986 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
1987 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
1988 GV->getType()->getAddressSpace() == 0)
1994 if (
auto *I = dyn_cast<Instruction>(V)) {
1998 if (
auto *Ty = dyn_cast<IntegerType>(V->
getType())) {
1999 const APInt ZeroValue(Ty->getBitWidth(), 0);
2007 if (Depth++ >= MaxDepth)
2013 if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0)
2017 if (
const Argument *A = dyn_cast<Argument>(V))
2018 if (A->hasByValOrInAllocaAttr() || A->hasNonNullAttr())
2022 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
2026 if (
const auto *Call = dyn_cast<CallBase>(V)) {
2027 if (Call->isReturnNonNull())
2048 Value *
X =
nullptr, *
Y =
nullptr;
2053 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
2054 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), Depth, Q);
2061 if (Q.IIQ.hasNoUnsignedWrap(BO))
2085 auto ShiftVal = Shift->getLimitedValue(BitWidth - 1);
2136 if ((Q.IIQ.hasNoSignedWrap(BO) || Q.IIQ.hasNoUnsignedWrap(BO)) &&
2141 else if (
const SelectInst *
SI = dyn_cast<SelectInst>(V)) {
2147 else if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
2150 if (PN->getNumIncomingValues() == 2) {
2151 Value *Start = PN->getIncomingValue(0);
2152 Value *Induction = PN->getIncomingValue(1);
2153 if (isa<ConstantInt>(Induction) && !isa<ConstantInt>(Start))
2156 if (!
C->isZero() && !
C->isNegative()) {
2158 if (Q.IIQ.UseInstrInfo &&
2168 return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZero();
2170 if (AllNonZeroConstants)
2176 return Known.
One != 0;
2237 assert(isa<Operator>(Select) &&
2239 "Input should be a Select!");
2241 const Value *LHS, *RHS, *LHS2, *RHS2;
2260 return CLow->
sle(*CHigh);
2270 if (!CV || !CV->getType()->isVectorTy())
2273 unsigned MinSignBits = TyBits;
2274 unsigned NumElts = CV->getType()->getVectorNumElements();
2275 for (
unsigned i = 0; i != NumElts; ++i) {
2277 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
2281 MinSignBits = std::min(MinSignBits, Elt->getValue().getNumSignBits());
2293 assert(Result > 0 &&
"At least one sign bit needs to be present!");
2305 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2313 Q.DL.getIndexTypeSizeInBits(ScalarTy) :
2314 Q.DL.getTypeSizeInBits(ScalarTy);
2317 unsigned FirstAnswer = 1;
2322 if (Depth == MaxDepth)
2328 case Instruction::SExt:
2332 case Instruction::SDiv: {
2333 const APInt *Denominator;
2345 return std::min(TyBits, NumBits + Denominator->
logBase2());
2350 case Instruction::SRem: {
2351 const APInt *Denominator;
2379 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
2380 return std::max(NumrBits, ResBits);
2385 case Instruction::AShr: {
2390 if (ShAmt->uge(TyBits))
2393 Tmp += ShAmtLimited;
2394 if (Tmp > TyBits) Tmp = TyBits;
2398 case Instruction::Shl: {
2403 if (ShAmt->
uge(TyBits) ||
2404 ShAmt->
uge(Tmp))
break;
2410 case Instruction::And:
2411 case Instruction::Or:
2412 case Instruction::Xor:
2417 FirstAnswer = std::min(Tmp, Tmp2);
2428 const APInt *CLow, *CHigh;
2433 if (Tmp == 1)
break;
2435 return std::min(Tmp, Tmp2);
2442 if (Tmp == 1)
break;
2445 if (
const auto *CRHS = dyn_cast<Constant>(U->
getOperand(1)))
2446 if (CRHS->isAllOnesValue()) {
2452 if ((Known.
Zero | 1).isAllOnesValue())
2462 if (Tmp2 == 1)
break;
2463 return std::min(Tmp, Tmp2)-1;
2465 case Instruction::Sub:
2467 if (Tmp2 == 1)
break;
2470 if (
const auto *CLHS = dyn_cast<Constant>(U->
getOperand(0)))
2471 if (CLHS->isNullValue()) {
2476 if ((Known.
Zero | 1).isAllOnesValue())
2490 if (Tmp == 1)
break;
2491 return std::min(Tmp, Tmp2)-1;
2493 case Instruction::Mul: {
2496 if (SignBitsOp0 == 1)
break;
2498 if (SignBitsOp1 == 1)
break;
2499 unsigned OutValidBits =
2500 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
2501 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
2504 case Instruction::PHI: {
2505 const PHINode *PN = cast<PHINode>(U);
2508 if (NumIncomingValues > 4)
break;
2510 if (NumIncomingValues == 0)
break;
2515 for (
unsigned i = 1, e = NumIncomingValues; i != e; ++i) {
2516 if (Tmp == 1)
return Tmp;
2523 case Instruction::Trunc:
2528 case Instruction::ExtractElement:
2535 case Instruction::ShuffleVector: {
2542 auto *Shuf = cast<ShuffleVectorInst>(U);
2543 int NumElts = Shuf->getOperand(0)->getType()->getVectorNumElements();
2544 int NumMaskElts = Shuf->getMask()->getType()->getVectorNumElements();
2545 APInt DemandedLHS(NumElts, 0), DemandedRHS(NumElts, 0);
2546 for (
int i = 0; i != NumMaskElts; ++i) {
2547 int M = Shuf->getMaskValue(i);
2548 assert(M < NumElts * 2 &&
"Invalid shuffle mask constant");
2554 DemandedLHS.setBit(M % NumElts);
2556 DemandedRHS.
setBit(M % NumElts);
2561 if (!!DemandedRHS) {
2563 Tmp = std::min(Tmp, Tmp2);
2569 "Failed to determine minimum sign bits");
2595 bool LookThroughSExt,
unsigned Depth) {
2596 const unsigned MaxDepth = 6;
2598 assert(V &&
"No Value?");
2599 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2616 if (CO && CO == BaseVal) {
2627 if (Depth == MaxDepth)
return false;
2630 if (!I)
return false;
2634 case Instruction::SExt:
2635 if (!LookThroughSExt)
return false;
2638 case Instruction::ZExt:
2640 LookThroughSExt, Depth+1);
2641 case Instruction::Shl:
2642 case Instruction::Mul: {
2646 if (I->
getOpcode() == Instruction::Shl) {
2648 if (!Op1CI)
return false;
2657 Value *Mul0 =
nullptr;
2659 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
2660 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
2661 if (Op1C->getType()->getPrimitiveSizeInBits() <
2662 MulC->getType()->getPrimitiveSizeInBits())
2664 if (Op1C->getType()->getPrimitiveSizeInBits() >
2665 MulC->getType()->getPrimitiveSizeInBits())
2673 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
2674 if (Mul0CI->getValue() == 1) {
2681 Value *Mul1 =
nullptr;
2683 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
2684 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
2685 if (Op0C->getType()->getPrimitiveSizeInBits() <
2686 MulC->getType()->getPrimitiveSizeInBits())
2688 if (Op0C->getType()->getPrimitiveSizeInBits() >
2689 MulC->getType()->getPrimitiveSizeInBits())
2697 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
2698 if (Mul1CI->getValue() == 1) {
2759 case LibFunc_log10f:
2760 case LibFunc_log10l:
2778 case LibFunc_copysign:
2779 case LibFunc_copysignf:
2780 case LibFunc_copysignl:
2783 case LibFunc_floorf:
2784 case LibFunc_floorl:
2791 case LibFunc_truncf:
2792 case LibFunc_truncl:
2798 case LibFunc_nearbyint:
2799 case LibFunc_nearbyintf:
2800 case LibFunc_nearbyintl:
2803 case LibFunc_roundf:
2804 case LibFunc_roundl:
2826 if (
auto *CFP = dyn_cast<ConstantFP>(V))
2827 return !CFP->getValueAPF().isNegZero();
2830 if (Depth == MaxDepth)
2838 if (
auto *FPO = dyn_cast<FPMathOperator>(
Op))
2839 if (FPO->hasNoSignedZeros())
2847 if (isa<SIToFPInst>(
Op) || isa<UIToFPInst>(
Op))
2850 if (
auto *Call = dyn_cast<CallInst>(
Op)) {
2880 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2881 return !CFP->getValueAPF().isNegative() ||
2882 (!SignBitOnly && CFP->getValueAPF().isZero());
2886 if (
auto *CV = dyn_cast<Constant>(V)) {
2887 if (CV->getType()->isVectorTy()) {
2888 unsigned NumElts = CV->getType()->getVectorNumElements();
2889 for (
unsigned i = 0; i != NumElts; ++i) {
2890 auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
2893 if (CFP->getValueAPF().isNegative() &&
2894 (SignBitOnly || !CFP->getValueAPF().isZero()))
2903 if (Depth == MaxDepth)
2914 case Instruction::UIToFP:
2916 case Instruction::FMul:
2919 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()))
2923 case Instruction::FAdd:
2924 case Instruction::FDiv:
2925 case Instruction::FRem:
2935 case Instruction::FPExt:
2936 case Instruction::FPTrunc:
2940 case Instruction::ExtractElement:
2947 const auto *CI = cast<CallInst>(
I);
2955 SignBitOnly, Depth + 1)) ||
2958 SignBitOnly, Depth + 1));
2980 return CI->hasNoNaNs() && (CI->hasNoSignedZeros() ||
3009 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()) &&
3032 if (
auto *FPMathOp = dyn_cast<FPMathOperator>(V))
3033 if (FPMathOp->hasNoNaNs())
3037 if (
auto *CFP = dyn_cast<ConstantFP>(V))
3038 return !CFP->isNaN();
3040 if (Depth == MaxDepth)
3043 if (
auto *Inst = dyn_cast<Instruction>(V)) {
3044 switch (Inst->getOpcode()) {
3045 case Instruction::FAdd:
3046 case Instruction::FMul:
3047 case Instruction::FSub:
3048 case Instruction::FDiv:
3049 case Instruction::FRem: {
3057 case Instruction::SIToFP:
3058 case Instruction::UIToFP:
3060 case Instruction::FPTrunc:
3061 case Instruction::FPExt:
3068 if (
const auto *II = dyn_cast<IntrinsicInst>(V)) {
3069 switch (II->getIntrinsicID()) {
3096 for (
unsigned i = 0; i != NumElts; ++i) {
3097 Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
3100 if (isa<UndefValue>(Elt))
3103 if (!CElt || CElt->isNaN())
3120 if (isa<UndefValue>(V))
3140 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
3142 if (CFP->getType()->isHalfTy())
3144 else if (CFP->getType()->isFloatTy())
3146 else if (CFP->getType()->isDoubleTy())
3154 if (CI->getBitWidth() % 8 == 0) {
3155 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
3156 if (!CI->getValue().isSplat(8))
3167 if (LHS == UndefInt8)
3169 if (RHS == UndefInt8)
3175 Value *Val = UndefInt8;
3176 for (
unsigned I = 0,
E = CA->getNumElements(); I !=
E; ++
I)
3182 if (isa<ConstantVector>(C)) {
3187 if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
3188 Value *Val = UndefInt8;
3223 while (PrevTo != OrigTo) {
3249 "tmp", InsertBefore);
3266 assert(InsertBefore &&
"Must have someplace to insert!");
3271 unsigned IdxSkip = Idxs.
size();
3286 if (idx_range.
empty())
3290 "Not looking at a struct or array?");
3292 "Invalid indices for type?");
3294 if (
Constant *
C = dyn_cast<Constant>(V)) {
3295 C =
C->getAggregateElement(idx_range[0]);
3296 if (!
C)
return nullptr;
3303 const unsigned *req_idx = idx_range.
begin();
3304 for (
const unsigned *i = I->idx_begin(), *e = I->idx_end();
3305 i != e; ++i, ++req_idx) {
3306 if (req_idx == idx_range.
end()) {
3346 unsigned size = I->getNumIndices() + idx_range.
size();
3351 Idxs.
append(I->idx_begin(), I->idx_end());
3357 &&
"Number of indices added not correct?");
3371 APInt ByteOffset(BitWidth, 0);
3377 while (Visited.
insert(Ptr).second) {
3389 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
3392 APInt OrigByteOffset(ByteOffset);
3397 ByteOffset = OrigByteOffset;
3401 Ptr =
GEP->getPointerOperand();
3404 Ptr = cast<Operator>(Ptr)->getOperand(0);
3405 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
3406 if (GA->isInterposable())
3408 Ptr = GA->getAliasee();
3418 unsigned CharSize) {
3432 if (!FirstIdx || !FirstIdx->
isZero())
3440 unsigned ElementSize, uint64_t
Offset) {
3457 uint64_t StartIdx = 0;
3458 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
GEP->getOperand(2)))
3459 StartIdx = CI->getZExtValue();
3470 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
3475 if (GV->getInitializer()->isNullValue()) {
3476 Type *GVTy = GV->getValueType();
3477 if ( (ArrayTy = dyn_cast<ArrayType>(GVTy)) ) {
3481 const DataLayout &DL = GV->getParent()->getDataLayout();
3483 uint64_t Length = SizeInBytes / (ElementSize / 8);
3484 if (Length <= Offset)
3487 Slice.
Array =
nullptr;
3503 if (Offset > NumElts)
3506 Slice.
Array = Array;
3516 uint64_t
Offset,
bool TrimAtNul) {
3521 if (Slice.
Array ==
nullptr) {
3557 unsigned CharSize) {
3563 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
3564 if (!PHIs.
insert(PN).second)
3568 uint64_t LenSoFar = ~0ULL;
3569 for (
Value *IncValue : PN->incoming_values()) {
3571 if (Len == 0)
return 0;
3573 if (Len == ~0ULL)
continue;
3575 if (Len != LenSoFar && LenSoFar != ~0ULL)
3587 if (Len1 == 0)
return 0;
3589 if (Len2 == 0)
return 0;
3590 if (Len1 == ~0ULL)
return Len2;
3591 if (Len2 == ~0ULL)
return Len1;
3592 if (Len1 != Len2)
return 0;
3601 if (Slice.
Array ==
nullptr)
3605 unsigned NullIndex = 0;
3606 for (
unsigned E = Slice.
Length; NullIndex <
E; ++NullIndex) {
3611 return NullIndex + 1;
3624 return Len == ~0ULL ? 1 : Len;
3629 "getArgumentAliasingToReturnedPointer only works on nonnull calls");
3655 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3657 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3665 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
3672 unsigned MaxLookup) {
3675 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
3677 V =
GEP->getPointerOperand();
3680 V = cast<Operator>(V)->getOperand(0);
3681 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
3682 if (GA->isInterposable())
3684 V = GA->getAliasee();
3685 }
else if (isa<AllocaInst>(V)) {
3689 if (
auto *Call = dyn_cast<CallBase>(V)) {
3722 unsigned MaxLookup) {
3730 if (!Visited.
insert(P).second)
3739 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
3752 for (
Value *IncValue : PN->incoming_values())
3758 }
while (!Worklist.
empty());
3765 if (
const Operator *U = dyn_cast<Operator>(V)) {
3768 if (U->getOpcode() == Instruction::PtrToInt)
3769 return U->getOperand(0);
3777 (!isa<ConstantInt>(U->getOperand(1)) &&
3779 !isa<PHINode>(U->getOperand(1))))
3781 V = U->getOperand(0);
3803 for (
Value *V : Objs) {
3804 if (!Visited.
insert(V).second)
3820 Objects.
push_back(const_cast<Value *>(V));
3822 }
while (!Working.
empty());
3830 if (!II)
return false;
3853 case Instruction::UDiv:
3854 case Instruction::URem: {
3861 case Instruction::SDiv:
3862 case Instruction::SRem: {
3864 const APInt *Numerator, *Denominator;
3868 if (*Denominator == 0)
3871 if (*Denominator != -1)
3881 const LoadInst *LI = cast<LoadInst>(Inst);
3894 auto *CI = cast<const CallInst>(Inst);
3899 return Callee && Callee->isSpeculatable();
3901 case Instruction::VAArg:
3902 case Instruction::Alloca:
3903 case Instruction::Invoke:
3904 case Instruction::PHI:
3907 case Instruction::Br:
3908 case Instruction::IndirectBr:
3909 case Instruction::Switch:
3910 case Instruction::Unreachable:
3911 case Instruction::Fence:
3912 case Instruction::AtomicRMW:
3913 case Instruction::AtomicCmpXchg:
3914 case Instruction::LandingPad:
3915 case Instruction::Resume:
3916 case Instruction::CatchSwitch:
3917 case Instruction::CatchPad:
3918 case Instruction::CatchRet:
3919 case Instruction::CleanupPad:
3920 case Instruction::CleanupRet:
3932 bool UseInstrInfo) {
3952 if (ZeroBits >= BitWidth)
3962 (void)LHSMax.
umul_ov(RHSMax, MaxOverflow);
3996 if (SignBits > BitWidth + 1)
4004 if (SignBits == BitWidth + 1) {
4010 nullptr, UseInstrInfo);
4012 nullptr, UseInstrInfo);
4022 bool UseInstrInfo) {
4024 nullptr, UseInstrInfo);
4027 nullptr, UseInstrInfo);
4064 APInt Result = std::move(MaxLHS) + std::move(MaxRHS);
4078 APInt Result = std::move(MinLHS) + std::move(MinRHS);
4131 bool LHSOrRHSKnownNonNegative =
4133 bool LHSOrRHSKnownNegative =
4135 if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) {
4137 if ((AddKnown.
isNonNegative() && LHSOrRHSKnownNonNegative) ||
4138 (AddKnown.
isNegative() && LHSOrRHSKnownNegative)) {
4204 "Not an overflow intrinsic!");
4211 if (
const auto *EVI = dyn_cast<ExtractValueInst>(U)) {
4212 assert(EVI->getNumIndices() == 1 &&
"Obvious from CI's type");
4214 if (EVI->getIndices()[0] == 0)
4217 assert(EVI->getIndices()[0] == 1 &&
"Obvious from CI's type");
4219 for (
const auto *U : EVI->users())
4220 if (
const auto *
B = dyn_cast<BranchInst>(U)) {
4221 assert(
B->isConditional() &&
"How else is it using an i1?");
4232 auto AllUsesGuardedByBranch = [&](
const BranchInst *BI) {
4234 if (!NoWrapEdge.isSingleEdge())
4238 for (
const auto *Result : Results) {
4241 if (DT.
dominates(NoWrapEdge, Result->getParent()))
4244 for (
auto &RU : Result->uses())
4252 return llvm::any_of(GuardingBranches, AllUsesGuardedByBranch);
4262 Add, DL, AC, CxtI, DT);
4281 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
4282 return !LI->isVolatile();
4284 return !
SI->isVolatile();
4286 return !CXI->isVolatile();
4288 return !RMWI->isVolatile();
4289 if (
const MemIntrinsic *MII = dyn_cast<MemIntrinsic>(I))
4290 return !MII->isVolatile();
4293 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(I))
4294 return !CRI->unwindsToCaller();
4295 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I))
4296 return !CatchSwitch->unwindsToCaller();
4297 if (isa<ResumeInst>(I))
4299 if (isa<ReturnInst>(I))
4301 if (isa<UnreachableInst>(I))
4307 if (!CS.doesNotThrow())
4326 return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory() ||
4327 match(I, m_Intrinsic<Intrinsic::assume>()) ||
4328 match(I, m_Intrinsic<Intrinsic::sideeffect>());
4338 for (
auto I = BB->
begin(),
E = BB->
end(); I !=
E; ++
I)
4353 if (&LI == I)
return true;
4356 llvm_unreachable(
"Instruction not contained in its own parent basic block.");
4362 case Instruction::Sub:
4363 case Instruction::Xor:
4364 case Instruction::Trunc:
4365 case Instruction::BitCast:
4366 case Instruction::AddrSpaceCast:
4367 case Instruction::Mul:
4368 case Instruction::Shl:
4369 case Instruction::GetElementPtr:
4375 case Instruction::AShr:
4376 case Instruction::SExt:
4381 case Instruction::ICmp:
4399 case Instruction::AtomicCmpXchg:
4402 case Instruction::AtomicRMW:
4405 case Instruction::UDiv:
4406 case Instruction::SDiv:
4407 case Instruction::URem:
4408 case Instruction::SRem:
4430 YieldsPoison.
insert(PoisonI);
4436 while (Iter++ < MaxDepth) {
4438 if (&I != PoisonI) {
4440 if (NotPoison !=
nullptr && YieldsPoison.
count(NotPoison))
4447 if (YieldsPoison.
count(&I)) {
4457 if (Visited.
insert(NextBB).second) {
4474 if (
auto *
C = dyn_cast<ConstantFP>(V))
4477 if (
auto *
C = dyn_cast<ConstantDataVector>(V)) {
4478 if (!
C->getElementType()->isFloatingPointTy())
4480 for (
unsigned I = 0,
E =
C->getNumElements(); I <
E; ++
I) {
4481 if (
C->getElementAsAPFloat(I).isNaN())
4491 if (
auto *
C = dyn_cast<ConstantFP>(V))
4492 return !
C->isZero();
4494 if (
auto *
C = dyn_cast<ConstantDataVector>(V)) {
4495 if (!
C->getElementType()->isFloatingPointTy())
4497 for (
unsigned I = 0,
E =
C->getNumElements(); I <
E; ++
I) {
4498 if (
C->getElementAsAPFloat(I).isZero())
4521 if (CmpRHS == FalseVal) {
4543 FC1->
compare(*FC2) == APFloat::cmpResult::cmpLessThan)
4553 FC1->
compare(*FC2) == APFloat::cmpResult::cmpGreaterThan)
4569 if (CmpRHS != TrueVal) {
4735 if ((CmpLHS == TrueVal &&
match(FalseVal,
m_APInt(C2))) ||
4769 assert(X && Y &&
"Invalid operand");
4800 Value *OutputZeroVal =
nullptr;
4802 !cast<Constant>(TrueVal)->containsUndefElement())
4803 OutputZeroVal = TrueVal;
4805 !cast<Constant>(FalseVal)->containsUndefElement())
4806 OutputZeroVal = FalseVal;
4808 if (OutputZeroVal) {
4810 CmpLHS = OutputZeroVal;
4812 CmpRHS = OutputZeroVal;
4835 bool Ordered =
false;
4846 if (LHSSafe && RHSSafe) {
4876 if (TrueVal == CmpRHS && FalseVal == CmpLHS) {
4887 if (TrueVal == CmpLHS && FalseVal == CmpRHS) {
4912 auto MaybeSExtCmpLHS =
4916 if (
match(TrueVal, MaybeSExtCmpLHS)) {
4934 else if (
match(FalseVal, MaybeSExtCmpLHS)) {
4955 return matchMinMax(Pred, CmpLHS, CmpRHS, TrueVal, FalseVal, LHS, RHS, Depth);
4989 Type *SrcTy = Cast1->getSrcTy();
4990 if (
auto *Cast2 = dyn_cast<CastInst>(V2)) {
4992 if (*CastOp == Cast2->getOpcode() && SrcTy == Cast2->getSrcTy())
4993 return Cast2->getOperand(0);
5003 case Instruction::ZExt:
5007 case Instruction::SExt:
5011 case Instruction::Trunc:
5014 CmpConst->
getType() == SrcTy) {
5036 CastedTo = CmpConst;
5041 case Instruction::FPTrunc:
5044 case Instruction::FPExt:
5047 case Instruction::FPToUI:
5050 case Instruction::FPToSI:
5053 case Instruction::UIToFP:
5056 case Instruction::SIToFP:
5069 if (CastedBack !=
C)
5078 if (Depth >= MaxDepth)
5093 if (isa<FPMathOperator>(CmpI))
5105 if (*CastOp == Instruction::FPToSI || *CastOp == Instruction::FPToUI)
5108 cast<CastInst>(TrueVal)->getOperand(0),
C,
5114 if (*CastOp == Instruction::FPToSI || *CastOp == Instruction::FPToUI)
5117 C, cast<CastInst>(FalseVal)->getOperand(0),
5178 auto MatchNUWAddsToSameValue = [&](
const Value *A,
const Value *
B,
5191 if (CA->isSubsetOf(Known.
Zero) && CB->isSubsetOf(Known.
Zero))
5199 const APInt *CLHS, *CRHS;
5200 if (MatchNUWAddsToSameValue(LHS, RHS, X, CLHS, CRHS))
5201 return CLHS->
ule(*CRHS);
5238 bool &IsSwappedOps) {
5240 bool IsMatchingOps = (ALHS == BLHS && ARHS ==
BRHS);
5241 IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
5242 return IsMatchingOps || IsSwappedOps;
5250 bool AreSwappedOps) {
5277 if (Intersection.isEmptySet())
5305 APred, BPred, AreSwappedOps))
5314 if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
5316 APred, cast<ConstantInt>(ARHS), BPred, cast<ConstantInt>(BRHS)))
5338 "Expected LHS to be 'and' or 'or'.");
5340 assert(Depth <= MaxDepth &&
"Hit recursion limit");
5364 if (Depth == MaxDepth)
5388 if (LHSCmp && RHSCmp)
5394 if (LHSBO && RHSCmp) {
5395 if ((LHSBO->
getOpcode() == Instruction::And ||
5406 if (!ContextI || !ContextI->
getParent())
5423 if (TrueBB == FalseBB)
5426 assert((TrueBB == ContextBB || FalseBB == ContextBB) &&
5427 "Predecessor block does not point to successor?");
5430 bool CondIsTrue = TrueBB == ContextBB;
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.
bool isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Returns true if the given value is known be positive (i.e.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
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, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
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.
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.
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.
This class represents lattice values for constants.
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.
Optional< bool > isImpliedByDomCondition(const Value *Cond, const Instruction *ContextI, const DataLayout &DL)
Return the boolean condition value in the context of the given instruction if it is known based on do...
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.
const Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
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.
void push_back(const T &Elt)
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.
gep_type_iterator gep_type_end(const User *GEP)
const Value * getTrueValue() const
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call)
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.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
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.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
static IntegerType * getInt16Ty(LLVMContext &C)
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.
Value * getArgOperand(unsigned i) const
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.
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, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined. ...
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.
APInt shl(unsigned shiftAmt) const
Left-shift function.
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.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo=true)
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.
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, bool UseInstrInfo=true)
Return true if 'V & Mask' is known to be zero.
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...
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.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
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.
OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo=true)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Returns true if the give value is known to be non-negative.
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.
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits...
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...
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
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)
This is an important class for using LLVM in a threaded context.
static Optional< bool > isImpliedCondMatchingOperands(CmpInst::Predicate APred, CmpInst::Predicate BPred, bool AreSwappedOps)
Return true if "icmp1 APred X, Y" implies "icmp2 BPred X, Y" is true.
Conditional or Unconditional Branch instruction.
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.
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...
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
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...
brc_match< Cond_t > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
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.
bool isLifetimeStartOrEnd() const
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
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.
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
static wasm::ValType getType(const TargetRegisterClass *RC)
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.
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call)
This function returns call pointer argument that is considered the same by aliasing rules...
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 ...
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.
BlockVerifier::State From
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 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))) ...
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)
bool isGuard(const User *U)
Returns true iff U has semantics of a guard.
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 isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
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...
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.
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 Optional< bool > isImpliedCondMatchingImmOperands(CmpInst::Predicate APred, const ConstantInt *C1, CmpInst::Predicate BPred, const ConstantInt *C2)
Return true if "icmp APred X, C1" implies "icmp BPred X, C2" is true.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Returns true if the given value is known be negative (i.e.
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.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given values are known to be non-equal when defined.
bool haveNoCommonBitsSet(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if LHS and RHS have no common bits set.
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value's sign bit is 0.
Value * getReturnedArgOperand() const
If one of the arguments has the 'returned' attribute, returns its operand value.
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
bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
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())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
Given one NaN input, returns the NaN.
static bool isSignedMinMaxClamp(const Value *Select, const Value *&In, const APInt *&CLow, const APInt *&CHigh)
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...
unsigned getNumSignBits() const
Computes the number of leading bits of this APInt that are equal to its sign bit. ...
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.
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.
Type * getElementType() const
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.
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, bool UseInstrInfo=true)
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...
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
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)
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.
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)
Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
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 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.