54 #include "llvm/IR/IntrinsicsAArch64.h" 55 #include "llvm/IR/IntrinsicsX86.h" 120 std::array<const Value *, MaxDepth> Excluded;
125 unsigned NumExcluded = 0;
130 : DL(DL), AC(AC), CxtI(CxtI), DT(DT), ORE(ORE), IIQ(UseInstrInfo) {}
132 Query(
const Query &Q,
const Value *NewExcl)
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;
167 unsigned Depth,
const Query &Q);
175 Query(DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo, ORE));
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));
244 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()) {
509 case Intrinsic::assume:
510 case Intrinsic::sideeffect:
511 case Intrinsic::dbg_declare:
512 case Intrinsic::dbg_value:
513 case Intrinsic::dbg_label:
514 case Intrinsic::invariant_start:
515 case Intrinsic::invariant_end:
516 case Intrinsic::lifetime_start:
517 case Intrinsic::lifetime_end:
518 case Intrinsic::objectsize:
519 case Intrinsic::ptr_annotation:
520 case Intrinsic::var_annotation:
582 if (!Q.AC || !Q.CxtI)
588 auto CmpExcludesZero = [V](
ICmpInst *Cmp) {
596 if (Cmp->getOperand(1) != RHS)
618 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
623 "Got assumption for the wrong function!");
632 "must be an assume intrinsic");
647 unsigned Depth,
const Query &Q) {
650 if (!Q.AC || !Q.CxtI)
658 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
663 "Got assumption for the wrong function!");
672 "must be an assume intrinsic");
677 assert(BitWidth == 1 &&
"assume operand is not i1?");
683 assert(BitWidth == 1 &&
"assume operand is not i1?");
689 if (Depth == MaxDepth)
711 Known.
One |= RHSKnown.
One;
713 }
else if (
match(Cmp,
724 Known.
One |= RHSKnown.
One & MaskKnown.
One;
739 }
else if (
match(Cmp,
765 }
else if (
match(Cmp,
807 Known.
One |= RHSKnown.
One;
829 Known.
One |= RHSKnown.
One <<
C;
944 <<
"Detected conflicting code assumptions. Program may " 945 "have undefined behavior, or compiler may have " 961 unsigned Depth,
const Query &Q,
966 if (
auto *SA = dyn_cast<ConstantInt>(I->
getOperand(1))) {
967 unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
970 Known.
Zero = KZF(Known.
Zero, ShiftAmt);
971 Known.
One = KOF(Known.
One, ShiftAmt);
1010 if (!*ShifterOperandIsNonZero)
1018 for (
unsigned ShiftAmt = 0; ShiftAmt < BitWidth; ++ShiftAmt) {
1021 if ((ShiftAmt & ~ShiftAmtKZ) != ShiftAmt)
1023 if ((ShiftAmt | ShiftAmtKO) != ShiftAmt)
1028 if (ShiftAmt == 0) {
1029 if (!ShifterOperandIsNonZero.
hasValue())
1030 ShifterOperandIsNonZero =
1032 if (*ShifterOperandIsNonZero)
1036 Known.
Zero &= KZF(Known2.
Zero, ShiftAmt);
1037 Known.
One &= KOF(Known2.
One, ShiftAmt);
1047 unsigned Depth,
const Query &Q) {
1055 Q.IIQ.getMetadata(cast<LoadInst>(I), LLVMContext::MD_range))
1058 case Instruction::And: {
1073 Value *
X =
nullptr, *
Y =
nullptr;
1074 if (!Known.
Zero[0] && !Known.
One[0] &&
1083 case Instruction::Or:
1092 case Instruction::Xor: {
1100 Known.
Zero = std::move(KnownZeroOut);
1103 case Instruction::Mul: {
1104 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1109 case Instruction::UDiv: {
1119 if (RHSMaxLeadingZeros != BitWidth)
1120 LeadZ = std::min(BitWidth, LeadZ + BitWidth - RHSMaxLeadingZeros - 1);
1126 const Value *LHS =
nullptr, *RHS =
nullptr;
1136 unsigned MaxHighOnes = 0;
1137 unsigned MaxHighZeros = 0;
1173 Q.IIQ.hasNoSignedWrap(cast<Instruction>(RHS)))
1180 if (MaxHighOnes > 0)
1182 if (MaxHighZeros > 0)
1186 case Instruction::FPTrunc:
1187 case Instruction::FPExt:
1188 case Instruction::FPToUI:
1189 case Instruction::FPToSI:
1190 case Instruction::SIToFP:
1191 case Instruction::UIToFP:
1193 case Instruction::PtrToInt:
1194 case Instruction::IntToPtr:
1197 case Instruction::ZExt:
1198 case Instruction::Trunc: {
1201 unsigned SrcBitWidth;
1206 Q.DL.getPointerTypeSizeInBits(ScalarTy) :
1207 Q.DL.getTypeSizeInBits(ScalarTy);
1209 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1215 case Instruction::BitCast: {
1226 case Instruction::SExt: {
1230 Known = Known.
trunc(SrcBitWidth);
1234 Known = Known.
sext(BitWidth);
1237 case Instruction::Shl: {
1239 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1240 auto KZF = [NSW](
const APInt &KnownZero,
unsigned ShiftAmt) {
1241 APInt KZResult = KnownZero << ShiftAmt;
1250 auto KOF = [NSW](
const APInt &KnownOne,
unsigned ShiftAmt) {
1251 APInt KOResult = KnownOne << ShiftAmt;
1260 case Instruction::LShr: {
1262 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1263 APInt KZResult = KnownZero.
lshr(ShiftAmt);
1269 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1270 return KnownOne.
lshr(ShiftAmt);
1276 case Instruction::AShr: {
1278 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1279 return KnownZero.
ashr(ShiftAmt);
1282 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1283 return KnownOne.
ashr(ShiftAmt);
1289 case Instruction::Sub: {
1290 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1292 Known, Known2,
Depth, Q);
1296 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
1298 Known, Known2,
Depth, Q);
1301 case Instruction::SRem:
1303 APInt RA = Rem->getValue().abs();
1305 APInt LowBits = RA - 1;
1309 Known.
Zero = Known2.
Zero & LowBits;
1310 Known.
One = Known2.
One & LowBits;
1315 Known.
Zero |= ~LowBits;
1320 Known.
One |= ~LowBits;
1322 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1335 case Instruction::URem: {
1337 const APInt &
RA = Rem->getValue();
1339 APInt LowBits = (RA - 1);
1341 Known.
Zero |= ~LowBits;
1342 Known.
One &= LowBits;
1359 case Instruction::Alloca: {
1369 case Instruction::GetElementPtr: {
1390 unsigned Idx = cast<ConstantInt>(
Index)->getZExtValue();
1393 TrailZ = std::min<unsigned>(TrailZ,
1403 uint64_t
TypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1404 LocalKnown.
Zero = LocalKnown.
One =
APInt(GEPOpiBits, 0);
1406 TrailZ = std::min(TrailZ,
1415 case Instruction::PHI: {
1421 for (
unsigned i = 0; i != 2; ++i) {
1434 Opcode == Instruction::Sub ||
1435 Opcode == Instruction::And ||
1436 Opcode == Instruction::Or ||
1437 Opcode == Instruction::Mul) {
1468 if (OverflowOp && Q.IIQ.hasNoSignedWrap(OverflowOp)) {
1487 else if (Opcode == Instruction::Sub && LL == I) {
1495 else if (Opcode == Instruction::Mul && Known2.
isNonNegative() &&
1511 if (Depth < MaxDepth - 1 && !Known.
Zero && !Known.
One) {
1521 if (IncValue == P)
continue;
1538 if (!Known.
Zero && !Known.
One)
1545 case Instruction::Invoke:
1550 Q.IIQ.getMetadata(cast<Instruction>(I), LLVMContext::MD_range))
1558 switch (II->getIntrinsicID()) {
1560 case Intrinsic::bitreverse:
1565 case Intrinsic::bswap:
1570 case Intrinsic::ctlz: {
1576 PossibleLZ = std::min(PossibleLZ, BitWidth - 1);
1577 unsigned LowBits =
Log2_32(PossibleLZ)+1;
1581 case Intrinsic::cttz: {
1587 PossibleTZ = std::min(PossibleTZ, BitWidth - 1);
1588 unsigned LowBits =
Log2_32(PossibleTZ)+1;
1592 case Intrinsic::ctpop: {
1597 unsigned LowBits =
Log2_32(BitsPossiblySet)+1;
1603 case Intrinsic::fshr:
1604 case Intrinsic::fshl: {
1610 uint64_t ShiftAmt = SA->
urem(BitWidth);
1611 if (II->getIntrinsicID() == Intrinsic::fshr)
1612 ShiftAmt = BitWidth - ShiftAmt;
1621 Known2.
One.
shl(ShiftAmt) | Known3.
One.
lshr(BitWidth - ShiftAmt);
1624 case Intrinsic::uadd_sat:
1625 case Intrinsic::usub_sat: {
1626 bool IsAdd = II->getIntrinsicID() == Intrinsic::uadd_sat;
1633 unsigned LeadingKnown;
1642 IsAdd,
false, Known, Known2);
1647 Known.One.setHighBits(LeadingKnown);
1648 Known.Zero.clearAllBits();
1650 Known.Zero.setHighBits(LeadingKnown);
1651 Known.One.clearAllBits();
1655 case Intrinsic::x86_sse42_crc32_64_64:
1661 case Instruction::ExtractElement:
1668 case Instruction::ExtractValue:
1673 switch (II->getIntrinsicID()) {
1675 case Intrinsic::uadd_with_overflow:
1676 case Intrinsic::sadd_with_overflow:
1678 II->getArgOperand(1),
false, Known, Known2,
1681 case Intrinsic::usub_with_overflow:
1682 case Intrinsic::ssub_with_overflow:
1684 II->getArgOperand(1),
false, Known, Known2,
1687 case Intrinsic::umul_with_overflow:
1688 case Intrinsic::smul_with_overflow:
1690 Known, Known2,
Depth, Q);
1723 assert(V &&
"No Value?");
1724 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1729 "Not integer or pointer type!");
1732 unsigned ExpectedWidth = ScalarTy->
isPointerTy() ?
1733 Q.DL.getPointerTypeSizeInBits(ScalarTy) : Q.DL.getTypeSizeInBits(ScalarTy);
1734 assert(ExpectedWidth == BitWidth &&
"V and Known should have same BitWidth");
1736 (void)ExpectedWidth;
1746 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
1756 for (
unsigned i = 0,
e = CDS->getNumElements(); i !=
e; ++i) {
1757 APInt Elt = CDS->getElementAsAPInt(i);
1764 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
1768 for (
unsigned i = 0,
e = CV->getNumOperands(); i !=
e; ++i) {
1770 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
1775 const APInt &Elt = ElementCI->getValue();
1786 if (isa<UndefValue>(V))
1791 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
1795 if (Depth == MaxDepth)
1800 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1801 if (!GA->isInterposable())
1806 if (
const Operator *I = dyn_cast<Operator>(V))
1822 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1831 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1850 if (Depth++ == MaxDepth)
1853 Value *
X =
nullptr, *
Y =
nullptr;
1860 if (
const ZExtInst *ZI = dyn_cast<ZExtInst>(V))
1882 if (OrZero || Q.IIQ.hasNoUnsignedWrap(VOBO) ||
1883 Q.IIQ.hasNoSignedWrap(VOBO)) {
1902 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
1931 if (
const Instruction *I = dyn_cast<Instruction>(GEP))
1932 F = I->getFunction();
1950 GTI != GTE; ++GTI) {
1952 if (
StructType *STy = GTI.getStructTypeOrNull()) {
1953 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
1957 if (ElementOffset > 0)
1963 if (Q.DL.getTypeAllocSize(GTI.getIndexedType()) == 0)
1968 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
1979 if (Depth++ >= MaxDepth)
1992 if (isa<Constant>(V))
1998 unsigned NumUsesExplored = 0;
1999 for (
auto *U : V->
users()) {
2008 if (
auto *CalledFunc = CS.getCalledFunction())
2010 if (CS.getArgOperand(
Arg.getArgNo()) == V &&
2011 Arg.hasNonNullAttr() && DT->
dominates(CS.getInstruction(), CtxI))
2025 if (!
match(const_cast<User *>(U),
2032 for (
auto *CmpU : U->users()) {
2034 if (Visited.
insert(CmpU).second)
2037 while (!WorkList.
empty()) {
2045 if (
auto *BO = dyn_cast<BinaryOperator>(Curr))
2046 if (BO->getOpcode() == Instruction::And) {
2047 for (
auto *BOU : BO->users())
2048 if (Visited.
insert(BOU).second)
2053 if (
const BranchInst *BI = dyn_cast<BranchInst>(Curr)) {
2054 assert(BI->isConditional() &&
"uses a comparison!");
2062 DT->
dominates(cast<Instruction>(Curr), CtxI)) {
2078 for (
unsigned i = 0; i < NumRanges; ++i) {
2080 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 0));
2082 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 1));
2084 if (Range.contains(Value))
2097 if (
auto *
C = dyn_cast<Constant>(V)) {
2098 if (
C->isNullValue())
2100 if (isa<ConstantInt>(
C))
2104 if (
auto *CE = dyn_cast<ConstantExpr>(
C)) {
2106 if (CE->getOpcode() == Instruction::IntToPtr ||
2107 CE->getOpcode() == Instruction::PtrToInt)
2108 if (Q.DL.getTypeSizeInBits(CE->getOperand(0)->getType()) <=
2109 Q.DL.getTypeSizeInBits(CE->getType()))
2115 if (
auto *VecTy = dyn_cast<VectorType>(
C->
getType())) {
2116 for (
unsigned i = 0,
e = VecTy->getNumElements(); i !=
e; ++i) {
2117 Constant *Elt =
C->getAggregateElement(i);
2120 if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
2129 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2130 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
2131 GV->getType()->getAddressSpace() == 0)
2137 if (
auto *I = dyn_cast<Instruction>(V)) {
2138 if (
MDNode *Ranges = Q.IIQ.getMetadata(I, LLVMContext::MD_range)) {
2141 if (
auto *Ty = dyn_cast<IntegerType>(V->
getType())) {
2142 const APInt ZeroValue(Ty->getBitWidth(), 0);
2153 if (Depth++ >= MaxDepth)
2159 if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0)
2163 if (
const Argument *A = dyn_cast<Argument>(V))
2164 if (A->hasByValOrInAllocaAttr() || A->hasNonNullAttr())
2168 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
2169 if (Q.IIQ.getMetadata(LI, LLVMContext::MD_nonnull))
2172 if (
const auto *Call = dyn_cast<CallBase>(V)) {
2173 if (Call->isReturnNonNull())
2196 if (
auto *BCO = dyn_cast<BitCastOperator>(V))
2199 if (
auto *I2P = dyn_cast<IntToPtrInst>(V))
2200 if (Q.DL.getTypeSizeInBits(I2P->getSrcTy()) <=
2201 Q.DL.getTypeSizeInBits(I2P->getDestTy()))
2207 if (
auto *P2I = dyn_cast<PtrToIntInst>(V))
2208 if (Q.DL.getTypeSizeInBits(P2I->getSrcTy()) <=
2209 Q.DL.getTypeSizeInBits(P2I->getDestTy()))
2215 Value *
X =
nullptr, *
Y =
nullptr;
2220 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
2221 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), Depth, Q);
2228 if (Q.IIQ.hasNoUnsignedWrap(BO))
2252 auto ShiftVal = Shift->getLimitedValue(BitWidth - 1);
2303 if ((Q.IIQ.hasNoSignedWrap(BO) || Q.IIQ.hasNoUnsignedWrap(BO)) &&
2308 else if (
const SelectInst *
SI = dyn_cast<SelectInst>(V)) {
2314 else if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
2317 if (PN->getNumIncomingValues() == 2) {
2318 Value *Start = PN->getIncomingValue(0);
2319 Value *Induction = PN->getIncomingValue(1);
2320 if (isa<ConstantInt>(Induction) && !isa<ConstantInt>(Start))
2323 if (!
C->isZero() && !
C->isNegative()) {
2325 if (Q.IIQ.UseInstrInfo &&
2335 return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZero();
2337 if (AllNonZeroConstants)
2343 return Known.
One != 0;
2404 assert(isa<Operator>(Select) &&
2406 "Input should be a Select!");
2408 const Value *LHS =
nullptr, *RHS =
nullptr;
2416 const Value *LHS2 =
nullptr, *RHS2 =
nullptr;
2428 return CLow->
sle(*CHigh);
2438 if (!CV || !CV->getType()->isVectorTy())
2441 unsigned MinSignBits = TyBits;
2442 unsigned NumElts = CV->getType()->getVectorNumElements();
2443 for (
unsigned i = 0; i != NumElts; ++i) {
2445 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
2449 MinSignBits = std::min(MinSignBits, Elt->getValue().getNumSignBits());
2461 assert(Result > 0 &&
"At least one sign bit needs to be present!");
2473 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2481 Q.DL.getPointerTypeSizeInBits(ScalarTy) :
2482 Q.DL.getTypeSizeInBits(ScalarTy);
2485 unsigned FirstAnswer = 1;
2490 if (Depth == MaxDepth)
2493 if (
auto *U = dyn_cast<Operator>(V)) {
2496 case Instruction::SExt:
2497 Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
2500 case Instruction::SDiv: {
2501 const APInt *Denominator;
2513 return std::min(TyBits, NumBits + Denominator->
logBase2());
2518 case Instruction::SRem: {
2519 const APInt *Denominator;
2546 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
2547 return std::max(NumrBits, ResBits);
2552 case Instruction::AShr: {
2557 if (ShAmt->uge(TyBits))
2560 Tmp += ShAmtLimited;
2561 if (Tmp > TyBits) Tmp = TyBits;
2565 case Instruction::Shl: {
2570 if (ShAmt->
uge(TyBits) ||
2571 ShAmt->
uge(Tmp))
break;
2577 case Instruction::And:
2578 case Instruction::Or:
2579 case Instruction::Xor:
2584 FirstAnswer = std::min(Tmp, Tmp2);
2595 const APInt *CLow, *CHigh;
2600 if (Tmp == 1)
break;
2602 return std::min(Tmp, Tmp2);
2609 if (Tmp == 1)
break;
2612 if (
const auto *CRHS = dyn_cast<Constant>(U->getOperand(1)))
2613 if (CRHS->isAllOnesValue()) {
2619 if ((Known.
Zero | 1).isAllOnesValue())
2629 if (Tmp2 == 1)
break;
2630 return std::min(Tmp, Tmp2) - 1;
2632 case Instruction::Sub:
2634 if (Tmp2 == 1)
break;
2637 if (
const auto *CLHS = dyn_cast<Constant>(U->getOperand(0)))
2638 if (CLHS->isNullValue()) {
2643 if ((Known.
Zero | 1).isAllOnesValue())
2658 if (Tmp == 1)
break;
2659 return std::min(Tmp, Tmp2) - 1;
2661 case Instruction::Mul: {
2665 if (SignBitsOp0 == 1)
break;
2667 if (SignBitsOp1 == 1)
break;
2668 unsigned OutValidBits =
2669 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
2670 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
2673 case Instruction::PHI: {
2674 const PHINode *PN = cast<PHINode>(U);
2677 if (NumIncomingValues > 4)
break;
2679 if (NumIncomingValues == 0)
break;
2684 for (
unsigned i = 1,
e = NumIncomingValues; i !=
e; ++i) {
2685 if (Tmp == 1)
return Tmp;
2692 case Instruction::Trunc:
2697 case Instruction::ExtractElement:
2704 case Instruction::ShuffleVector: {
2711 auto *Shuf = cast<ShuffleVectorInst>(U);
2712 int NumElts = Shuf->getOperand(0)->getType()->getVectorNumElements();
2713 int NumMaskElts = Shuf->getMask()->getType()->getVectorNumElements();
2714 APInt DemandedLHS(NumElts, 0), DemandedRHS(NumElts, 0);
2715 for (
int i = 0; i != NumMaskElts; ++i) {
2716 int M = Shuf->getMaskValue(i);
2717 assert(M < NumElts * 2 &&
"Invalid shuffle mask constant");
2723 DemandedLHS.setBit(M % NumElts);
2725 DemandedRHS.
setBit(M % NumElts);
2730 if (!!DemandedRHS) {
2732 Tmp = std::min(Tmp, Tmp2);
2739 "Failed to determine minimum sign bits");
2766 bool LookThroughSExt,
unsigned Depth) {
2767 assert(V &&
"No Value?");
2768 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2785 if (CO && CO == BaseVal) {
2796 if (Depth == MaxDepth)
return false;
2799 if (!I)
return false;
2803 case Instruction::SExt:
2804 if (!LookThroughSExt)
return false;
2807 case Instruction::ZExt:
2809 LookThroughSExt, Depth+1);
2810 case Instruction::Shl:
2811 case Instruction::Mul: {
2815 if (I->
getOpcode() == Instruction::Shl) {
2817 if (!Op1CI)
return false;
2826 Value *Mul0 =
nullptr;
2828 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
2829 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
2830 if (Op1C->getType()->getPrimitiveSizeInBits() <
2831 MulC->getType()->getPrimitiveSizeInBits())
2833 if (Op1C->getType()->getPrimitiveSizeInBits() >
2834 MulC->getType()->getPrimitiveSizeInBits())
2842 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
2843 if (Mul0CI->getValue() == 1) {
2850 Value *Mul1 =
nullptr;
2852 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
2853 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
2854 if (Op0C->getType()->getPrimitiveSizeInBits() <
2855 MulC->getType()->getPrimitiveSizeInBits())
2857 if (Op0C->getType()->getPrimitiveSizeInBits() >
2858 MulC->getType()->getPrimitiveSizeInBits())
2866 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
2867 if (Mul1CI->getValue() == 1) {
2910 return Intrinsic::sin;
2914 return Intrinsic::cos;
2918 return Intrinsic::exp;
2922 return Intrinsic::exp2;
2926 return Intrinsic::log;
2928 case LibFunc_log10f:
2929 case LibFunc_log10l:
2930 return Intrinsic::log10;
2938 return Intrinsic::fabs;
2947 case LibFunc_copysign:
2948 case LibFunc_copysignf:
2949 case LibFunc_copysignl:
2950 return Intrinsic::copysign;
2952 case LibFunc_floorf:
2953 case LibFunc_floorl:
2954 return Intrinsic::floor;
2958 return Intrinsic::ceil;
2960 case LibFunc_truncf:
2961 case LibFunc_truncl:
2962 return Intrinsic::trunc;
2966 return Intrinsic::rint;
2967 case LibFunc_nearbyint:
2968 case LibFunc_nearbyintf:
2969 case LibFunc_nearbyintl:
2970 return Intrinsic::nearbyint;
2972 case LibFunc_roundf:
2973 case LibFunc_roundl:
2978 return Intrinsic::pow;
2982 return Intrinsic::sqrt;
2995 if (
auto *CFP = dyn_cast<ConstantFP>(V))
2996 return !CFP->getValueAPF().isNegZero();
2999 if (Depth == MaxDepth)
3007 if (
auto *FPO = dyn_cast<FPMathOperator>(
Op))
3008 if (FPO->hasNoSignedZeros())
3016 if (isa<SIToFPInst>(
Op) || isa<UIToFPInst>(
Op))
3019 if (
auto *Call = dyn_cast<CallInst>(
Op)) {
3025 case Intrinsic::sqrt:
3026 case Intrinsic::canonicalize:
3029 case Intrinsic::fabs:
3049 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3050 return !CFP->getValueAPF().isNegative() ||
3051 (!SignBitOnly && CFP->getValueAPF().isZero());
3055 if (
auto *CV = dyn_cast<Constant>(V)) {
3056 if (CV->getType()->isVectorTy()) {
3057 unsigned NumElts = CV->getType()->getVectorNumElements();
3058 for (
unsigned i = 0; i != NumElts; ++i) {
3059 auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
3062 if (CFP->getValueAPF().isNegative() &&
3063 (SignBitOnly || !CFP->getValueAPF().isZero()))
3072 if (Depth == MaxDepth)
3083 case Instruction::UIToFP:
3085 case Instruction::FMul:
3088 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()))
3092 case Instruction::FAdd:
3093 case Instruction::FDiv:
3094 case Instruction::FRem:
3104 case Instruction::FPExt:
3105 case Instruction::FPTrunc:
3109 case Instruction::ExtractElement:
3116 const auto *CI = cast<CallInst>(
I);
3124 SignBitOnly, Depth + 1)) ||
3127 SignBitOnly, Depth + 1));
3140 case Intrinsic::exp:
3141 case Intrinsic::exp2:
3142 case Intrinsic::fabs:
3145 case Intrinsic::sqrt:
3149 return CI->hasNoNaNs() && (CI->hasNoSignedZeros() ||
3152 case Intrinsic::powi:
3174 case Intrinsic::fma:
3175 case Intrinsic::fmuladd:
3178 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()) &&
3201 if (
auto *FPMathOp = dyn_cast<FPMathOperator>(V))
3202 if (FPMathOp->hasNoInfs())
3206 if (
auto *CFP = dyn_cast<ConstantFP>(V))
3207 return !CFP->isInfinity();
3209 if (Depth == MaxDepth)
3212 if (
auto *Inst = dyn_cast<Instruction>(V)) {
3213 switch (Inst->getOpcode()) {
3218 case Instruction::UIToFP:
3221 Inst->getType()->getScalarType()->getFltSemantics())) >=
3222 (int)Inst->getOperand(0)->getType()->getScalarSizeInBits();
3234 for (
unsigned i = 0; i != NumElts; ++i) {
3235 Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
3238 if (isa<UndefValue>(Elt))
3241 if (!CElt || CElt->isInfinity())
3253 if (
auto *FPMathOp = dyn_cast<FPMathOperator>(V))
3254 if (FPMathOp->hasNoNaNs())
3258 if (
auto *CFP = dyn_cast<ConstantFP>(V))
3259 return !CFP->isNaN();
3261 if (Depth == MaxDepth)
3264 if (
auto *Inst = dyn_cast<Instruction>(V)) {
3265 switch (Inst->getOpcode()) {
3266 case Instruction::FAdd:
3267 case Instruction::FSub:
3274 case Instruction::FMul:
3282 case Instruction::FDiv:
3283 case Instruction::FRem:
3291 case Instruction::SIToFP:
3292 case Instruction::UIToFP:
3294 case Instruction::FPTrunc:
3295 case Instruction::FPExt:
3302 if (
const auto *II = dyn_cast<IntrinsicInst>(V)) {
3303 switch (II->getIntrinsicID()) {
3304 case Intrinsic::canonicalize:
3305 case Intrinsic::fabs:
3306 case Intrinsic::copysign:
3307 case Intrinsic::exp:
3308 case Intrinsic::exp2:
3309 case Intrinsic::floor:
3310 case Intrinsic::ceil:
3311 case Intrinsic::trunc:
3312 case Intrinsic::rint:
3313 case Intrinsic::nearbyint:
3316 case Intrinsic::sqrt:
3335 for (
unsigned i = 0; i != NumElts; ++i) {
3336 Constant *Elt = cast<Constant>(V)->getAggregateElement(i);
3339 if (isa<UndefValue>(Elt))
3342 if (!CElt || CElt->isNaN())
3359 if (isa<UndefValue>(V))
3383 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
3385 if (CFP->getType()->isHalfTy())
3387 else if (CFP->getType()->isFloatTy())
3389 else if (CFP->getType()->isDoubleTy())
3398 if (CI->getBitWidth() % 8 == 0) {
3399 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
3400 if (!CI->getValue().isSplat(8))
3406 if (
auto *CE = dyn_cast<ConstantExpr>(C)) {
3407 if (CE->getOpcode() == Instruction::IntToPtr) {
3409 cast<PointerType>(CE->getType())->getAddressSpace());
3422 if (LHS == UndefInt8)
3424 if (RHS == UndefInt8)
3430 Value *Val = UndefInt8;
3431 for (
unsigned I = 0,
E = CA->getNumElements(); I !=
E; ++
I)
3437 if (isa<ConstantAggregate>(C)) {
3438 Value *Val = UndefInt8;
3473 while (PrevTo != OrigTo) {
3499 "tmp", InsertBefore);
3516 assert(InsertBefore &&
"Must have someplace to insert!");
3521 unsigned IdxSkip = Idxs.
size();
3536 if (idx_range.
empty())
3540 "Not looking at a struct or array?");
3542 "Invalid indices for type?");
3544 if (
Constant *
C = dyn_cast<Constant>(V)) {
3545 C =
C->getAggregateElement(idx_range[0]);
3546 if (!
C)
return nullptr;
3553 const unsigned *req_idx = idx_range.
begin();
3554 for (
const unsigned *i = I->idx_begin(), *
e = I->idx_end();
3555 i !=
e; ++i, ++req_idx) {
3556 if (req_idx == idx_range.
end()) {
3596 unsigned size = I->getNumIndices() + idx_range.
size();
3601 Idxs.
append(I->idx_begin(), I->idx_end());
3607 &&
"Number of indices added not correct?");
3617 unsigned CharSize) {
3631 if (!FirstIdx || !FirstIdx->
isZero())
3639 unsigned ElementSize, uint64_t
Offset) {
3656 uint64_t StartIdx = 0;
3657 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
GEP->getOperand(2)))
3658 StartIdx = CI->getZExtValue();
3669 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
3674 if (GV->getInitializer()->isNullValue()) {
3675 Type *GVTy = GV->getValueType();
3676 if ( (ArrayTy = dyn_cast<ArrayType>(GVTy)) ) {
3680 const DataLayout &DL = GV->getParent()->getDataLayout();
3682 uint64_t Length = SizeInBytes / (ElementSize / 8);
3683 if (Length <= Offset)
3686 Slice.
Array =
nullptr;
3702 if (Offset > NumElts)
3705 Slice.
Array = Array;
3715 uint64_t
Offset,
bool TrimAtNul) {
3720 if (Slice.
Array ==
nullptr) {
3756 unsigned CharSize) {
3762 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
3763 if (!PHIs.
insert(PN).second)
3767 uint64_t LenSoFar = ~0ULL;
3768 for (
Value *IncValue : PN->incoming_values()) {
3770 if (Len == 0)
return 0;
3772 if (Len == ~0ULL)
continue;
3774 if (Len != LenSoFar && LenSoFar != ~0ULL)
3786 if (Len1 == 0)
return 0;
3788 if (Len2 == 0)
return 0;
3789 if (Len1 == ~0ULL)
return Len2;
3790 if (Len2 == ~0ULL)
return Len1;
3791 if (Len1 != Len2)
return 0;
3800 if (Slice.
Array ==
nullptr)
3804 unsigned NullIndex = 0;
3805 for (
unsigned E = Slice.
Length; NullIndex <
E; ++NullIndex) {
3810 return NullIndex + 1;
3823 return Len == ~0ULL ? 1 : Len;
3828 bool MustPreserveNullness) {
3830 "getArgumentAliasingToReturnedPointer only works on nonnull calls");
3835 Call, MustPreserveNullness))
3841 const CallBase *Call,
bool MustPreserveNullness) {
3842 return Call->
getIntrinsicID() == Intrinsic::launder_invariant_group ||
3846 (!MustPreserveNullness &&
3861 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3863 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3871 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
3878 unsigned MaxLookup) {
3881 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
3883 V =
GEP->getPointerOperand();
3886 V = cast<Operator>(V)->getOperand(0);
3887 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
3888 if (GA->isInterposable())
3890 V = GA->getAliasee();
3891 }
else if (isa<AllocaInst>(V)) {
3895 if (
auto *Call = dyn_cast<CallBase>(V)) {
3929 unsigned MaxLookup) {
3937 if (!Visited.
insert(P).second)
3940 if (
auto *
SI = dyn_cast<SelectInst>(P)) {
3946 if (
auto *PN = dyn_cast<PHINode>(P)) {
3959 for (
Value *IncValue : PN->incoming_values())
3965 }
while (!Worklist.
empty());
3972 if (
const Operator *U = dyn_cast<Operator>(V)) {
3975 if (U->getOpcode() == Instruction::PtrToInt)
3976 return U->getOperand(0);
3984 (!isa<ConstantInt>(U->getOperand(1)) &&
3986 !isa<PHINode>(U->getOperand(1))))
3988 V = U->getOperand(0);
4010 for (
const Value *V : Objs) {
4011 if (!Visited.
insert(V).second)
4027 Objects.
push_back(const_cast<Value *>(V));
4029 }
while (!Working.
empty());
4037 if (!II)
return false;
4072 case Instruction::UDiv:
4073 case Instruction::URem: {
4080 case Instruction::SDiv:
4081 case Instruction::SRem: {
4083 const APInt *Numerator, *Denominator;
4087 if (*Denominator == 0)
4090 if (*Denominator != -1)
4100 const LoadInst *LI = cast<LoadInst>(Inst);
4109 auto *CI = cast<const CallInst>(Inst);
4114 return Callee && Callee->isSpeculatable();
4116 case Instruction::VAArg:
4117 case Instruction::Alloca:
4118 case Instruction::Invoke:
4119 case Instruction::CallBr:
4120 case Instruction::PHI:
4123 case Instruction::Br:
4124 case Instruction::IndirectBr:
4125 case Instruction::Switch:
4126 case Instruction::Unreachable:
4127 case Instruction::Fence:
4128 case Instruction::AtomicRMW:
4129 case Instruction::AtomicCmpXchg:
4130 case Instruction::LandingPad:
4131 case Instruction::Resume:
4132 case Instruction::CatchSwitch:
4133 case Instruction::CatchPad:
4134 case Instruction::CatchRet:
4135 case Instruction::CleanupPad:
4136 case Instruction::CleanupRet:
4166 V, DL, Depth, AC, CxtI, DT, ORE, UseInstrInfo);
4177 bool UseInstrInfo) {
4179 nullptr, UseInstrInfo);
4181 nullptr, UseInstrInfo);
4207 if (SignBits > BitWidth + 1)
4215 if (SignBits == BitWidth + 1) {
4221 nullptr, UseInstrInfo);
4223 nullptr, UseInstrInfo);
4233 bool UseInstrInfo) {
4235 LHS,
false, DL, 0, AC, CxtI, DT,
4236 nullptr, UseInstrInfo);
4238 RHS,
false, DL, 0, AC, CxtI, DT,
4239 nullptr, UseInstrInfo);
4273 LHS,
true, DL, 0, AC, CxtI, DT);
4275 RHS,
true, DL, 0, AC, CxtI, DT);
4290 bool LHSOrRHSKnownNonNegative =
4292 bool LHSOrRHSKnownNegative =
4294 if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) {
4297 Add, AddKnown, 0, Query(DL, AC, CxtI, DT,
true));
4298 if ((AddKnown.isNonNegative() && LHSOrRHSKnownNonNegative) ||
4299 (AddKnown.isNegative() && LHSOrRHSKnownNegative))
4313 LHS,
false, DL, 0, AC, CxtI, DT);
4315 RHS,
false, DL, 0, AC, CxtI, DT);
4332 LHS,
true, DL, 0, AC, CxtI, DT);
4334 RHS,
true, DL, 0, AC, CxtI, DT);
4344 if (
const auto *EVI = dyn_cast<ExtractValueInst>(U)) {
4345 assert(EVI->getNumIndices() == 1 &&
"Obvious from CI's type");
4347 if (EVI->getIndices()[0] == 0)
4350 assert(EVI->getIndices()[0] == 1 &&
"Obvious from CI's type");
4352 for (
const auto *U : EVI->users())
4353 if (
const auto *
B = dyn_cast<BranchInst>(U)) {
4354 assert(
B->isConditional() &&
"How else is it using an i1?");
4365 auto AllUsesGuardedByBranch = [&](
const BranchInst *BI) {
4367 if (!NoWrapEdge.isSingleEdge())
4371 for (
const auto *Result : Results) {
4374 if (DT.
dominates(NoWrapEdge, Result->getParent()))
4377 for (
auto &RU : Result->uses())
4385 return llvm::any_of(GuardingBranches, AllUsesGuardedByBranch);
4391 if (isa<FreezeInst>(V))
4397 if (isa<ConstantInt>(V) || isa<GlobalVariable>(V))
4409 Add, DL, AC, CxtI, DT);
4427 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(I))
4428 return !CRI->unwindsToCaller();
4429 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I))
4430 return !CatchSwitch->unwindsToCaller();
4431 if (isa<ResumeInst>(I))
4433 if (isa<ReturnInst>(I))
4435 if (isa<UnreachableInst>(I))
4441 if (!CS.doesNotThrow())
4446 if (CS.hasFnAttr(Attribute::WillReturn))
4465 return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory();
4475 for (
auto I = BB->
begin(),
E = BB->
end(); I !=
E; ++
I)
4490 if (&LI == I)
return true;
4493 llvm_unreachable(
"Instruction not contained in its own parent basic block.");
4501 case Instruction::Sub:
4502 case Instruction::Xor:
4503 case Instruction::Trunc:
4504 case Instruction::BitCast:
4505 case Instruction::AddrSpaceCast:
4506 case Instruction::Mul:
4507 case Instruction::Shl:
4508 case Instruction::GetElementPtr:
4514 case Instruction::AShr:
4515 case Instruction::SExt:
4520 case Instruction::ICmp:
4538 case Instruction::AtomicCmpXchg:
4541 case Instruction::AtomicRMW:
4544 case Instruction::UDiv:
4545 case Instruction::SDiv:
4546 case Instruction::URem:
4547 case Instruction::SRem:
4562 return (NotPoison && KnownPoison.
count(NotPoison));
4580 YieldsPoison.
insert(PoisonI);
4586 while (Iter++ < MaxDepth) {
4588 if (&I != PoisonI) {
4596 if (YieldsPoison.
count(&I)) {
4606 if (Visited.
insert(NextBB).second) {
4623 if (
auto *
C = dyn_cast<ConstantFP>(V))
4626 if (
auto *
C = dyn_cast<ConstantDataVector>(V)) {
4627 if (!
C->getElementType()->isFloatingPointTy())
4629 for (
unsigned I = 0,
E =
C->getNumElements(); I <
E; ++
I) {
4630 if (
C->getElementAsAPFloat(I).isNaN())
4640 if (
auto *
C = dyn_cast<ConstantFP>(V))
4641 return !
C->isZero();
4643 if (
auto *
C = dyn_cast<ConstantDataVector>(V)) {
4644 if (!
C->getElementType()->isFloatingPointTy())
4646 for (
unsigned I = 0,
E =
C->getNumElements(); I <
E; ++
I) {
4647 if (
C->getElementAsAPFloat(I).isZero())
4670 if (CmpRHS == FalseVal) {
4692 FC1->
compare(*FC2) == APFloat::cmpResult::cmpLessThan)
4702 FC1->
compare(*FC2) == APFloat::cmpResult::cmpGreaterThan)
4718 if (CmpRHS != TrueVal) {
4757 Value *A =
nullptr, *
B =
nullptr;
4762 Value *
C =
nullptr, *
D =
nullptr;
4884 if ((CmpLHS == TrueVal &&
match(FalseVal,
m_APInt(C2))) ||
4918 assert(X && Y &&
"Invalid operand");
4949 Value *OutputZeroVal =
nullptr;
4951 !cast<Constant>(TrueVal)->containsUndefElement())
4952 OutputZeroVal = TrueVal;
4954 !cast<Constant>(FalseVal)->containsUndefElement())
4955 OutputZeroVal = FalseVal;
4957 if (OutputZeroVal) {
4959 CmpLHS = OutputZeroVal;
4961 CmpRHS = OutputZeroVal;
4984 bool Ordered =
false;
4995 if (LHSSafe && RHSSafe) {
5025 if (TrueVal == CmpRHS && FalseVal == CmpLHS) {
5036 if (TrueVal == CmpLHS && FalseVal == CmpRHS) {
5061 auto MaybeSExtCmpLHS =
5065 if (
match(TrueVal, MaybeSExtCmpLHS)) {
5087 else if (
match(FalseVal, MaybeSExtCmpLHS)) {
5108 return matchMinMax(Pred, CmpLHS, CmpRHS, TrueVal, FalseVal, LHS, RHS, Depth);
5142 Type *SrcTy = Cast1->getSrcTy();
5143 if (
auto *Cast2 = dyn_cast<CastInst>(V2)) {
5145 if (*CastOp == Cast2->getOpcode() && SrcTy == Cast2->getSrcTy())
5146 return Cast2->getOperand(0);
5156 case Instruction::ZExt:
5160 case Instruction::SExt:
5164 case Instruction::Trunc:
5167 CmpConst->
getType() == SrcTy) {
5189 CastedTo = CmpConst;
5194 case Instruction::FPTrunc:
5197 case Instruction::FPExt:
5200 case Instruction::FPToUI:
5203 case Instruction::FPToSI:
5206 case Instruction::UIToFP:
5209 case Instruction::SIToFP:
5222 if (CastedBack !=
C)
5231 if (Depth >= MaxDepth)
5254 if (isa<FPMathOperator>(CmpI))
5266 if (*CastOp == Instruction::FPToSI || *CastOp == Instruction::FPToUI)
5269 cast<CastInst>(TrueVal)->getOperand(0),
C,
5275 if (*CastOp == Instruction::FPToSI || *CastOp == Instruction::FPToUI)
5278 C, cast<CastInst>(FalseVal)->getOperand(0),
5339 auto MatchNUWAddsToSameValue = [&](
const Value *A,
const Value *
B,
5352 if (CA->isSubsetOf(Known.
Zero) && CB->isSubsetOf(Known.
Zero))
5360 const APInt *CLHS, *CRHS;
5361 if (MatchNUWAddsToSameValue(LHS, RHS, X, CLHS, CRHS))
5362 return CLHS->
ule(*CRHS);
5399 bool &IsSwappedOps) {
5401 bool IsMatchingOps = (ALHS == BLHS && ARHS ==
BRHS);
5402 IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
5403 return IsMatchingOps || IsSwappedOps;
5411 bool AreSwappedOps) {
5438 if (Intersection.isEmptySet())
5466 APred, BPred, AreSwappedOps))
5475 if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
5477 APred, cast<ConstantInt>(ARHS), BPred, cast<ConstantInt>(BRHS)))
5499 "Expected LHS to be 'and' or 'or'.");
5501 assert(Depth <= MaxDepth &&
"Hit recursion limit");
5525 if (Depth == MaxDepth)
5549 if (LHSCmp && RHSCmp)
5555 if (LHSBO && RHSCmp) {
5556 if ((LHSBO->
getOpcode() == Instruction::And ||
5567 if (!ContextI || !ContextI->
getParent())
5584 if (TrueBB == FalseBB)
5587 assert((TrueBB == ContextBB || FalseBB == ContextBB) &&
5588 "Predecessor block does not point to successor?");
5591 bool CondIsTrue = TrueBB == ContextBB;
5606 }
else if (IIQ.
hasNoSignedWrap(cast<OverflowingBinaryOperator>(&BO))) {
5620 case Instruction::And:
5626 case Instruction::Or:
5632 case Instruction::AShr:
5638 unsigned ShiftAmount = Width - 1;
5644 Upper = C->
ashr(ShiftAmount) + 1;
5647 Lower = C->
ashr(ShiftAmount);
5653 case Instruction::LShr:
5659 unsigned ShiftAmount = Width - 1;
5662 Lower = C->
lshr(ShiftAmount);
5667 case Instruction::Shl:
5677 Lower = C->
shl(ShiftAmount);
5683 Upper = C->
shl(ShiftAmount) + 1;
5689 case Instruction::SDiv:
5701 Lower = IntMin.
sdiv(*C);
5702 Upper = IntMax.
sdiv(*C);
5703 if (Lower.
sgt(Upper))
5706 assert(Upper != Lower &&
"Upper part of range has wrapped!");
5712 Upper = Lower.
lshr(1) + 1;
5715 Upper = C->
abs() + 1;
5716 Lower = (-Upper) + 1;
5721 case Instruction::UDiv:
5731 case Instruction::SRem:
5735 Lower = (-Upper) + 1;
5739 case Instruction::URem:
5755 case Intrinsic::uadd_sat:
5761 case Intrinsic::sadd_sat:
5775 case Intrinsic::usub_sat:
5783 case Intrinsic::ssub_sat:
5813 const Value *LHS =
nullptr, *RHS =
nullptr;
5836 Upper =
APInt(BitWidth, 1);
5875 if (
auto *BO = dyn_cast<BinaryOperator>(V))
5877 else if (
auto *II = dyn_cast<IntrinsicInst>(V))
5879 else if (
auto *
SI = dyn_cast<SelectInst>(V))
5884 if (
auto *I = dyn_cast<Instruction>(V))
5885 if (
auto *Range = IIQ.
getMetadata(I, LLVMContext::MD_range))
5895 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
5948 int64_t OffsetVal = 0;
5949 bool HasSameBase =
false;
5968 auto Offset = getOffsetFromBase(GEP1, Ptr2);
5973 auto Offset = getOffsetFromBase(GEP2, Ptr1);
5983 if (!GEP1 || !GEP2 || GEP1->
getOperand(0) != GEP2->getOperand(0))
5988 for (; Idx != GEP1->
getNumOperands() && Idx != GEP2->getNumOperands(); ++Idx)
5989 if (GEP1->
getOperand(Idx) != GEP2->getOperand(Idx))
5994 if (!Offset1 || !Offset2)
5996 return *Offset2 - *Offset1;
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
APInt abs() const
Get the absolute value;.
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...
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.
ValTy * getReturnedArgOperand() const
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. ...
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 ConstantRange computeConstantRangeIncludingKnownBits(const Value *V, bool ForSigned, const DataLayout &DL, unsigned Depth, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Combine constant ranges from computeConstantRange() and computeKnownBits().
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.
static unsigned ComputeNumSignBits(const Value *V, unsigned Depth, const Query &Q)
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
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.
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
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
Always overflows in the direction of signed/unsigned min value.
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)
Represents an op.with.overflow intrinsic.
bool isGuaranteedNotToBeUndefOrPoison(const Value *V)
Return true if this function can prove that V is never undef value or poison value.
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...
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
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.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
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.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
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
OverflowResult unsignedAddMayOverflow(const ConstantRange &Other) const
Return whether unsigned add of the two ranges always/never overflows.
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
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, MaybeAlign Alignment, 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...
Always overflows in the direction of signed/unsigned min value.
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 greater than comparison.
bool mustSuppressSpeculation(const LoadInst &LI)
Return true if speculation of the given load must be suppressed to avoid ordering or interfering with...
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.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
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
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
OverflowResult signedAddMayOverflow(const ConstantRange &Other) const
Return whether signed add of the two ranges always/never overflows.
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.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
static ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)
Initialize a range based on a known bits constraint.
static IntegerType * getInt64Ty(LLVMContext &C)
ConstantRange computeConstantRange(const Value *V, bool UseInstrInfo=true)
Determine the possible constant range of an integer or vector of integer value.
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
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...
LLVM_READONLY APFloat maximum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 maximum semantics.
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.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
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.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
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 isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(const CallBase *Call, bool MustPreserveNullness)
{launder,strip}.invariant.group returns pointer that aliases its argument, and it only captures point...
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.
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.
Value * getArgOperand(unsigned i) const
unsigned 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...
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)
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
const Value * getLoadStorePointerOperand(const Value *V)
A helper function that returns the pointer operand of a load or store instruction.
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.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
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
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.
LLVM_READONLY APFloat minimum(const APFloat &A, const APFloat &B)
Implements IEEE 754-2018 minimum semantics.
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.
bool hasNoUnsignedWrap(const InstT *Op) const
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static Optional< int64_t > getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL)
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)
KnownBits zextOrTrunc(unsigned BitWidth, bool ExtendedBitsAreKnownZero) const
Extends or truncates the underlying known Zero and One bits.
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 ConstantRange getNonEmpty(APInt Lower, APInt Upper)
Create non-empty constant range with the given bounds.
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.
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.
bool isOverflowIntrinsicNoWrap(const WithOverflowInst *WO, const DominatorTree &DT)
Returns true if the arithmetic part of the WO 's result is used only along the paths control dependen...
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.
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
OverflowResult unsignedMulMayOverflow(const ConstantRange &Other) const
Return whether unsigned mul of the two ranges always/never overflows.
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
Class to represent array types.
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)
SelectPatternResult matchDecomposedSelectPattern(CmpInst *CmpI, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Determine the pattern that a select with the given compare as its predicate and given values as its t...
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
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.
OverflowResult
Represents whether an operation on the given constant range is known to always or never overflow...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
bool isAllNegative() const
Return true if all values in this range are negative.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
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.
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
static void setLimitsForSelectPattern(const SelectInst &SI, APInt &Lower, APInt &Upper, const InstrInfoQuery &IIQ)
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)
bool isExact(const BinaryOperator *Op) const
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
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)
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
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.
bool isAllNonNegative() const
Return true if all values in this range are non-negative.
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.
void GetUnderlyingObjects(const Value *V, SmallVectorImpl< const 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...
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.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
bool isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if the floating-point scalar value is not an infinity or if the floating-point vector val...
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.
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
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.
static void setLimitsForIntrinsic(const IntrinsicInst &II, APInt &Lower, APInt &Upper)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
size_t size() const
size - Get the array size.
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.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
MaybeAlign getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
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...
bool mustTriggerUB(const Instruction *I, const SmallSet< const Value *, 16 > &KnownPoison)
Return true if the given instruction must trigger undefined behavior.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
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...
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)
Always overflows in the direction of signed/unsigned max value.
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.
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()
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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. ...
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.
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.
static bool isKnownNonZeroFromAssume(const Value *V, const Query &Q)
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 address space casts.
unsigned 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...
OverflowResult signedSubMayOverflow(const ConstantRange &Other) const
Return whether signed sub of the two ranges always/never overflows.
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)
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...
OverflowResult unsignedSubMayOverflow(const ConstantRange &Other) const
Return whether unsigned sub of the two ranges always/never overflows.
#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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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 aggregate and an sequence of indices, see if the scalar value indexed is already around as a...
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.
Value * isBytewiseValue(Value *V, const DataLayout &DL)
If the specified value can be set by repeating the same byte in memory, return the i8 value that it i...
bool isEmptySet() const
Return true if this set contains no members.
Given one NaN input, returns the non-NaN.
static OverflowResult mapOverflowResult(ConstantRange::OverflowResult OR)
Convert ConstantRange OverflowResult into ValueTracking OverflowResult.
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.
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
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call, bool MustPreserveNullness)
This function returns call pointer argument that is considered the same by aliasing rules...
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.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
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)
LLVM_NODISCARD T pop_back_val()
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static void setLimitsForBinOp(const BinaryOperator &BO, APInt &Lower, APInt &Upper, const InstrInfoQuery &IIQ)
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.
KnownBits sext(unsigned BitWidth) const
Sign extends the underlying known Zero and One bits.
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)
KnownBits trunc(unsigned BitWidth) const
Truncate the underlying known Zero and One bits.
bool isGuard(const User *U)
Returns true iff U has semantics of a guard expressed in a form of call of llvm.experimental.guard intrinsic.
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
Optional< int64_t > isPointerOffset(const Value *Ptr1, const Value *Ptr2, const DataLayout &DL)
If Ptr1 is provably equal to Ptr2 plus a constant offset, return that offset.
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.
amdgpu Simplify well known AMD library false FunctionCallee Callee
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.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
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)
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 greater than comparison.
Predicate getPredicate() const
Return the predicate for this instruction.
Always overflows in the direction of signed/unsigned max value.
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.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
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.
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 ...
static APFloat getLargest(const fltSemantics &Sem, bool Negative=false)
Returns the largest finite number in the given semantics.
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...
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
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.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
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.
PreferredRangeType
If represented precisely, the result of some range operations may consist of multiple disjoint ranges...
bool isEquality() const
This is just a convenience that dispatches to the subclasses.
1 0 1 1 True if unordered, greater than, or equal
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...
unsigned countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
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.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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.
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.
Type * getSourceElementType() const
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
unsigned countLeadingOnes() const
Count the number of leading one bits.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
APInt getMaxValue() const
Return the maximal value possible given these KnownBits.
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...
static APInt getNullValue(unsigned numBits)
Get the '0' value.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
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.
0 0 1 1 True if ordered and greater than or equal
bool hasNoSignedWrap(const InstT *Op) const
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.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
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'.
int ilogb(const IEEEFloat &Arg)
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.