48 using namespace llvm::PatternMatch;
94 std::array<const Value *, MaxDepth> Excluded;
99 : DL(DL), AC(AC), CxtI(CxtI), DT(DT), ORE(ORE), NumExcluded(0) {}
102 :
DL(Q.
DL), AC(Q.AC), CxtI(Q.CxtI), DT(Q.DT), ORE(Q.ORE),
103 NumExcluded(Q.NumExcluded) {
104 Excluded = Q.Excluded;
105 Excluded[NumExcluded++] = NewExcl;
106 assert(NumExcluded <= Excluded.size());
110 if (NumExcluded == 0)
112 auto End = Excluded.begin() + NumExcluded;
163 "LHS and RHS should have the same type");
165 "LHS and RHS should be integers");
171 return (LHSKnown.Zero | RHSKnown.Zero).isAllOnesValue();
177 if (
const ICmpInst *IC = dyn_cast<ICmpInst>(U))
178 if (IC->isEquality())
179 if (
Constant *
C = dyn_cast<Constant>(IC->getOperand(1)))
180 if (
C->isNullValue())
218 if (
auto *CI = dyn_cast<ConstantInt>(V))
219 return CI->getValue().isStrictlyPositive();
279 uint64_t CarryIn = 0;
286 APInt PossibleSumZero = ~LHSKnown.
Zero + ~Known2.
Zero + CarryIn;
287 APInt PossibleSumOne = LHSKnown.
One + Known2.
One + CarryIn;
290 APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnown.
Zero ^ Known2.
Zero);
291 APInt CarryKnownOne = PossibleSumOne ^ LHSKnown.
One ^ Known2.
One;
296 APInt CarryKnownUnion = CarryKnownZero | CarryKnownOne;
297 APInt Known = LHSKnownUnion & RHSKnownUnion & CarryKnownUnion;
299 assert((PossibleSumZero & Known) == (PossibleSumOne & Known) &&
300 "known bits of sum differ");
303 KnownOut.
Zero = ~PossibleSumOne & Known;
304 KnownOut.
One = PossibleSumOne & Known;
307 if (!Known.isSignBitSet()) {
334 isKnownNonNegative =
true;
339 bool isKnownNegativeOp0 = Known2.
isNegative();
341 isKnownNonNegative = (isKnownNegativeOp1 && isKnownNegativeOp0) ||
342 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
345 if (!isKnownNonNegative)
346 isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
348 (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
361 BitWidth) - BitWidth;
363 TrailZ =
std::min(TrailZ, BitWidth);
374 if (isKnownNonNegative && !Known.
isNegative())
389 for (
unsigned i = 0; i < NumRanges; ++i) {
391 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 0));
393 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 1));
397 unsigned CommonPrefixBits =
401 Known.
One &= Range.getUnsignedMax() &
Mask;
402 Known.
Zero &= ~Range.getUnsignedMax() &
Mask;
417 while (!WorkSet.
empty()) {
419 if (!Visited.
insert(V).second)
428 if (
const User *U = dyn_cast<User>(V))
442 if (
const CallInst *CI = dyn_cast<CallInst>(I))
443 if (
Function *
F = CI->getCalledFunction())
444 switch (
F->getIntrinsicID()) {
447 case Intrinsic::assume:
448 case Intrinsic::dbg_declare:
449 case Intrinsic::dbg_value:
450 case Intrinsic::invariant_start:
451 case Intrinsic::invariant_end:
452 case Intrinsic::lifetime_start:
453 case Intrinsic::lifetime_end:
454 case Intrinsic::objectsize:
455 case Intrinsic::ptr_annotation:
456 case Intrinsic::var_annotation:
515 if (!Q.AC || !Q.CxtI)
523 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
528 "Got assumption for the wrong function!");
537 "must be an assume intrinsic");
542 assert(BitWidth == 1 &&
"assume operand is not i1?");
548 assert(BitWidth == 1 &&
"assume operand is not i1?");
570 Known.
One |= RHSKnown.
One;
572 }
else if (
match(Arg,
584 Known.
One |= RHSKnown.
One & MaskKnown.
One;
600 }
else if (
match(Arg,
628 }
else if (
match(Arg,
673 Known.
One |= RHSKnown.
One;
688 }
else if (
match(Arg,
790 Q.ORE->emit(ORA <<
"Detected conflicting code assumptions. Program may "
791 "have undefined behavior, or compiler may have "
812 if (
auto *SA = dyn_cast<ConstantInt>(I->
getOperand(1))) {
813 unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
816 Known.
Zero = KZF(Known.
Zero, ShiftAmt);
817 Known.
One = KOF(Known.
One, ShiftAmt);
821 if ((Known.
Zero & Known.
One) != 0)
831 if ((~Known.
Zero).uge(BitWidth)) {
854 ShifterOperandIsNonZero =
856 if (!*ShifterOperandIsNonZero)
864 for (
unsigned ShiftAmt = 0; ShiftAmt < BitWidth; ++ShiftAmt) {
867 if ((ShiftAmt & ~ShiftAmtKZ) != ShiftAmt)
869 if ((ShiftAmt | ShiftAmtKO) != ShiftAmt)
875 if (!ShifterOperandIsNonZero.
hasValue())
876 ShifterOperandIsNonZero =
878 if (*ShifterOperandIsNonZero)
882 Known.
Zero &= KZF(Known2.
Zero, ShiftAmt);
883 Known.
One &= KOF(Known2.
One, ShiftAmt);
896 unsigned Depth,
const Query &Q) {
906 case Instruction::And: {
922 if (!Known.
Zero[0] && !Known.
One[0] &&
934 case Instruction::Or: {
944 case Instruction::Xor: {
952 Known.
Zero = std::move(KnownZeroOut);
955 case Instruction::Mul: {
956 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
961 case Instruction::UDiv: {
971 if (RHSMaxLeadingZeros != BitWidth)
972 LeadZ =
std::min(BitWidth, LeadZ + BitWidth - RHSMaxLeadingZeros - 1);
978 const Value *LHS, *RHS;
988 unsigned MaxHighOnes = 0;
989 unsigned MaxHighZeros = 0;
1025 if (MaxHighOnes > 0)
1027 if (MaxHighZeros > 0)
1031 case Instruction::FPTrunc:
1032 case Instruction::FPExt:
1033 case Instruction::FPToUI:
1034 case Instruction::FPToSI:
1035 case Instruction::SIToFP:
1036 case Instruction::UIToFP:
1038 case Instruction::PtrToInt:
1039 case Instruction::IntToPtr:
1042 case Instruction::ZExt:
1043 case Instruction::Trunc: {
1046 unsigned SrcBitWidth;
1049 SrcBitWidth = Q.DL.getTypeSizeInBits(SrcTy->
getScalarType());
1051 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1056 if (BitWidth > SrcBitWidth)
1060 case Instruction::BitCast: {
1071 case Instruction::SExt: {
1075 Known = Known.
trunc(SrcBitWidth);
1079 Known = Known.
sext(BitWidth);
1082 case Instruction::Shl: {
1084 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1085 auto KZF = [NSW](
const APInt &KnownZero,
unsigned ShiftAmt) {
1086 APInt KZResult = KnownZero << ShiftAmt;
1095 auto KOF = [NSW](
const APInt &KnownOne,
unsigned ShiftAmt) {
1096 APInt KOResult = KnownOne << ShiftAmt;
1105 case Instruction::LShr: {
1107 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1108 APInt KZResult = KnownZero.
lshr(ShiftAmt);
1114 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1115 return KnownOne.
lshr(ShiftAmt);
1121 case Instruction::AShr: {
1123 auto KZF = [](
const APInt &KnownZero,
unsigned ShiftAmt) {
1124 return KnownZero.
ashr(ShiftAmt);
1127 auto KOF = [](
const APInt &KnownOne,
unsigned ShiftAmt) {
1128 return KnownOne.
ashr(ShiftAmt);
1134 case Instruction::Sub: {
1135 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1137 Known, Known2,
Depth, Q);
1141 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1143 Known, Known2,
Depth, Q);
1146 case Instruction::SRem:
1150 APInt LowBits = RA - 1;
1154 Known.
Zero = Known2.
Zero & LowBits;
1155 Known.
One = Known2.
One & LowBits;
1160 Known.
Zero |= ~LowBits;
1165 Known.
One |= ~LowBits;
1167 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1180 case Instruction::URem: {
1182 const APInt &RA = Rem->getValue();
1184 APInt LowBits = (RA - 1);
1186 Known.
Zero |= ~LowBits;
1187 Known.
One &= LowBits;
1204 case Instruction::Alloca: {
1214 case Instruction::GetElementPtr: {
1222 for (
unsigned i = 1, e = I->
getNumOperands(); i != e; ++i, ++GTI) {
1228 Constant *CIndex = cast<Constant>(Index);
1235 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
1238 TrailZ = std::min<unsigned>(TrailZ,
1248 uint64_t TypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1249 LocalKnown.
Zero = LocalKnown.
One =
APInt(GEPOpiBits, 0);
1260 case Instruction::PHI: {
1266 for (
unsigned i = 0; i != 2; ++i) {
1277 Opcode == Instruction::Sub ||
1278 Opcode == Instruction::And ||
1279 Opcode == Instruction::Or ||
1280 Opcode == Instruction::Mul) {
1305 if (OverflowOp && OverflowOp->hasNoSignedWrap()) {
1324 else if (Opcode == Instruction::Sub && LL == I) {
1332 else if (Opcode == Instruction::Mul && Known2.
isNonNegative() &&
1357 if (IncValue == P)
continue;
1367 if (!Known.
Zero && !Known.
One)
1374 case Instruction::Invoke:
1386 switch (II->getIntrinsicID()) {
1388 case Intrinsic::bitreverse:
1393 case Intrinsic::bswap:
1398 case Intrinsic::ctlz: {
1404 PossibleLZ =
std::min(PossibleLZ, BitWidth - 1);
1405 unsigned LowBits =
Log2_32(PossibleLZ)+1;
1409 case Intrinsic::cttz: {
1415 PossibleTZ =
std::min(PossibleTZ, BitWidth - 1);
1416 unsigned LowBits =
Log2_32(PossibleTZ)+1;
1420 case Intrinsic::ctpop: {
1425 unsigned LowBits =
Log2_32(BitsPossiblySet)+1;
1431 case Intrinsic::x86_sse42_crc32_64_64:
1437 case Instruction::ExtractElement:
1444 case Instruction::ExtractValue:
1449 switch (II->getIntrinsicID()) {
1451 case Intrinsic::uadd_with_overflow:
1452 case Intrinsic::sadd_with_overflow:
1454 II->getArgOperand(1),
false, Known, Known2,
1457 case Intrinsic::usub_with_overflow:
1458 case Intrinsic::ssub_with_overflow:
1460 II->getArgOperand(1),
false, Known, Known2,
1463 case Intrinsic::umul_with_overflow:
1464 case Intrinsic::smul_with_overflow:
1466 Known, Known2,
Depth, Q);
1499 assert(V &&
"No Value?");
1505 "Not integer or pointer type!");
1507 "V and Known should have same BitWidth");
1518 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
1528 APInt Elt(BitWidth, 0);
1529 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1530 Elt = CDS->getElementAsInteger(i);
1537 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
1541 APInt Elt(BitWidth, 0);
1542 for (
unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
1544 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
1549 Elt = ElementCI->getValue();
1560 if (isa<UndefValue>(V))
1565 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
1574 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1575 if (!GA->isInterposable())
1580 if (
const Operator *I = dyn_cast<Operator>(V))
1596 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
1605 if (
const Constant *
C = dyn_cast<Constant>(V)) {
1606 if (
C->isNullValue())
1609 const APInt *ConstIntOrConstSplatInt;
1611 return ConstIntOrConstSplatInt->
isPowerOf2();
1628 Value *
X =
nullptr, *
Y =
nullptr;
1635 if (
const ZExtInst *ZI = dyn_cast<ZExtInst>(V))
1676 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
1719 GTI != GTE; ++GTI) {
1721 if (
StructType *STy = GTI.getStructTypeOrNull()) {
1722 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
1726 if (ElementOffset > 0)
1732 if (Q.DL.getTypeAllocSize(GTI.getIndexedType()) == 0)
1737 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
1764 for (
unsigned i = 0; i < NumRanges; ++i) {
1766 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 0));
1768 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 1));
1770 if (Range.contains(Value))
1783 if (
auto *
C = dyn_cast<Constant>(V)) {
1784 if (
C->isNullValue())
1786 if (isa<ConstantInt>(
C))
1792 if (
auto *VecTy = dyn_cast<VectorType>(
C->getType())) {
1793 for (
unsigned i = 0, e = VecTy->getNumElements(); i != e; ++i) {
1794 Constant *Elt =
C->getAggregateElement(i);
1797 if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
1806 if (
auto *I = dyn_cast<Instruction>(V)) {
1810 if (
auto *Ty = dyn_cast<IntegerType>(V->
getType())) {
1811 const APInt ZeroValue(Ty->getBitWidth(), 0);
1834 Value *
X =
nullptr, *
Y =
nullptr;
1839 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
1840 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), Depth, Q);
1871 auto ShiftVal = Shift->getLimitedValue(BitWidth - 1);
1927 else if (
const SelectInst *
SI = dyn_cast<SelectInst>(V)) {
1933 else if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
1936 if (PN->getNumIncomingValues() == 2) {
1937 Value *Start = PN->getIncomingValue(0);
1938 Value *Induction = PN->getIncomingValue(1);
1939 if (isa<ConstantInt>(Induction) && !isa<ConstantInt>(Start))
1942 if (!
C->isZero() && !
C->isNegative()) {
1952 bool AllNonZeroConstants =
all_of(PN->operands(), [](Value *V) {
1953 return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZero();
1955 if (AllNonZeroConstants)
1961 return Known.
One != 0;
1969 Value *
Op =
nullptr;
2025 if (!CV || !CV->getType()->isVectorTy())
2028 unsigned MinSignBits = TyBits;
2029 unsigned NumElts = CV->getType()->getVectorNumElements();
2030 for (
unsigned i = 0; i != NumElts; ++i) {
2032 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(i));
2037 APInt EltVal = Elt->getValue();
2052 assert(Result > 0 &&
"At least one sign bit needs to be present!");
2071 unsigned FirstAnswer = 1;
2082 case Instruction::SExt:
2086 case Instruction::SDiv: {
2087 const APInt *Denominator;
2104 case Instruction::SRem: {
2105 const APInt *Denominator;
2133 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
2134 return std::max(NumrBits, ResBits);
2139 case Instruction::AShr: {
2145 if (ShAmtLimited >= TyBits)
2147 Tmp += ShAmtLimited;
2148 if (Tmp > TyBits) Tmp = TyBits;
2152 case Instruction::Shl: {
2158 if (Tmp2 >= TyBits ||
2164 case Instruction::And:
2165 case Instruction::Or:
2166 case Instruction::Xor:
2180 if (Tmp == 1)
return 1;
2188 if (Tmp == 1)
return 1;
2191 if (
const auto *CRHS = dyn_cast<Constant>(U->
getOperand(1)))
2192 if (CRHS->isAllOnesValue()) {
2198 if ((Known.
Zero | 1).isAllOnesValue())
2208 if (Tmp2 == 1)
return 1;
2211 case Instruction::Sub:
2213 if (Tmp2 == 1)
return 1;
2216 if (
const auto *CLHS = dyn_cast<Constant>(U->
getOperand(0)))
2217 if (CLHS->isNullValue()) {
2222 if ((Known.
Zero | 1).isAllOnesValue())
2236 if (Tmp == 1)
return 1;
2239 case Instruction::PHI: {
2240 const PHINode *PN = cast<PHINode>(U);
2243 if (NumIncomingValues > 4)
break;
2245 if (NumIncomingValues == 0)
break;
2250 for (
unsigned i = 1, e = NumIncomingValues; i != e; ++i) {
2251 if (Tmp == 1)
return Tmp;
2258 case Instruction::Trunc:
2263 case Instruction::ExtractElement:
2292 bool LookThroughSExt,
unsigned Depth) {
2295 assert(V &&
"No Value?");
2296 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2313 if (CO && CO == BaseVal) {
2324 if (Depth == MaxDepth)
return false;
2327 if (!I)
return false;
2331 case Instruction::SExt:
2332 if (!LookThroughSExt)
return false;
2335 case Instruction::ZExt:
2337 LookThroughSExt, Depth+1);
2338 case Instruction::Shl:
2339 case Instruction::Mul: {
2343 if (I->
getOpcode() == Instruction::Shl) {
2345 if (!Op1CI)
return false;
2354 Value *Mul0 =
nullptr;
2356 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
2357 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
2358 if (Op1C->getType()->getPrimitiveSizeInBits() <
2359 MulC->getType()->getPrimitiveSizeInBits())
2361 if (Op1C->getType()->getPrimitiveSizeInBits() >
2362 MulC->getType()->getPrimitiveSizeInBits())
2370 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
2371 if (Mul0CI->getValue() == 1) {
2378 Value *Mul1 =
nullptr;
2380 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
2381 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
2382 if (Op0C->getType()->getPrimitiveSizeInBits() <
2383 MulC->getType()->getPrimitiveSizeInBits())
2385 if (Op0C->getType()->getPrimitiveSizeInBits() >
2386 MulC->getType()->getPrimitiveSizeInBits())
2394 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
2395 if (Mul1CI->getValue() == 1) {
2438 return Intrinsic::sin;
2442 return Intrinsic::cos;
2446 return Intrinsic::exp;
2450 return Intrinsic::exp2;
2454 return Intrinsic::log;
2456 case LibFunc_log10f:
2457 case LibFunc_log10l:
2458 return Intrinsic::log10;
2462 return Intrinsic::log2;
2466 return Intrinsic::fabs;
2475 case LibFunc_copysign:
2476 case LibFunc_copysignf:
2477 case LibFunc_copysignl:
2478 return Intrinsic::copysign;
2480 case LibFunc_floorf:
2481 case LibFunc_floorl:
2482 return Intrinsic::floor;
2486 return Intrinsic::ceil;
2488 case LibFunc_truncf:
2489 case LibFunc_truncl:
2490 return Intrinsic::trunc;
2494 return Intrinsic::rint;
2495 case LibFunc_nearbyint:
2496 case LibFunc_nearbyintf:
2497 case LibFunc_nearbyintl:
2498 return Intrinsic::nearbyint;
2500 case LibFunc_roundf:
2501 case LibFunc_roundl:
2506 return Intrinsic::pow;
2510 if (ICS->hasNoNaNs())
2511 return Intrinsic::sqrt;
2526 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V))
2527 return !CFP->getValueAPF().isNegZero();
2533 if (!I)
return false;
2537 if (FPO->hasNoSignedZeros())
2541 if (I->
getOpcode() == Instruction::FAdd)
2543 if (CFP->isNullValue())
2547 if (isa<SIToFPInst>(I) || isa<UIToFPInst>(
I))
2550 if (
const CallInst *CI = dyn_cast<CallInst>(I)) {
2556 case Intrinsic::sqrt:
2559 case Intrinsic::fabs:
2579 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2580 return !CFP->getValueAPF().isNegative() ||
2581 (!SignBitOnly && CFP->getValueAPF().isZero());
2595 case Instruction::UIToFP:
2597 case Instruction::FMul:
2600 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()))
2604 case Instruction::FAdd:
2605 case Instruction::FDiv:
2606 case Instruction::FRem:
2616 case Instruction::FPExt:
2617 case Instruction::FPTrunc:
2622 const auto *CI = cast<CallInst>(
I);
2637 case Intrinsic::exp:
2638 case Intrinsic::exp2:
2639 case Intrinsic::fabs:
2642 case Intrinsic::sqrt:
2646 return CI->hasNoNaNs() && (CI->hasNoSignedZeros() ||
2649 case Intrinsic::powi:
2671 case Intrinsic::fma:
2672 case Intrinsic::fmuladd:
2675 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()) &&
2703 if (
Constant *
C = dyn_cast<Constant>(V))
2704 if (
C->isNullValue())
2709 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2710 if (CFP->getType()->isFloatTy())
2712 if (CFP->getType()->isDoubleTy())
2719 if (CI->getBitWidth() % 8 == 0) {
2720 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
2722 if (!CI->getValue().isSplat(8))
2731 Value *Elt = CA->getElementAsConstant(0);
2736 for (
unsigned I = 1,
E = CA->getNumElements(); I !=
E; ++
I)
2737 if (CA->getElementAsConstant(I) != Elt)
2777 while (PrevTo != OrigTo) {
2803 "tmp", InsertBefore);
2820 assert(InsertBefore &&
"Must have someplace to insert!");
2825 unsigned IdxSkip = Idxs.
size();
2840 if (idx_range.
empty())
2844 "Not looking at a struct or array?");
2846 "Invalid indices for type?");
2848 if (
Constant *
C = dyn_cast<Constant>(V)) {
2849 C =
C->getAggregateElement(idx_range[0]);
2850 if (!
C)
return nullptr;
2857 const unsigned *req_idx = idx_range.
begin();
2858 for (
const unsigned *i = I->idx_begin(), *e = I->idx_end();
2859 i != e; ++i, ++req_idx) {
2860 if (req_idx == idx_range.
end()) {
2900 unsigned size = I->getNumIndices() + idx_range.
size();
2905 Idxs.
append(I->idx_begin(), I->idx_end());
2911 &&
"Number of indices added not correct?");
2925 APInt ByteOffset(BitWidth, 0);
2931 while (Visited.
insert(Ptr).second) {
2943 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
2948 Ptr =
GEP->getPointerOperand();
2951 Ptr = cast<Operator>(
Ptr)->getOperand(0);
2952 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
2953 if (GA->isInterposable())
2955 Ptr = GA->getAliasee();
2965 unsigned CharSize) {
2979 if (!FirstIdx || !FirstIdx->
isZero())
2987 unsigned ElementSize, uint64_t
Offset) {
3004 uint64_t StartIdx = 0;
3005 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
GEP->getOperand(2)))
3006 StartIdx = CI->getZExtValue();
3024 if ( (ArrayTy = dyn_cast<ArrayType>(GVTy)) ) {
3030 uint64_t Length = SizeInBytes / (ElementSize / 8);
3031 if (Length <= Offset)
3034 Slice.
Array =
nullptr;
3050 if (Offset > NumElts)
3053 Slice.
Array = Array;
3063 uint64_t
Offset,
bool TrimAtNul) {
3068 if (Slice.
Array ==
nullptr) {
3104 unsigned CharSize) {
3110 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
3111 if (!PHIs.
insert(PN).second)
3115 uint64_t LenSoFar = ~0ULL;
3116 for (Value *IncValue : PN->incoming_values()) {
3118 if (Len == 0)
return 0;
3120 if (Len == ~0ULL)
continue;
3122 if (Len != LenSoFar && LenSoFar != ~0ULL)
3134 if (Len1 == 0)
return 0;
3136 if (Len2 == 0)
return 0;
3137 if (Len1 == ~0ULL)
return Len2;
3138 if (Len2 == ~0ULL)
return Len1;
3139 if (Len1 != Len2)
return 0;
3148 if (Slice.
Array ==
nullptr)
3152 unsigned NullIndex = 0;
3153 for (
unsigned E = Slice.
Length; NullIndex <
E; ++NullIndex) {
3158 return NullIndex + 1;
3170 return Len == ~0ULL ? 1 : Len;
3184 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3186 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3194 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
3201 unsigned MaxLookup) {
3204 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
3206 V =
GEP->getPointerOperand();
3209 V = cast<Operator>(V)->getOperand(0);
3210 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
3211 if (GA->isInterposable())
3213 V = GA->getAliasee();
3214 }
else if (isa<AllocaInst>(V)) {
3219 if (Value *RV = CS.getReturnedArgOperand()) {
3241 unsigned MaxLookup) {
3249 if (!Visited.
insert(P).second)
3258 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
3271 for (Value *IncValue : PN->incoming_values())
3277 }
while (!Worklist.
empty());
3284 if (
const Operator *U = dyn_cast<Operator>(V)) {
3287 if (U->getOpcode() == Instruction::PtrToInt)
3288 return U->getOperand(0);
3296 (!isa<ConstantInt>(U->getOperand(1)) &&
3298 !isa<PHINode>(U->getOperand(1))))
3300 V = U->getOperand(0);
3321 for (Value *V : Objs) {
3322 if (!Visited.
insert(V).second)
3338 Objects.
push_back(const_cast<Value *>(V));
3340 }
while (!Working.
empty());
3347 if (!II)
return false;
3371 case Instruction::UDiv:
3372 case Instruction::URem: {
3379 case Instruction::SDiv:
3380 case Instruction::SRem: {
3382 const APInt *Numerator, *Denominator;
3386 if (*Denominator == 0)
3389 if (*Denominator != -1)
3399 const LoadInst *LI = cast<LoadInst>(Inst);
3411 auto *CI = cast<const CallInst>(Inst);
3412 const Function *Callee = CI->getCalledFunction();
3418 case Instruction::VAArg:
3419 case Instruction::Alloca:
3420 case Instruction::Invoke:
3421 case Instruction::PHI:
3424 case Instruction::Br:
3425 case Instruction::IndirectBr:
3427 case Instruction::Unreachable:
3428 case Instruction::Fence:
3429 case Instruction::AtomicRMW:
3430 case Instruction::AtomicCmpXchg:
3431 case Instruction::LandingPad:
3432 case Instruction::Resume:
3433 case Instruction::CatchSwitch:
3434 case Instruction::CatchPad:
3435 case Instruction::CatchRet:
3436 case Instruction::CleanupPad:
3437 case Instruction::CleanupRet:
3451 if (isa<AllocaInst>(V))
return true;
3454 if (
const Argument *
A = dyn_cast<Argument>(V))
3455 return A->hasByValOrInAllocaAttr() ||
A->hasNonNullAttr();
3460 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
3461 return !GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
3462 GV->getType()->getAddressSpace() == 0;
3465 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
3469 if (CS.isReturnNonNull())
3479 assert(!isa<ConstantData>(V) &&
"Did not expect ConstantPointerNull");
3480 assert(CtxI &&
"Context instruction required for analysis");
3481 assert(DT &&
"Dominator tree required for analysis");
3483 unsigned NumUsesExplored = 0;
3484 for (
auto *U : V->
users()) {
3493 if (
auto *CalledFunc = CS.getCalledFunction())
3494 for (
const Argument &Arg : CalledFunc->args())
3495 if (CS.getArgOperand(Arg.getArgNo()) == V &&
3496 Arg.hasNonNullAttr() && DT->
dominates(CS.getInstruction(), CtxI))
3501 if (!
match(const_cast<User *>(U),
3506 for (
auto *CmpU : U->users()) {
3507 if (
const BranchInst *BI = dyn_cast<BranchInst>(CmpU)) {
3508 assert(BI->isConditional() &&
"uses a comparison!");
3516 match(CmpU, m_Intrinsic<Intrinsic::experimental_guard>()) &&
3517 DT->
dominates(cast<Instruction>(CmpU), CtxI)) {
3528 if (isa<ConstantPointerNull>(V) || isa<UndefValue>(V))
3563 if (ZeroBits >= BitWidth)
3573 (void)LHSMax.
umul_ov(RHSMax, MaxOverflow);
3634 APInt Result = std::move(MaxLHS) + std::move(MaxRHS);
3648 APInt Result = std::move(MinLHS) + std::move(MinRHS);
3701 bool LHSOrRHSKnownNonNegative =
3703 bool LHSOrRHSKnownNegative =
3705 if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) {
3707 if ((AddKnown.
isNonNegative() && LHSOrRHSKnownNonNegative) ||
3708 (AddKnown.
isNegative() && LHSOrRHSKnownNegative)) {
3720 assert((IID == Intrinsic::sadd_with_overflow ||
3721 IID == Intrinsic::uadd_with_overflow ||
3722 IID == Intrinsic::ssub_with_overflow ||
3723 IID == Intrinsic::usub_with_overflow ||
3724 IID == Intrinsic::smul_with_overflow ||
3725 IID == Intrinsic::umul_with_overflow) &&
3726 "Not an overflow intrinsic!");
3733 if (
const auto *EVI = dyn_cast<ExtractValueInst>(U)) {
3734 assert(EVI->getNumIndices() == 1 &&
"Obvious from CI's type");
3736 if (EVI->getIndices()[0] == 0)
3739 assert(EVI->getIndices()[0] == 1 &&
"Obvious from CI's type");
3741 for (
const auto *U : EVI->users())
3742 if (
const auto *
B = dyn_cast<BranchInst>(U)) {
3743 assert(
B->isConditional() &&
"How else is it using an i1?");
3754 auto AllUsesGuardedByBranch = [&](
const BranchInst *BI) {
3756 if (!NoWrapEdge.isSingleEdge())
3760 for (
const auto *Result : Results) {
3763 if (DT.
dominates(NoWrapEdge, Result->getParent()))
3766 for (
auto &RU : Result->uses())
3774 return any_of(GuardingBranches, AllUsesGuardedByBranch);
3784 Add, DL, AC, CxtI, DT);
3803 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
3804 return !LI->isVolatile();
3806 return !
SI->isVolatile();
3808 return !CXI->isVolatile();
3810 return !RMWI->isVolatile();
3811 if (
const MemIntrinsic *MII = dyn_cast<MemIntrinsic>(I))
3812 return !MII->isVolatile();
3815 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(I))
3816 return !CRI->unwindsToCaller();
3817 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I))
3818 return !CatchSwitch->unwindsToCaller();
3819 if (isa<ResumeInst>(I))
3821 if (isa<ReturnInst>(I))
3823 if (isa<UnreachableInst>(I))
3829 if (!CS.doesNotThrow())
3848 return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory() ||
3849 match(I, m_Intrinsic<Intrinsic::assume>());
3865 if (&LI == I)
return true;
3868 llvm_unreachable(
"Instruction not contained in its own parent basic block.");
3874 case Instruction::Sub:
3875 case Instruction::Xor:
3876 case Instruction::Trunc:
3877 case Instruction::BitCast:
3878 case Instruction::AddrSpaceCast:
3879 case Instruction::Mul:
3880 case Instruction::Shl:
3881 case Instruction::GetElementPtr:
3887 case Instruction::AShr:
3888 case Instruction::SExt:
3893 case Instruction::ICmp:
3911 case Instruction::AtomicCmpXchg:
3914 case Instruction::AtomicRMW:
3917 case Instruction::UDiv:
3918 case Instruction::SDiv:
3919 case Instruction::URem:
3920 case Instruction::SRem:
3942 YieldsPoison.
insert(PoisonI);
3950 if (&I != PoisonI) {
3952 if (NotPoison !=
nullptr && YieldsPoison.
count(NotPoison))
3959 if (YieldsPoison.
count(&I)) {
3969 if (Visited.
insert(NextBB).second) {
3986 if (
auto *
C = dyn_cast<ConstantFP>(V))
3992 if (
auto *
C = dyn_cast<ConstantFP>(V))
3993 return !
C->isZero();
3999 Value *CmpLHS, Value *CmpRHS,
4000 Value *TrueVal, Value *FalseVal,
4001 Value *&LHS, Value *&RHS) {
4055 if ((CmpLHS == TrueVal &&
match(FalseVal,
m_APInt(C2))) ||
4089 Value *CmpLHS, Value *CmpRHS,
4090 Value *TrueVal, Value *FalseVal,
4091 Value *&LHS, Value *&RHS) {
4111 bool Ordered =
false;
4122 if (LHSSafe && RHSSafe) {
4152 if (TrueVal == CmpRHS && FalseVal == CmpLHS) {
4163 if (TrueVal == CmpLHS && FalseVal == CmpRHS) {
4204 return matchMinMax(Pred, CmpLHS, CmpRHS, TrueVal, FalseVal, LHS, RHS);
4214 Type *SrcTy = Cast1->getSrcTy();
4215 if (
auto *Cast2 = dyn_cast<CastInst>(V2)) {
4217 if (*CastOp == Cast2->getOpcode() && SrcTy == Cast2->getSrcTy())
4218 return Cast2->getOperand(0);
4228 case Instruction::ZExt:
4232 case Instruction::SExt:
4236 case Instruction::Trunc:
4239 case Instruction::FPTrunc:
4242 case Instruction::FPExt:
4245 case Instruction::FPToUI:
4248 case Instruction::FPToSI:
4251 case Instruction::UIToFP:
4254 case Instruction::SIToFP:
4267 if (CastedBack !=
C)
4287 if (isa<FPMathOperator>(CmpI))
4298 cast<CastInst>(TrueVal)->getOperand(0),
C,
4302 C, cast<CastInst>(FalseVal)->getOperand(0),
4311 const Value *LHS,
const Value *RHS,
4340 auto MatchNUWAddsToSameValue = [&](
const Value *
A,
const Value *
B,
4353 if (CA->isSubsetOf(Known.
Zero) && CB->isSubsetOf(Known.
Zero))
4361 const APInt *CLHS, *CRHS;
4362 if (MatchNUWAddsToSameValue(LHS, RHS, X, CLHS, CRHS))
4363 return CLHS->
ule(*CRHS);
4374 const Value *ARHS,
const Value *BLHS,
4403 const Value *BLHS,
const Value *BRHS,
4404 bool &IsSwappedOps) {
4406 bool IsMatchingOps = (ALHS == BLHS && ARHS == BRHS);
4407 IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
4408 return IsMatchingOps || IsSwappedOps;
4420 bool IsSwappedOps) {
4442 assert(ALHS == BLHS &&
"LHS operands must match.");
4449 if (Intersection.isEmptySet())
4500 ALHS, RHS, DL, LHSIsFalse, Depth + 1, AC, CxtI, DT))
4503 ARHS, RHS, DL, LHSIsFalse, Depth + 1, AC, CxtI, DT))
4510 assert(isa<ICmpInst>(LHS) && isa<ICmpInst>(RHS) &&
"Expected icmps.");
4521 APred, ALHS, ARHS, BPred, BLHS, BRHS, IsSwappedOps))
4530 if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
4532 APred, ALHS, cast<ConstantInt>(ARHS), BPred, BLHS,
4533 cast<ConstantInt>(BRHS)))
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
const Value * getGuaranteedNonFullPoisonOp(const Instruction *I)
Return either nullptr or an operand of I such that I will trigger undefined behavior if I is executed...
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool isAddOfNonZero(const Value *V1, const Value *V2, const Query &Q)
Return true if V2 == V1 + X, where X is known non-zero.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
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")))
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
Type * getSourceElementType() const
void push_back(const T &Elt)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
A parsed version of the target data layout string in and methods for querying it. ...
Type * getIndexedType() const
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to have exactly one bit set when defined. ...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
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 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...
static unsigned ComputeNumSignBits(const Value *V, unsigned Depth, const Query &Q)
bool isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
Value * getAggregateOperand()
uint64_t getZExtValue() const
Get zero extended value.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
static bool MaskedValueIsZero(const Value *V, const APInt &Mask, unsigned Depth, const Query &Q)
Return true if 'V & Mask' is known to be zero.
Value * isBytewiseValue(Value *V)
If the specified value can be set by repeating the same byte in memory, return the i8 value that it i...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
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.
static bool isKnownNonEqual(const Value *V1, const Value *V2, const Query &Q)
Return true if it is known that V1 != V2.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
APInt reverseBits() const
an instruction that atomically checks whether a specified value is in a memory location, and, if it is, stores a new value there.
match_zero m_Zero()
Match an arbitrary zero/null constant.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Constant * getSplatValue() const
If this is a splat vector constant, meaning that all of the elements have the same value...
bool isLoopHeader(const BlockT *BB) const
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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 getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property...
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
unsigned countMaxLeadingZeros() const
Returns the maximum number of leading zero bits possible.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
Type * getValueType() const
This class represents a function call, abstracting a target machine's calling convention.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
static uint64_t round(uint64_t Acc, uint64_t Input)
gep_type_iterator gep_type_end(const User *GEP)
An efficient, type-erasing, non-owning reference to a callable.
bool isSigned() const
Determine if this instruction is using a signed comparison.
A cache of .assume calls within a function.
0 1 0 0 True if ordered and less than
Function Alias Analysis Results
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
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 isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
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...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const Function * getParent() const
Return the enclosing method, or null if none.
void setAllBits()
Set every bit to 1.
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr)
Return true if it is valid to use the assumptions provided by an assume intrinsic, I, at the point in the control-flow identified by the context instruction, CxtI.
An instruction for reading from memory.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
static IntegerType * getInt64Ty(LLVMContext &C)
an instruction that atomically reads a memory location, combines it with another value, and then stores the result back.
void GetUnderlyingObjects(Value *V, SmallVectorImpl< Value * > &Objects, const DataLayout &DL, LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to GetUnderlyingObject except that it can look through phi and select instruct...
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
void setBitsFrom(unsigned loBit)
Set the top bits starting from loBit.
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
bool isGEPBasedOnPointerToString(const GEPOperator *GEP, unsigned CharSize=8)
Returns true if the GEP is based on a pointer to a string (array of.
void reserve(size_type N)
uint64_t Offset
Slice starts at this Offset.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
void setAllZero()
Make all bits known to be zero and discard any previous information.
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)
BlockT * getHeader() const
bool isEquality() const
This is just a convenience that dispatches to the subclasses.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const AddOperator *Add, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool propagatesFullPoison(const Instruction *I)
Return true if this function can prove that I is guaranteed to yield full-poison (all bits poison) if...
uint64_t getArrayNumElements() const
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.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
bool isNegative() const
Determine sign of this APInt.
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)
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...
StructType * getStructTypeOrNull() const
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
bool isNonNegative() const
Returns true if this value is known to be non-negative.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static Value * getPointerOperand(Instruction &Inst)
void setBit(unsigned BitPosition)
Set a given bit to 1.
This class represents the LLVM 'select' instruction.
bool noSignedZeros() const
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
void setHighBits(unsigned hiBits)
Set the top hiBits bits.
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Exact_match< T > m_Exact(const T &SubPattern)
static bool isAssumeLikeIntrinsic(const Instruction *I)
Class to represent struct types.
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...
A Use represents the edge between a Value definition and its users.
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...
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
NaN behavior not applicable.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
not_match< LHS > m_Not(const LHS &L)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
LLVM_NODISCARD bool empty() const
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
bool getBoolValue() const
Convert APInt to a boolean value.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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)
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
A constant value that is initialized with an expression using other constant values.
const ConstantDataArray * Array
ConstantDataArray pointer.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
Class to represent array types.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(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)
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.
KnownBits zextOrTrunc(unsigned BitWidth)
Zero extends or truncates the underlying known Zero and One bits.
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
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'...
bool haveNoCommonBitsSet(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if LHS and RHS have no common bits set.
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
bool isArrayTy() const
True if this is an instance of ArrayType.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
unsigned getBitWidth() const
Get the bit width of this value.
static Optional< bool > isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS, const DataLayout &DL, unsigned Depth, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred ALHS ARHS" is true.
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'...
static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known, unsigned Depth, const Query &Q)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Type * getElementType() const
size_t size() const
size - Get the array size.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
bool mayReadOrWriteMemory() const
Return true if this instruction may read or write memory.
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.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
static bool isKnownNonNaN(const Value *V, FastMathFlags FMF)
uint64_t getElementOffset(unsigned Idx) const
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 ContantDataArray.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
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)
bool isAllOnes() const
Returns true if value is all one bits.
static bool isSameUnderlyingObjectInLoop(const PHINode *PN, const LoopInfo *LI)
PN defines a loop-variant pointer to an object.
OverflowResult computeOverflowForSignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
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 intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
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.
bool isNegative() const
Returns true if this value is known to be negative.
LLVM Basic Block Representation.
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value, otherwise return null.
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)
Conditional or Unconditional Branch instruction.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the give value is known to be non-negative.
Type * getElementType(unsigned N) const
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
This is an important base class in LLVM.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
void resetAll()
Resets the known state of all bits.
const Value * getCondition() const
int64_t getSExtValue() const
Get sign extended value.
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
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 MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if 'V & Mask' is known to be zero.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool isZeroValue() const
Return true if the value is negative zero or null value.
bool isOverflowIntrinsicNoWrap(const IntrinsicInst *II, const DominatorTree &DT)
Returns true if the arithmetic part of the II 's result is used only along the paths control dependen...
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
static SelectPatternResult matchMinMax(CmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS)
Match non-obvious integer minimum and maximum sequences.
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.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
KnownBits trunc(unsigned BitWidth)
Truncate the underlying known Zero and One bits.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static const unsigned End
static bool isKnownNonNullFromDominatingCondition(const Value *V, const Instruction *CtxI, const DominatorTree *DT)
Value * getPointerOperand()
Value * getOperand(unsigned i) const
Value * getPointerOperand()
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. ...
Predicate getPredicate() const
Return the predicate for this instruction.
Represents offset+length into a ConstantDataArray.
bool empty() const
empty - Check if the array is empty.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
void clearSignBit()
Set the sign bit to 0.
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
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 isEmptySet() const
Return true if this set contains no members.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
static Value * BuildSubAggregate(Value *From, Value *To, Type *IndexedType, SmallVectorImpl< unsigned > &Idxs, unsigned IdxSkip, Instruction *InsertBefore)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
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...
static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS, const Value *RHS, const DataLayout &DL, unsigned Depth, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
Return true if "icmp Pred LHS RHS" is always true.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
Value * FindInsertedValue(Value *V, ArrayRef< unsigned > idx_range, Instruction *InsertBefore=nullptr)
Given an aggregrate and an sequence of indices, see if the scalar value indexed is already around as ...
static unsigned computeNumSignBitsVectorConstant(const Value *V, unsigned TyBits)
For vector constants, loop over the elements and find the constant with the minimum number of sign bi...
neg_match< LHS > m_Neg(const LHS &L)
Match an integer negate.
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
void makeNonNegative()
Make this value negative.
unsigned countMinLeadingOnes() const
Returns the minimum number of leading one bits.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Given one NaN input, returns the non-NaN.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
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.
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
BinaryOps getOpcode() const
const MDOperand & getOperand(unsigned I) const
This is the common base class for memset/memcpy/memmove.
Iterator for intrusive lists based on ilist_node.
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...
This is the shared class of boolean and integer constants.
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
SelectPatternFlavor Flavor
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return the number of times the sign bit of the register is replicated into the other bits...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
unsigned logBase2() const
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...
Utility class for floating point operations which can have information about relaxed accuracy require...
This is a utility class that provides an abstraction for the common functionality between Instruction...
uint64_t Length
Length of the slice.
Type * getType() const
All values are typed, get the type of this value.
SelectPatternFlavor
Specific patterns of select instructions we can match.
Provides information about what library functions are available for the current target.
static Optional< bool > isImpliedCondMatchingImmOperands(CmpInst::Predicate APred, const Value *ALHS, const ConstantInt *C1, CmpInst::Predicate BPred, const Value *BLHS, const ConstantInt *C2)
Return true if "icmp1 APred ALHS C1" implies "icmp2 BPred BLHS C2" is true.
This class represents a range of values.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
static bool checkRippleForSignedAdd(const KnownBits &LHSKnown, const KnownBits &RHSKnown)
Return true if we can prove that adding the two values of the knownbits will not overflow.
bool isTrueWhenEqual() const
This is just a convenience.
LLVM_NODISCARD T pop_back_val()
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, KnownBits &Known)
Compute known bits from the range metadata.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
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...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
unsigned ceilLogBase2() const
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.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
unsigned countMaxPopulation() const
Returns the maximum number of bits that could be one.
static cl::opt< unsigned > DomConditionsMaxUses("dom-conditions-max-uses", cl::Hidden, cl::init(20))
Class for arbitrary precision integers.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
bool isIntegerTy() const
True if this is an instance of IntegerType.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
iterator_range< user_iterator > users()
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)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isFPPredicate() const
static void computeKnownBitsFromOperator(const Operator *I, KnownBits &Known, unsigned Depth, const Query &Q)
llvm_unreachable("Unknown RegBank!")
bool isStructTy() const
True if this is an instance of StructType.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
static Value * lookThroughCast(CmpInst *CmpI, Value *V1, Value *V2, Instruction::CastOps *CastOp)
bool isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the given value is known be negative (i.e.
bool isAllOnesValue() const
Determine if all bits are set.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isKnownNonNull(const Value *V)
Return true if this pointer couldn't possibly be null by its definition.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
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)
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
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.
match_one m_One()
Match an integer 1 or a vector with all elements equal to 1.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
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.
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value's sign bit is 0.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
bool ComputeMultiple(Value *V, unsigned Base, Value *&Multiple, bool LookThroughSExt=false, unsigned Depth=0)
This function computes the integer multiple of Base that equals V.
static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
unsigned countMinSignBits() const
Returns the number of times the sign bit is replicated into the other bits.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
bool isKnownNonNullAt(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if this pointer couldn't possibly be null.
bool isZero() const
Returns true if value is all zero.
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 ...
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
1 0 1 0 True if unordered or greater than
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given values are known to be non-equal when defined.
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool hasLocalLinkage() const
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 isSpeculatable() const
Determine if the call has sideeffects.
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Given one NaN input, returns the NaN.
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...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
match_sign_mask m_SignMask()
Match an integer or vector with only the sign bit(s) set.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static const Instruction * safeCxtI(const Value *V, const Instruction *CxtI)
#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.
unsigned countMinTrailingOnes() const
Returns the minimum number of trailing one bits.
static bool isKnownNonZero(const Value *V, unsigned Depth, const Query &Q)
Return true if the given value is known to be non-zero when defined.
KnownBits sext(unsigned BitWidth)
Sign extends the underlying known Zero and One bits.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the given value is known be positive (i.e.
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to be non-zero when defined.
Optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsFalse=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if RHS is known to be implied true by LHS.
const Value * getFalseValue() const
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
bool CannotBeOrderedLessThanZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value is either NaN or never less than -0...
bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
APInt abs() const
Get the absolute value;.
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
unsigned getNumElements() const
Random access to the elements.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
op_range incoming_values()
0 0 1 1 True if ordered and greater than or equal
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSignBitClear() const
Determine if sign bit of this APInt is clear.
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static IntegerType * getInt8Ty(LLVMContext &C)
const BasicBlock * getParent() const
void setLowBits(unsigned loBits)
Set the bottom loBits bits.
static cl::opt< bool > DontImproveNonNegativePhiBits("dont-improve-non-negative-phi-bits", cl::Hidden, cl::init(true))
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
static Optional< bool > isImpliedCondMatchingOperands(CmpInst::Predicate APred, const Value *ALHS, const Value *ARHS, CmpInst::Predicate BPred, const Value *BLHS, const Value *BRHS, bool IsSwappedOps)
Return true if "icmp1 APred ALHS ARHS" implies "icmp2 BPred BLHS BRHS" is true.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
void 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 noNaNs() const
Flag queries.
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.
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)
bool slt(const APInt &RHS) const
Signed less than comparison.
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...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.