40 using namespace llvm::PatternMatch;
104 : AC(AC), CxtI(CxtI), DT(DT) {}
106 Query(
const Query &Q,
const Value *NewExcl)
107 : ExclInvs(Q.ExclInvs), AC(Q.AC), CxtI(Q.CxtI), DT(Q.DT) {
108 ExclInvs.insert(NewExcl);
145 "LHS and RHS should have the same type");
147 "LHS and RHS should be integers");
149 APInt LHSKnownZero(IT->getBitWidth(), 0), LHSKnownOne(IT->getBitWidth(), 0);
150 APInt RHSKnownZero(IT->getBitWidth(), 0), RHSKnownOne(IT->getBitWidth(), 0);
153 return (LHSKnownZero | RHSKnownZero).isAllOnesValue();
176 Query(AC,
safeCxtI(V, CxtI), DT), DL);
189 unsigned Depth,
const Query &Q);
199 unsigned Depth,
const Query &Q);
214 if (
ConstantInt *CLHS = dyn_cast<ConstantInt>(Op0)) {
218 if (!CLHS->getValue().isNegative()) {
228 if ((KnownZero2 & MaskV) == MaskV) {
229 unsigned NLZ2 = CLHS->getValue().countLeadingZeros();
241 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
246 APInt CarryIn(BitWidth, 0);
253 APInt PossibleSumZero = ~LHSKnownZero + ~KnownZero2 + CarryIn;
254 APInt PossibleSumOne = LHSKnownOne + KnownOne2 + CarryIn;
257 APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnownZero ^ KnownZero2);
258 APInt CarryKnownOne = PossibleSumOne ^ LHSKnownOne ^ KnownOne2;
261 APInt LHSKnown = LHSKnownZero | LHSKnownOne;
262 APInt RHSKnown = KnownZero2 | KnownOne2;
263 APInt CarryKnown = CarryKnownZero | CarryKnownOne;
264 APInt Known = LHSKnown & RHSKnown & CarryKnown;
266 assert((PossibleSumZero & Known) == (PossibleSumOne & Known) &&
267 "known bits of sum differ");
270 KnownZero = ~PossibleSumOne & Known;
271 KnownOne = PossibleSumOne & Known;
274 if (!Known.isNegative()) {
278 if (LHSKnownZero.isNegative() && KnownZero2.
isNegative())
282 else if (LHSKnownOne.
isNegative() && KnownOne2.isNegative())
297 bool isKnownNegative =
false;
298 bool isKnownNonNegative =
false;
303 isKnownNonNegative =
true;
305 bool isKnownNonNegativeOp1 = KnownZero.
isNegative();
306 bool isKnownNonNegativeOp0 = KnownZero2.
isNegative();
307 bool isKnownNegativeOp1 = KnownOne.
isNegative();
308 bool isKnownNegativeOp0 = KnownOne2.
isNegative();
310 isKnownNonNegative = (isKnownNegativeOp1 && isKnownNegativeOp0) ||
311 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
314 if (!isKnownNonNegative)
315 isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
317 (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
331 BitWidth) - BitWidth;
333 TrailZ =
std::min(TrailZ, BitWidth);
343 if (isKnownNonNegative && !KnownOne.
isNegative())
344 KnownZero.
setBit(BitWidth - 1);
345 else if (isKnownNegative && !KnownZero.
isNegative())
346 KnownOne.
setBit(BitWidth - 1);
353 assert(NumRanges >= 1);
356 unsigned MinLeadingZeros = BitWidth;
357 for (
unsigned i = 0; i < NumRanges; ++i) {
359 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 0));
361 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 * i + 1));
363 if (Range.isWrappedSet())
366 MinLeadingZeros =
std::min(LeadingZeros, MinLeadingZeros);
377 while (!WorkSet.
empty()) {
379 if (!Visited.
insert(V).second)
383 bool FoundNEUse =
false;
385 if (!EphValues.
count(I)) {
395 if (
const User *U = dyn_cast<User>(V))
409 if (
const CallInst *CI = dyn_cast<CallInst>(I))
410 if (
Function *
F = CI->getCalledFunction())
411 switch (
F->getIntrinsicID()) {
414 case Intrinsic::assume:
415 case Intrinsic::dbg_declare:
416 case Intrinsic::dbg_value:
417 case Intrinsic::invariant_start:
418 case Intrinsic::invariant_end:
419 case Intrinsic::lifetime_start:
420 case Intrinsic::lifetime_end:
421 case Intrinsic::objectsize:
422 case Intrinsic::ptr_annotation:
423 case Intrinsic::var_annotation:
442 if (Q.DT->dominates(Inv, Q.CxtI)) {
444 }
else if (Inv->
getParent() == Q.CxtI->getParent()) {
460 if (Inv->
getParent() == Q.CxtI->getParent()->getSinglePredecessor()) {
462 }
else if (Inv->
getParent() == Q.CxtI->getParent()) {
487 Query(
nullptr, CxtI, DT));
490 template<
typename LHS,
typename RHS>
497 template<
typename LHS,
typename RHS>
504 template<
typename LHS,
typename RHS>
511 template<
typename LHS,
typename RHS>
525 unsigned Depth,
const Query &Q) {
531 if (LHS != V && RHS != V)
545 APInt KnownZeroTemp(BitWidth, 0), KnownOneTemp(BitWidth, 0);
547 if (KnownOneTemp.
isAllOnesValue() || KnownZeroTemp.isNegative()) {
555 APInt KnownZeroTemp(BitWidth, 0), KnownOneTemp(BitWidth, 0);
562 KnownZero |= KnownZeroTemp;
563 KnownOne |= KnownOneTemp;
568 APInt KnownZeroTemp(BitWidth, 0), KnownOneTemp(BitWidth, 0);
571 unsigned SignBits = KnownZeroTemp.countLeadingOnes();
577 APInt KnownZeroTemp(BitWidth, 0), KnownOneTemp(BitWidth, 0);
581 unsigned SignBits = KnownZeroTemp.countLeadingOnes();
601 if (!Q.DT || !Q.CxtI)
606 if (
auto VI = dyn_cast<Instruction>(V))
624 unsigned NumBlocksExplored = 0;
632 if (!Q.DT->getNode(Current)->getIDom())
634 Current = Q.DT->getNode(Current)->getIDom()->getBlock();
653 if (!Edge.isSingleEdge() || !Q.DT->dominates(Edge, Q.CxtI->getParent()))
661 unsigned NumUsesExplored = 0;
662 for (
auto U : V->
users()) {
675 for (
auto *CmpU : Cmp->
users()) {
687 if (!Edge.isSingleEdge() || !Q.DT->dominates(Edge, Q.CxtI->getParent()))
698 unsigned Depth,
const Query &Q) {
701 if (!Q.AC || !Q.CxtI)
706 for (
auto &AssumeVH : Q.AC->assumptions()) {
711 "Got assumption for the wrong function!");
712 if (Q.ExclInvs.count(I))
720 "must be an assume intrinsic");
725 assert(BitWidth == 1 &&
"assume operand is not i1?");
745 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
747 KnownZero |= RHSKnownZero;
748 KnownOne |= RHSKnownOne;
750 }
else if (
match(Arg,
753 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
755 APInt MaskKnownZero(BitWidth, 0), MaskKnownOne(BitWidth, 0);
760 KnownZero |= RHSKnownZero & MaskKnownOne;
761 KnownOne |= RHSKnownOne & MaskKnownOne;
766 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
768 APInt MaskKnownZero(BitWidth, 0), MaskKnownOne(BitWidth, 0);
773 KnownZero |= RHSKnownOne & MaskKnownOne;
774 KnownOne |= RHSKnownZero & MaskKnownOne;
776 }
else if (
match(Arg,
779 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
781 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
786 KnownZero |= RHSKnownZero & BKnownZero;
787 KnownOne |= RHSKnownOne & BKnownZero;
792 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
794 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
799 KnownZero |= RHSKnownOne & BKnownZero;
800 KnownOne |= RHSKnownZero & BKnownZero;
802 }
else if (
match(Arg,
805 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
807 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
813 KnownZero |= RHSKnownZero & BKnownZero;
814 KnownOne |= RHSKnownOne & BKnownZero;
815 KnownZero |= RHSKnownOne & BKnownOne;
816 KnownOne |= RHSKnownZero & BKnownOne;
821 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
823 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
829 KnownZero |= RHSKnownOne & BKnownZero;
830 KnownOne |= RHSKnownZero & BKnownZero;
831 KnownZero |= RHSKnownZero & BKnownOne;
832 KnownOne |= RHSKnownOne & BKnownOne;
837 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
847 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
854 }
else if (
match(Arg,
859 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
871 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
880 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
883 if (RHSKnownZero.isNegative()) {
890 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
900 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
910 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
913 if (RHSKnownZero.isAllOnesValue() || RHSKnownOne.
isNegative()) {
920 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
929 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
946 unsigned Depth,
const Query &Q) {
949 APInt KnownZero2(KnownZero), KnownOne2(KnownOne);
962 KnownOne &= KnownOne2;
964 KnownZero |= KnownZero2;
972 KnownZero &= KnownZero2;
974 KnownOne |= KnownOne2;
982 APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2);
984 KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2);
985 KnownZero = KnownZeroOut;
988 case Instruction::Mul: {
989 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
991 KnownOne, KnownZero2, KnownOne2, DL, Depth, Q);
994 case Instruction::UDiv: {
999 unsigned LeadZ = KnownZero2.countLeadingOnes();
1001 KnownOne2.clearAllBits();
1002 KnownZero2.clearAllBits();
1004 unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
1005 if (RHSUnknownLeadingOnes != BitWidth)
1007 LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
1017 KnownOne &= KnownOne2;
1018 KnownZero &= KnownZero2;
1020 case Instruction::FPTrunc:
1021 case Instruction::FPExt:
1022 case Instruction::FPToUI:
1023 case Instruction::FPToSI:
1024 case Instruction::SIToFP:
1025 case Instruction::UIToFP:
1027 case Instruction::PtrToInt:
1028 case Instruction::IntToPtr:
1029 case Instruction::AddrSpaceCast:
1031 case Instruction::ZExt:
1032 case Instruction::Trunc: {
1035 unsigned SrcBitWidth;
1040 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1047 if (BitWidth > SrcBitWidth)
1051 case Instruction::BitCast: {
1062 case Instruction::SExt: {
1066 KnownZero = KnownZero.
trunc(SrcBitWidth);
1067 KnownOne = KnownOne.
trunc(SrcBitWidth);
1069 KnownZero = KnownZero.
zext(BitWidth);
1070 KnownOne = KnownOne.
zext(BitWidth);
1074 if (KnownZero[SrcBitWidth-1])
1076 else if (KnownOne[SrcBitWidth-1])
1080 case Instruction::Shl:
1083 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth);
1085 KnownZero <<= ShiftAmt;
1086 KnownOne <<= ShiftAmt;
1090 case Instruction::LShr:
1094 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth);
1104 case Instruction::AShr:
1108 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth-1);
1116 if (KnownZero[BitWidth-ShiftAmt-1])
1117 KnownZero |= HighBits;
1118 else if (KnownOne[BitWidth-ShiftAmt-1])
1119 KnownOne |= HighBits;
1122 case Instruction::Sub: {
1123 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1125 KnownZero, KnownOne, KnownZero2, KnownOne2, DL,
1129 case Instruction::Add: {
1130 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1132 KnownZero, KnownOne, KnownZero2, KnownOne2, DL,
1136 case Instruction::SRem:
1140 APInt LowBits = RA - 1;
1145 KnownZero = KnownZero2 & LowBits;
1146 KnownOne = KnownOne2 & LowBits;
1150 if (KnownZero2[BitWidth-1] || ((KnownZero2 & LowBits) == LowBits))
1151 KnownZero |= ~LowBits;
1155 if (KnownOne2[BitWidth-1] && ((KnownOne2 & LowBits) != 0))
1156 KnownOne |= ~LowBits;
1158 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
1165 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
1169 if (LHSKnownZero.isNegative())
1170 KnownZero.
setBit(BitWidth - 1);
1174 case Instruction::URem: {
1176 APInt RA = Rem->getValue();
1178 APInt LowBits = (RA - 1);
1181 KnownZero |= ~LowBits;
1182 KnownOne &= LowBits;
1193 KnownZero2.countLeadingOnes());
1194 KnownOne.clearAllBits();
1199 case Instruction::Alloca: {
1209 case Instruction::GetElementPtr: {
1212 APInt LocalKnownZero(BitWidth, 0), LocalKnownOne(BitWidth, 0);
1215 unsigned TrailZ = LocalKnownZero.countTrailingOnes();
1218 for (
unsigned i = 1, e = I->
getNumOperands(); i != e; ++i, ++GTI) {
1220 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
1224 Constant *CIndex = cast<Constant>(Index);
1231 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
1234 TrailZ = std::min<unsigned>(TrailZ,
1244 uint64_t TypeSize = DL.getTypeAllocSize(IndexedTy);
1245 LocalKnownZero = LocalKnownOne =
APInt(GEPOpiBits, 0);
1250 LocalKnownZero.countTrailingOnes()));
1263 for (
unsigned i = 0; i != 2; ++i) {
1273 if (Opcode == Instruction::Add ||
1274 Opcode == Instruction::Sub ||
1277 Opcode == Instruction::Mul) {
1292 APInt KnownZero3(KnownZero), KnownOne3(KnownOne);
1296 std::min(KnownZero2.countTrailingOnes(),
1297 KnownZero3.countTrailingOnes()));
1309 if (Depth <
MaxDepth - 1 && !KnownZero && !KnownOne) {
1318 if (IncValue == P)
continue;
1320 KnownZero2 =
APInt(BitWidth, 0);
1321 KnownOne2 =
APInt(BitWidth, 0);
1326 KnownZero &= KnownZero2;
1327 KnownOne &= KnownOne2;
1330 if (!KnownZero && !KnownOne)
1337 case Instruction::Invoke:
1344 switch (II->getIntrinsicID()) {
1346 case Intrinsic::ctlz:
1347 case Intrinsic::cttz: {
1348 unsigned LowBits =
Log2_32(BitWidth)+1;
1355 case Intrinsic::ctpop: {
1356 unsigned LowBits =
Log2_32(BitWidth)+1;
1360 case Intrinsic::x86_sse42_crc32_64_64:
1366 case Instruction::ExtractValue:
1371 switch (II->getIntrinsicID()) {
1373 case Intrinsic::uadd_with_overflow:
1374 case Intrinsic::sadd_with_overflow:
1376 II->getArgOperand(1),
false, KnownZero,
1377 KnownOne, KnownZero2, KnownOne2, DL, Depth, Q);
1379 case Intrinsic::usub_with_overflow:
1380 case Intrinsic::ssub_with_overflow:
1382 II->getArgOperand(1),
false, KnownZero,
1383 KnownOne, KnownZero2, KnownOne2, DL, Depth, Q);
1385 case Intrinsic::umul_with_overflow:
1386 case Intrinsic::smul_with_overflow:
1388 KnownZero, KnownOne, KnownZero2, KnownOne2, DL,
1413 const DataLayout &DL,
unsigned Depth,
const Query &Q) {
1414 assert(V &&
"No Value?");
1415 assert(Depth <=
MaxDepth &&
"Limit Search Depth");
1420 "Not integer or pointer type!");
1426 "V, KnownOne and KnownZero should have same BitWidth");
1430 KnownOne = CI->getValue();
1431 KnownZero = ~KnownOne;
1435 if (isa<ConstantPointerNull>(V) ||
1436 isa<ConstantAggregateZero>(V)) {
1449 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
1450 Elt = CDS->getElementAsInteger(i);
1458 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1459 unsigned Align = GO->getAlignment();
1461 if (
auto *GVar = dyn_cast<GlobalVariable>(GO)) {
1462 Type *ObjectType = GVar->getType()->getElementType();
1467 if (GVar->isStrongDefinitionForLinker())
1483 if (
Argument *
A = dyn_cast<Argument>(V)) {
1484 unsigned Align =
A->getType()->isPointerTy() ?
A->getParamAlignment() : 0;
1486 if (!Align &&
A->hasStructRetAttr()) {
1488 Type *EltTy = cast<PointerType>(
A->getType())->getElementType();
1521 if (!GA->mayBeOverridden())
1526 if (
Operator *
I = dyn_cast<Operator>(V))
1541 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
1547 const DataLayout &DL,
unsigned Depth,
const Query &Q) {
1554 APInt ZeroBits(BitWidth, 0);
1555 APInt OneBits(BitWidth, 0);
1557 KnownOne = OneBits[BitWidth - 1];
1558 KnownZero = ZeroBits[BitWidth - 1];
1567 if (
Constant *C = dyn_cast<Constant>(V)) {
1568 if (C->isNullValue())
1571 return CI->getValue().isPowerOf2();
1589 Value *
X =
nullptr, *
Y =
nullptr;
1595 if (
ZExtInst *ZI = dyn_cast<ZExtInst>(V))
1628 APInt LHSZeroBits(BitWidth, 0), LHSOneBits(BitWidth, 0);
1631 APInt RHSZeroBits(BitWidth, 0), RHSOneBits(BitWidth, 0);
1636 if ((~(LHSZeroBits & RHSZeroBits)).isPowerOf2())
1663 unsigned Depth,
const Query &Q) {
1679 GTI != GTE; ++GTI) {
1681 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
1682 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
1686 if (ElementOffset > 0)
1697 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
1724 assert(NumRanges >= 1);
1725 for (
unsigned i = 0; i < NumRanges; ++i) {
1727 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 0));
1729 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 * i + 1));
1731 if (Range.contains(Value))
1743 if (
Constant *C = dyn_cast<Constant>(V)) {
1744 if (C->isNullValue())
1746 if (isa<ConstantInt>(C))
1758 const APInt ZeroValue(Ty->getBitWidth(), 0);
1781 Value *
X =
nullptr, *
Y =
nullptr;
1786 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
1787 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), DL, Depth, Q);
1797 APInt KnownZero(BitWidth, 0);
1798 APInt KnownOne(BitWidth, 0);
1811 bool XKnownNonNegative, XKnownNegative;
1812 ComputeSignBit(X, XKnownNonNegative, XKnownNegative, DL, Depth, Q);
1822 bool XKnownNonNegative, XKnownNegative;
1823 bool YKnownNonNegative, YKnownNegative;
1824 ComputeSignBit(X, XKnownNonNegative, XKnownNegative, DL, Depth, Q);
1829 if (XKnownNonNegative && YKnownNonNegative)
1835 if (BitWidth && XKnownNegative && YKnownNegative) {
1836 APInt KnownZero(BitWidth, 0);
1837 APInt KnownOne(BitWidth, 0);
1842 if ((KnownOne & Mask) != 0)
1847 if ((KnownOne & Mask) != 0)
1852 if (XKnownNonNegative &&
1855 if (YKnownNonNegative &&
1875 if (!BitWidth)
return false;
1876 APInt KnownZero(BitWidth, 0);
1877 APInt KnownOne(BitWidth, 0);
1879 return KnownOne != 0;
1892 unsigned Depth,
const Query &Q) {
1895 return (KnownZero & Mask) == Mask;
1912 unsigned FirstAnswer = 1;
1923 case Instruction::SExt:
1927 case Instruction::SDiv: {
1928 const APInt *Denominator;
1945 case Instruction::SRem: {
1946 const APInt *Denominator;
1974 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
1975 return std::max(NumrBits, ResBits);
1980 case Instruction::AShr: {
1985 Tmp += ShAmt->getZExtValue();
1986 if (Tmp > TyBits) Tmp = TyBits;
1990 case Instruction::Shl: {
1996 if (Tmp2 >= TyBits ||
2018 if (Tmp == 1)
return 1;
2022 case Instruction::Add:
2026 if (Tmp == 1)
return 1;
2029 if (
const auto *CRHS = dyn_cast<Constant>(U->
getOperand(1)))
2030 if (CRHS->isAllOnesValue()) {
2031 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
2037 if ((KnownZero |
APInt(TyBits, 1)).isAllOnesValue())
2042 if (KnownZero.isNegative())
2047 if (Tmp2 == 1)
return 1;
2050 case Instruction::Sub:
2052 if (Tmp2 == 1)
return 1;
2055 if (
const auto *CLHS = dyn_cast<Constant>(U->
getOperand(0)))
2056 if (CLHS->isNullValue()) {
2057 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
2062 if ((KnownZero |
APInt(TyBits, 1)).isAllOnesValue())
2067 if (KnownZero.isNegative())
2076 if (Tmp == 1)
return 1;
2080 PHINode *PN = cast<PHINode>(U);
2083 if (NumIncomingValues > 4)
break;
2085 if (NumIncomingValues == 0)
break;
2090 for (
unsigned i = 1, e = NumIncomingValues; i != e; ++i) {
2091 if (Tmp == 1)
return Tmp;
2098 case Instruction::Trunc:
2106 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
2110 if (KnownZero.isNegative()) {
2133 bool LookThroughSExt,
unsigned Depth) {
2136 assert(V &&
"No Value?");
2137 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2154 if (CO && CO == BaseVal) {
2165 if (Depth == MaxDepth)
return false;
2168 if (!I)
return false;
2172 case Instruction::SExt:
2173 if (!LookThroughSExt)
return false;
2175 case Instruction::ZExt:
2177 LookThroughSExt, Depth+1);
2178 case Instruction::Shl:
2179 case Instruction::Mul: {
2183 if (I->
getOpcode() == Instruction::Shl) {
2185 if (!Op1CI)
return false;
2194 Value *Mul0 =
nullptr;
2196 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
2197 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
2198 if (Op1C->getType()->getPrimitiveSizeInBits() <
2199 MulC->getType()->getPrimitiveSizeInBits())
2201 if (Op1C->getType()->getPrimitiveSizeInBits() >
2202 MulC->getType()->getPrimitiveSizeInBits())
2210 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
2211 if (Mul0CI->getValue() == 1) {
2218 Value *Mul1 =
nullptr;
2220 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
2221 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
2222 if (Op0C->getType()->getPrimitiveSizeInBits() <
2223 MulC->getType()->getPrimitiveSizeInBits())
2225 if (Op0C->getType()->getPrimitiveSizeInBits() >
2226 MulC->getType()->getPrimitiveSizeInBits())
2234 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
2235 if (Mul1CI->getValue() == 1) {
2255 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V))
2256 return !CFP->getValueAPF().isNegZero();
2265 if (!I)
return false;
2269 if (
FPO->hasNoSignedZeros())
2273 if (I->
getOpcode() == Instruction::FAdd)
2275 if (CFP->isNullValue())
2279 if (isa<SIToFPInst>(I) || isa<UIToFPInst>(
I))
2284 if (II->getIntrinsicID() == Intrinsic::sqrt)
2287 if (
const CallInst *CI = dyn_cast<CallInst>(I))
2288 if (
const Function *
F = CI->getCalledFunction()) {
2289 if (
F->isDeclaration()) {
2291 if (
F->getName() ==
"abs")
return true;
2293 if (
F->getName() ==
"fabs")
return true;
2294 if (
F->getName() ==
"fabsf")
return true;
2295 if (
F->getName() ==
"fabsl")
return true;
2296 if (
F->getName() ==
"sqrt" ||
F->getName() ==
"sqrtf" ||
2297 F->getName() ==
"sqrtl")
2306 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V))
2307 return !CFP->getValueAPF().isNegative() || CFP->getValueAPF().isZero();
2316 if (!I)
return false;
2320 case Instruction::FMul:
2325 case Instruction::FAdd:
2326 case Instruction::FDiv:
2327 case Instruction::FRem:
2330 case Instruction::FPExt:
2331 case Instruction::FPTrunc:
2336 switch (II->getIntrinsicID()) {
2338 case Intrinsic::exp:
2339 case Intrinsic::exp2:
2340 case Intrinsic::fabs:
2341 case Intrinsic::sqrt:
2343 case Intrinsic::powi:
2346 if (CI->getBitWidth() <= 64 && CI->getSExtValue() % 2u == 0)
2350 case Intrinsic::fma:
2351 case Intrinsic::fmuladd:
2371 if (
Constant *C = dyn_cast<Constant>(V))
2372 if (C->isNullValue())
2377 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2378 if (CFP->getType()->isFloatTy())
2380 if (CFP->getType()->isDoubleTy())
2387 if (CI->getBitWidth() % 8 == 0) {
2388 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
2390 if (!CI->getValue().isSplat(8))
2399 Value *Elt = CA->getElementAsConstant(0);
2404 for (
unsigned I = 1, E = CA->getNumElements();
I != E; ++
I)
2405 if (CA->getElementAsConstant(
I) != Elt)
2445 while (PrevTo != OrigTo) {
2471 "tmp", InsertBefore);
2488 assert(InsertBefore &&
"Must have someplace to insert!");
2493 unsigned IdxSkip = Idxs.
size();
2508 if (idx_range.
empty())
2512 "Not looking at a struct or array?");
2514 "Invalid indices for type?");
2516 if (
Constant *C = dyn_cast<Constant>(V)) {
2517 C = C->getAggregateElement(idx_range[0]);
2518 if (!C)
return nullptr;
2525 const unsigned *req_idx = idx_range.
begin();
2526 for (
const unsigned *i =
I->idx_begin(), *e =
I->idx_end();
2527 i != e; ++i, ++req_idx) {
2528 if (req_idx == idx_range.
end()) {
2568 unsigned size =
I->getNumIndices() + idx_range.
size();
2573 Idxs.
append(
I->idx_begin(),
I->idx_end());
2578 assert(Idxs.
size() == size
2579 &&
"Number of indices added not correct?");
2593 APInt ByteOffset(BitWidth, 0);
2599 APInt GEPOffset(BitWidth, 0);
2600 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
2603 ByteOffset += GEPOffset;
2605 Ptr =
GEP->getPointerOperand();
2608 Ptr = cast<Operator>(Ptr)->getOperand(0);
2609 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
2610 if (GA->mayBeOverridden())
2612 Ptr = GA->getAliasee();
2626 uint64_t Offset,
bool TrimAtNul) {
2636 if (
GEP->getNumOperands() != 3)
2640 PointerType *PT = cast<PointerType>(
GEP->getOperand(0)->getType());
2642 if (!AT || !AT->getElementType()->isIntegerTy(8))
2648 if (!FirstIdx || !FirstIdx->
isZero())
2654 uint64_t StartIdx = 0;
2655 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
GEP->getOperand(2)))
2690 if (Offset > NumElts)
2694 Str = Str.
substr(Offset);
2717 if (
PHINode *PN = dyn_cast<PHINode>(V)) {
2718 if (!PHIs.
insert(PN).second)
2722 uint64_t LenSoFar = ~0ULL;
2723 for (
Value *IncValue : PN->incoming_values()) {
2725 if (Len == 0)
return 0;
2727 if (Len == ~0ULL)
continue;
2729 if (Len != LenSoFar && LenSoFar != ~0ULL)
2741 if (Len1 == 0)
return 0;
2743 if (Len2 == 0)
return 0;
2744 if (Len1 == ~0ULL)
return Len2;
2745 if (Len2 == ~0ULL)
return Len1;
2746 if (Len1 != Len2)
return 0;
2755 return StrData.
size()+1;
2767 return Len == ~0ULL ? 1 : Len;
2780 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
2782 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
2790 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
2797 unsigned MaxLookup) {
2800 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
2802 V =
GEP->getPointerOperand();
2805 V = cast<Operator>(V)->getOperand(0);
2806 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
2807 if (GA->mayBeOverridden())
2809 V = GA->getAliasee();
2828 unsigned MaxLookup) {
2836 if (!Visited.
insert(P).second)
2845 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
2858 for (
Value *IncValue : PN->incoming_values())
2864 }
while (!Worklist.
empty());
2871 if (!II)
return false;
2885 assert(Offset.
isNonNegative() &&
"offset can't be negative");
2886 assert(Ty->
isSized() &&
"must be sized");
2889 bool CheckForNonNull =
false;
2890 if (
const Argument *
A = dyn_cast<Argument>(BV)) {
2891 DerefBytes =
A->getDereferenceableBytes();
2892 if (!DerefBytes.getBoolValue()) {
2893 DerefBytes =
A->getDereferenceableOrNullBytes();
2894 CheckForNonNull =
true;
2897 DerefBytes =
CS.getDereferenceableBytes(0);
2898 if (!DerefBytes.getBoolValue()) {
2899 DerefBytes =
CS.getDereferenceableOrNullBytes(0);
2900 CheckForNonNull =
true;
2902 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(BV)) {
2904 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
2907 if (!DerefBytes.getBoolValue()) {
2910 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
2913 CheckForNonNull =
true;
2917 if (DerefBytes.getBoolValue())
2951 if (isa<AllocaInst>(V))
return true;
2963 if (STy->
isSized() && DTy->isSized() &&
2972 return !GV->hasExternalWeakLinkage();
2975 if (
const Argument *
A = dyn_cast<Argument>(V))
2976 if (
A->hasByValAttr())
2986 const Value *Base =
GEP->getPointerOperand();
2989 if (!Visited.
insert(Base).second)
2996 if (!
GEP->accumulateConstantOffset(DL, Offset))
3007 if (
I->getIntrinsicID() == Intrinsic::experimental_gc_relocate) {
3035 if (Offset.isNonNegative())
3061 case Instruction::UDiv:
3062 case Instruction::URem: {
3069 case Instruction::SDiv:
3070 case Instruction::SRem: {
3072 const APInt *Numerator, *Denominator;
3076 if (*Denominator == 0)
3079 if (*Denominator != -1)
3089 const LoadInst *LI = cast<LoadInst>(Inst);
3098 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
3099 switch (II->getIntrinsicID()) {
3104 case Intrinsic::dbg_declare:
3105 case Intrinsic::dbg_value:
3108 case Intrinsic::bswap:
3109 case Intrinsic::ctlz:
3110 case Intrinsic::ctpop:
3111 case Intrinsic::cttz:
3112 case Intrinsic::objectsize:
3113 case Intrinsic::sadd_with_overflow:
3114 case Intrinsic::smul_with_overflow:
3115 case Intrinsic::ssub_with_overflow:
3116 case Intrinsic::uadd_with_overflow:
3117 case Intrinsic::umul_with_overflow:
3118 case Intrinsic::usub_with_overflow:
3122 case Intrinsic::sqrt:
3123 case Intrinsic::fma:
3124 case Intrinsic::fmuladd:
3125 case Intrinsic::fabs:
3139 case Instruction::VAArg:
3140 case Instruction::Alloca:
3141 case Instruction::Invoke:
3145 case Instruction::Br:
3146 case Instruction::IndirectBr:
3147 case Instruction::Switch:
3148 case Instruction::Unreachable:
3149 case Instruction::Fence:
3150 case Instruction::LandingPad:
3151 case Instruction::AtomicRMW:
3152 case Instruction::AtomicCmpXchg:
3153 case Instruction::Resume:
3161 if (isa<AllocaInst>(V))
return true;
3164 if (
const Argument *
A = dyn_cast<Argument>(V))
3165 return A->hasByValOrInAllocaAttr() ||
A->hasNonNullAttr();
3168 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
3169 return !GV->hasExternalWeakLinkage();
3172 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
3176 if (
CS.isReturnNonNull())
3189 unsigned NumUsesExplored = 0;
3190 for (
auto U : V->
users()) {
3203 for (
auto *CmpU : Cmp->
users()) {
3213 if (
match(const_cast<ICmpInst*>(Cmp),
3221 if (NonNullSuccessor) {
3252 APInt LHSKnownZero(BitWidth, 0);
3253 APInt LHSKnownOne(BitWidth, 0);
3254 APInt RHSKnownZero(BitWidth, 0);
3255 APInt RHSKnownOne(BitWidth, 0);
3266 if (ZeroBits >= BitWidth)
3270 APInt LHSMax = ~LHSKnownZero;
3271 APInt RHSMax = ~RHSKnownZero;
3276 LHSMax.
umul_ov(RHSMax, MaxOverflow);
3283 LHSKnownOne.
umul_ov(RHSKnownOne, MinOverflow);
3295 bool LHSKnownNonNegative, LHSKnownNegative;
3296 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, DL, 0,
3298 if (LHSKnownNonNegative || LHSKnownNegative) {
3299 bool RHSKnownNonNegative, RHSKnownNegative;
3300 ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, DL, 0,
3303 if (LHSKnownNegative && RHSKnownNegative) {
3309 if (LHSKnownNonNegative && RHSKnownNonNegative) {
3327 if (TrueVal == CmpLHS && FalseVal == CmpRHS) {
3342 if (TrueVal == CmpRHS && FalseVal == CmpLHS) {
3356 if (
ConstantInt *C1 = dyn_cast<ConstantInt>(CmpRHS)) {
3374 if (
const auto *C2 = dyn_cast<ConstantInt>(FalseVal)) {
3375 if (C1->getType() == C2->getType() && ~C1->getValue() == C2->getValue() &&
3398 if (isa<SExtInst>(CI) && CmpI->
isSigned()) {
3409 if (isa<TruncInst>(CI))
3438 cast<CastInst>(TrueVal)->getOperand(0), C,
3442 C, cast<CastInst>(FalseVal)->getOperand(0),
void clearAllBits()
Set every bit to 0.
static bool isDereferenceablePointer(const Value *V, const DataLayout &DL, const Instruction *CtxI, const DominatorTree *DT, const TargetLibraryInfo *TLI, SmallPtrSetImpl< const Value * > &Visited)
Return true if Value is always a dereferenceable pointer.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
static unsigned ComputeNumSignBits(Value *V, const DataLayout &DL, unsigned Depth, const Query &Q)
Return the number of times the sign bit of the register is replicated into the other bits...
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
Type * getIndexedType() const
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static bool rangeMetadataExcludesValue(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...
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
cst_pred_ty< is_sign_bit > m_SignBit()
Match an integer or vector with only the sign bit(s) set.
uint64_t GetStringLength(Value *V)
GetStringLength - If we can compute the length of the string pointed to by the specified pointer...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const
Get the absolute value;.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
LLVM Argument representation.
Value * getAggregateOperand()
uint64_t getZExtValue() const
Get zero extended value.
size_t size() const
size - Get the string size.
Value * isBytewiseValue(Value *V)
isBytewiseValue - If the specified value can be set by repeating the same byte in memory...
Intrinsic::ID getIntrinsicID() const
getIntrinsicID - Return the intrinsic ID of this intrinsic.
match_zero m_Zero()
Match an arbitrary zero/null constant.
Constant * getSplatValue() const
getSplatValue - If this is a splat vector constant, meaning that all of the elements have the same va...
bool isLoopHeader(const BlockT *BB) const
void setBit(unsigned bitPosition)
Set a given bit to 1.
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.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
static bool isDereferenceableFromAttribute(const Value *BV, APInt Offset, Type *Ty, const DataLayout &DL, const Instruction *CtxI, const DominatorTree *DT, const TargetLibraryInfo *TLI)
CallInst - This class represents a function call, abstracting a target machine's calling convention...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Xor >, BinaryOp_match< RHS, LHS, Instruction::Xor > > m_c_Xor(const LHS &L, const RHS &R)
void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static bool isKnownToBeAPowerOfTwo(Value *V, bool OrZero, unsigned Depth, const Query &Q, const DataLayout &DL)
Return true if the given value is known to have exactly one bit set when defined. ...
gep_type_iterator gep_type_end(const User *GEP)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
bool isSigned() const
Determine if this instruction is using a signed comparison.
A cache of .assume calls within a function.
bool haveNoCommonBitsSet(Value *LHS, Value *RHS, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if LHS and RHS have no common bits set.
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
SmallPtrSet< const Value *, 8 > ExclInvsSet
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
static bool isEquality(Predicate P)
isEquality - Return true if this predicate is either EQ or NE.
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.
LoadInst - an instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
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
getLoopFor - Return the inner most loop that BB lives in.
void reserve(size_type N)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
static bool isGEPKnownNonNull(GEPOperator *GEP, const DataLayout &DL, unsigned Depth, const Query &Q)
Test whether a GEP's result is known to be non-null.
bool isExact() const
Test whether this division is known to be exact, with zero remainder.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT 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...
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, APInt &KnownZero)
Compute known bits from the range metadata.
static void computeKnownBitsFromTrueCondition(Value *V, ICmpInst *Cmp, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth, const Query &Q)
Compute known bits in 'V' under the assumption that the condition 'Cmp' is true (at the context instr...
Type * getPointerElementType() const
static Constant * getNullValue(Type *Ty)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
ArrayType * getType() const
getType - Specialize the getType() method to always return an ArrayType, which reduces the amount of ...
SelectPatternFlavor 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...
bool isNegative() const
Determine sign of this APInt.
bool match(Val *V, const Pattern &P)
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
bool isUnconditional() const
This class represents a conversion between pointers from one address space to another.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
SelectInst - This class represents the LLVM 'select' instruction.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
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"), clEnumValEnd))
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)
static bool isValidAssumeForContext(Value *V, const Query &Q)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
StructType - Class to represent struct types.
bool isOperatorNewLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory and never returns nu...
BinOp2_match< LHS, RHS, Instruction::LShr, Instruction::AShr > m_Shr(const LHS &L, const RHS &R)
Matches LShr or AShr.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
bool isDereferenceablePointer(const Value *V, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
isDereferenceablePointer - Return true if this is always a dereferenceable pointer.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static cl::opt< unsigned > DomConditionsMaxUses("dom-conditions-max-uses", cl::Hidden, cl::init(2000))
bool isLoopInvariant(const Value *V) const
isLoopInvariant - Return true if the specified value is loop invariant
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Accumulate offsets from stripInBoundsConstantOffsets().
not_match< LHS > m_Not(const LHS &L)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
bool getBoolValue() const
Convert APInt to a boolean value.
APInt lshr(const APInt &LHS, unsigned shiftAmt)
Logical right-shift function.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ConstantExpr - a constant value that is initialized with an expression using other constant values...
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
GetPointerBaseWithConstantOffset - Analyze the specified pointer to see if it can be expressed as a b...
ArrayType - Class to represent array types.
bool isKnownToBeAPowerOfTwo(Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
isKnownToBeAPowerOfTwo - Return true if the given value is known to have exactly one bit set when def...
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
BasicBlock * getSuccessor(unsigned i) const
static bool isSameUnderlyingObjectInLoop(PHINode *PN, LoopInfo *LI)
PN defines a loop-variant pointer to an object.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Or >, BinaryOp_match< RHS, LHS, Instruction::Or > > m_c_Or(const LHS &L, const RHS &R)
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
bool isArrayTy() const
isArrayTy - True if this is an instance of ArrayType.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
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.
PointerType - Class to represent pointers.
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
uint64_t getElementOffset(unsigned Idx) const
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
OverflowResult computeOverflowForUnsignedAdd(Value *LHS, Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
static void computeKnownBitsMul(Value *Op0, Value *Op1, bool NSW, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, const DataLayout &DL, unsigned Depth, const Query &Q)
initializer< Ty > init(const Ty &Val)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
ConstantDataArray - An array constant whose element type is a simple 1/2/4/8-byte integer or float/do...
LLVM Basic Block Representation.
Value * hasConstantValue() const
hasConstantValue - If the specified PHI node always merges together the same value, return the value, otherwise return null.
static bool isEphemeralValueOf(Instruction *I, const Value *E)
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)
uint64_t getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
BranchInst - Conditional or Unconditional Branch instruction.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::And >, BinaryOp_match< RHS, LHS, Instruction::And > > m_c_And(const LHS &L, const RHS &R)
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
static cl::opt< bool > EnableDomConditions("value-tracking-dom-conditions", cl::Hidden, cl::init(false))
Enable an experimental feature to leverage information about dominating conditions to compute known b...
Type * getElementType(unsigned N) const
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
This is an important base class in LLVM.
PointerType * getType() const
getType - Overload to return most specific pointer type
const Value * getCondition() const
int64_t getSExtValue() const
Get sign extended value.
StringRef getAsString() const
getAsString - If this array is isString(), then this method returns the array as a StringRef...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool onlyUsedByLifetimeMarkers(const Value *V)
onlyUsedByLifetimeMarkers - Return true if the only users of this pointer are lifetime markers...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
unsigned getAlignment() const
getAlignment - 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.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static cl::opt< bool > DomConditionsSingleCmpUse("dom-conditions-single-cmp-use", cl::Hidden, cl::init(false))
bool isZeroValue() const
Return true if the value is negative zero or null value.
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...
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
OverflowResult computeOverflowForUnsignedMul(Value *LHS, Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
static uint64_t GetStringLengthH(Value *V, SmallPtrSetImpl< PHINode * > &PHIs)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
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.
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 bool isKnownNonNullFromDominatingCondition(const Value *V, const Instruction *CtxI, const DominatorTree *DT)
Value * getPointerOperand()
Value * getOperand(unsigned i) const
Value * getPointerOperand()
Class to represent integer types.
Type * getSrcTy() const
Return the source type, as a convenience.
Wraps a call to a gc.relocate and provides access to it's operands.
Predicate getPredicate() const
Return the predicate for this instruction.
bool empty() const
empty - Check if the array is empty.
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeSignBit - Determine whether the sign bit is known to be zero or one.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - 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)
const Value * getTrueValue() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
GetUnderlyingObject - This method strips off any GEP address adjustments and pointer casts from the s...
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
match_combine_or< CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate >, CmpClass_match< RHS, LHS, ICmpInst, ICmpInst::Predicate > > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Value * FindInsertedValue(Value *V, ArrayRef< unsigned > idx_range, Instruction *InsertBefore=nullptr)
FindInsertedValue - Given an aggregrate and an sequence of indices, see if the scalar value indexed i...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
neg_match< LHS > m_Neg(const LHS &L)
Match an integer negate.
bool isConditional() const
static cl::opt< unsigned > DomConditionsMaxDepth("dom-conditions-max-depth", cl::Hidden, cl::init(1))
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
const MDOperand & getOperand(unsigned I) const
static void computeKnownBitsFromDominatingCondition(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth, const Query &Q)
Compute known bits in 'V' from conditions which are known to be true along all paths leading to the c...
This is the shared class of boolean and integer constants.
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
unsigned logBase2() const
static void computeKnownBitsAddSub(bool Add, Value *Op0, Value *Op1, bool NSW, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, const DataLayout &DL, unsigned Depth, const Query &Q)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static bool isKnownNonZero(Value *V, const DataLayout &DL, unsigned Depth, const Query &Q)
Return true if the given value is known to be non-zero when defined.
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...
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 Constant * lookThroughCast(ICmpInst *CmpI, Value *V1, Value *V2, Instruction::CastOps *CastOp)
This class represents a range of values.
unsigned ComputeNumSignBits(Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeNumSignBits - Return the number of times the sign bit of the register is replicated into the o...
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isKnownNonNullAt(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
isKnownNonNullAt - Return true if this pointer couldn't possibly be null.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
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
getCalledFunction - 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.
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
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...
unsigned ceilLogBase2() const
unsigned Log2_32(uint32_t Value)
Log2_32 - This function returns 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.
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
isIntegerTy - 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 void computeKnownBitsFromOperator(Operator *I, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth, const Query &Q)
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI=nullptr)
isKnownNonNull - Return true if this pointer couldn't possibly be null by its definition.
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
bool isStructTy() const
isStructTy - True if this is an instance of StructType.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
bool isKnownNonZero(Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
isKnownNonZero - Return true if the given value is known to be non-zero when defined.
bool isAllOnesValue() const
Determine if all bits are set.
unsigned countLeadingOnes() const
Count the number of leading one bits.
bool CannotBeOrderedLessThanZero(const Value *V, unsigned Depth=0)
CannotBeOrderedLessThanZero - Return true if we can prove that the specified FP value is either a NaN...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Value * getCondition() const
bool isMinSignedValue() const
Determine if this is the smallest signed value.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
static IntegerType * getInt32Ty(LLVMContext &C)
static cl::opt< unsigned > DomConditionsMaxDomBlocks("dom-conditions-dom-blocks", cl::Hidden, cl::init(20000))
How many dominating blocks should be scanned looking for dominating conditions?
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
unsigned greater or equal
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ImmutableCallSite - establish a view to a call site for examination.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool hasOneUse() const
Return true if there is exactly one user of this value.
bool ComputeMultiple(Value *V, unsigned Base, Value *&Multiple, bool LookThroughSExt=false, unsigned Depth=0)
ComputeMultiple - This function computes the integer multiple of Base that equals V...
bool isString() const
isString - This method returns true if this is an array of i8.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
static void computeKnownBitsFromAssume(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth, const Query &Q)
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
uint64_t getArrayNumElements() const
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
getConstantStringInfo - This function computes the length of a null-terminated C string pointed to by...
BinOp2_match< LHS, RHS, Instruction::SDiv, Instruction::UDiv > m_IDiv(const LHS &L, const RHS &R)
Matches UDiv and SDiv.
bool CannotBeNegativeZero(const Value *V, unsigned Depth=0)
CannotBeNegativeZero - Return true if we can prove that the specified FP value is never equal to -0...
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
LLVM Value Representation.
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.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
const Value * getFalseValue() const
static bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth, const Query &Q)
Return true if 'V & Mask' is known to be zero.
StringRef - Represent a constant reference to a string, i.e.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
SimplifyInstruction - See if we can compute a simplified version of this instruction.
static SelectPatternFlavor matchSelectPattern(ICmpInst::Predicate Pred, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS)
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, const TargetLibraryInfo *TLI=nullptr)
isSafeToSpeculativelyExecute - Return true if the instruction does not have any effects besides calcu...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
unsigned getNumElements() const
Random access to the elements.
op_range incoming_values()
static IntegerType * getInt8Ty(LLVMContext &C)
const BasicBlock * getParent() const
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
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)