45 using namespace llvm::PatternMatch;
89 std::array<const Value *, MaxDepth> Excluded;
94 : DL(DL), AC(AC), CxtI(CxtI), DT(DT), NumExcluded(0) {}
97 :
DL(Q.
DL), AC(Q.AC), CxtI(Q.CxtI), DT(Q.DT), NumExcluded(Q.NumExcluded) {
98 Excluded = Q.Excluded;
99 Excluded[NumExcluded++] = NewExcl;
100 assert(NumExcluded <= Excluded.size());
104 if (NumExcluded == 0)
106 auto End = Excluded.begin() + NumExcluded;
144 "LHS and RHS should have the same type");
146 "LHS and RHS should be integers");
148 APInt LHSKnownZero(IT->getBitWidth(), 0), LHSKnownOne(IT->getBitWidth(), 0);
149 APInt RHSKnownZero(IT->getBitWidth(), 0), RHSKnownOne(IT->getBitWidth(), 0);
152 return (LHSKnownZero | RHSKnownZero).isAllOnesValue();
155 static void ComputeSignBit(
const Value *V,
bool &KnownZero,
bool &KnownOne,
190 bool NonNegative, Negative;
191 ComputeSignBit(V, NonNegative, Negative, DL, Depth, AC, CxtI, DT);
198 if (
auto *CI = dyn_cast<ConstantInt>(V))
199 return CI->getValue().isStrictlyPositive();
210 bool NonNegative, Negative;
211 ComputeSignBit(V, NonNegative, Negative, DL, Depth, AC, CxtI, DT);
253 if (
const ConstantInt *CLHS = dyn_cast<ConstantInt>(Op0)) {
257 if (!CLHS->getValue().isNegative()) {
267 if ((KnownZero2 & MaskV) == MaskV) {
268 unsigned NLZ2 = CLHS->getValue().countLeadingZeros();
280 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
285 APInt CarryIn(BitWidth, 0);
292 APInt PossibleSumZero = ~LHSKnownZero + ~KnownZero2 + CarryIn;
293 APInt PossibleSumOne = LHSKnownOne + KnownOne2 + CarryIn;
296 APInt CarryKnownZero = ~(PossibleSumZero ^ LHSKnownZero ^ KnownZero2);
297 APInt CarryKnownOne = PossibleSumOne ^ LHSKnownOne ^ KnownOne2;
300 APInt LHSKnown = LHSKnownZero | LHSKnownOne;
301 APInt RHSKnown = KnownZero2 | KnownOne2;
302 APInt CarryKnown = CarryKnownZero | CarryKnownOne;
303 APInt Known = LHSKnown & RHSKnown & CarryKnown;
305 assert((PossibleSumZero & Known) == (PossibleSumOne & Known) &&
306 "known bits of sum differ");
309 KnownZero = ~PossibleSumOne & Known;
310 KnownOne = PossibleSumOne & Known;
313 if (!Known.isNegative()) {
317 if (LHSKnownZero.isNegative() && KnownZero2.
isNegative())
321 else if (LHSKnownOne.
isNegative() && KnownOne2.isNegative())
341 isKnownNonNegative =
true;
343 bool isKnownNonNegativeOp1 = KnownZero.
isNegative();
344 bool isKnownNonNegativeOp0 = KnownZero2.
isNegative();
345 bool isKnownNegativeOp1 = KnownOne.
isNegative();
346 bool isKnownNegativeOp0 = KnownOne2.
isNegative();
348 isKnownNonNegative = (isKnownNegativeOp1 && isKnownNegativeOp0) ||
349 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
352 if (!isKnownNonNegative)
353 isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
355 (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
369 BitWidth) - BitWidth;
371 TrailZ =
std::min(TrailZ, BitWidth);
381 if (isKnownNonNegative && !KnownOne.
isNegative())
382 KnownZero.
setBit(BitWidth - 1);
383 else if (isKnownNegative && !KnownZero.
isNegative())
384 KnownOne.
setBit(BitWidth - 1);
397 for (
unsigned i = 0;
i < NumRanges; ++
i) {
399 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 0));
401 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 1));
405 unsigned CommonPrefixBits =
409 KnownOne &= Range.getUnsignedMax() &
Mask;
410 KnownZero &= ~Range.getUnsignedMax() &
Mask;
425 while (!WorkSet.
empty()) {
427 if (!Visited.
insert(V).second)
436 if (
const User *U = dyn_cast<User>(V))
450 if (
const CallInst *CI = dyn_cast<CallInst>(I))
451 if (
Function *
F = CI->getCalledFunction())
452 switch (
F->getIntrinsicID()) {
455 case Intrinsic::assume:
456 case Intrinsic::dbg_declare:
457 case Intrinsic::dbg_value:
458 case Intrinsic::invariant_start:
459 case Intrinsic::invariant_end:
460 case Intrinsic::lifetime_start:
461 case Intrinsic::lifetime_end:
462 case Intrinsic::objectsize:
463 case Intrinsic::ptr_annotation:
464 case Intrinsic::var_annotation:
524 if (!Q.AC || !Q.CxtI)
532 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
537 "Got assumption for the wrong function!");
546 "must be an assume intrinsic");
551 assert(BitWidth == 1 &&
"assume operand is not i1?");
571 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
573 KnownZero |= RHSKnownZero;
574 KnownOne |= RHSKnownOne;
576 }
else if (
match(Arg,
580 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
582 APInt MaskKnownZero(BitWidth, 0), MaskKnownOne(BitWidth, 0);
587 KnownZero |= RHSKnownZero & MaskKnownOne;
588 KnownOne |= RHSKnownOne & MaskKnownOne;
594 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
596 APInt MaskKnownZero(BitWidth, 0), MaskKnownOne(BitWidth, 0);
601 KnownZero |= RHSKnownOne & MaskKnownOne;
602 KnownOne |= RHSKnownZero & MaskKnownOne;
604 }
else if (
match(Arg,
608 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
610 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
615 KnownZero |= RHSKnownZero & BKnownZero;
616 KnownOne |= RHSKnownOne & BKnownZero;
622 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
624 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
629 KnownZero |= RHSKnownOne & BKnownZero;
630 KnownOne |= RHSKnownZero & BKnownZero;
632 }
else if (
match(Arg,
636 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
638 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
644 KnownZero |= RHSKnownZero & BKnownZero;
645 KnownOne |= RHSKnownOne & BKnownZero;
646 KnownZero |= RHSKnownOne & BKnownOne;
647 KnownOne |= RHSKnownZero & BKnownOne;
653 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
655 APInt BKnownZero(BitWidth, 0), BKnownOne(BitWidth, 0);
661 KnownZero |= RHSKnownOne & BKnownZero;
662 KnownOne |= RHSKnownZero & BKnownZero;
663 KnownZero |= RHSKnownZero & BKnownOne;
664 KnownOne |= RHSKnownOne & BKnownOne;
670 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
681 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
688 }
else if (
match(Arg,
694 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
707 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
717 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
720 if (RHSKnownZero.isNegative()) {
728 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
739 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
750 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
753 if (RHSKnownZero.isAllOnesValue() || RHSKnownOne.
isNegative()) {
761 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
771 APInt RHSKnownZero(BitWidth, 0), RHSKnownOne(BitWidth, 0);
801 if (
auto *SA = dyn_cast<ConstantInt>(I->
getOperand(1))) {
802 unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
805 KnownZero = KZF(KnownZero, ShiftAmt);
806 KnownOne = KOF(KnownOne, ShiftAmt);
810 if ((KnownZero & KnownOne) != 0) {
811 KnownZero.clearAllBits();
812 KnownOne.clearAllBits();
824 uint64_t ShiftAmtKO = KnownOne.zextOrTrunc(64).getZExtValue();
829 KnownOne.clearAllBits();
837 if (!(ShiftAmtKZ & (BitWidth - 1)) && !(ShiftAmtKO & (BitWidth - 1))) {
838 ShifterOperandIsNonZero =
840 if (!*ShifterOperandIsNonZero)
847 for (
unsigned ShiftAmt = 0; ShiftAmt < BitWidth; ++ShiftAmt) {
850 if ((ShiftAmt & ~ShiftAmtKZ) != ShiftAmt)
852 if ((ShiftAmt | ShiftAmtKO) != ShiftAmt)
858 if (!ShifterOperandIsNonZero.
hasValue())
859 ShifterOperandIsNonZero =
861 if (*ShifterOperandIsNonZero)
865 KnownZero &= KZF(KnownZero2, ShiftAmt);
866 KnownOne &= KOF(KnownOne2, ShiftAmt);
874 if ((KnownZero & KnownOne) != 0) {
875 KnownZero.clearAllBits();
876 KnownOne.clearAllBits();
881 APInt &KnownOne,
unsigned Depth,
885 APInt KnownZero2(KnownZero), KnownOne2(KnownOne);
898 KnownOne &= KnownOne2;
900 KnownZero |= KnownZero2;
912 APInt KnownZero3(BitWidth, 0), KnownOne3(BitWidth, 0);
924 KnownZero &= KnownZero2;
926 KnownOne |= KnownOne2;
934 APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2);
936 KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2);
937 KnownZero = KnownZeroOut;
940 case Instruction::Mul: {
941 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
943 KnownOne, KnownZero2, KnownOne2,
Depth, Q);
946 case Instruction::UDiv: {
953 KnownOne2.clearAllBits();
956 unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
957 if (RHSUnknownLeadingOnes != BitWidth)
959 LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
979 unsigned MaxHighOnes = 0;
980 unsigned MaxHighZeros = 0;
983 if (KnownOne[BitWidth - 1] && KnownOne2[BitWidth - 1])
987 std::max(KnownOne.countLeadingOnes(), KnownOne2.countLeadingOnes());
989 else if (KnownZero[BitWidth - 1] || KnownZero2[BitWidth - 1])
993 if (KnownZero[BitWidth - 1] && KnownZero2[BitWidth - 1])
999 else if (KnownOne[BitWidth - 1] || KnownOne2[BitWidth - 1])
1005 std::max(KnownOne.countLeadingOnes(), KnownOne2.countLeadingOnes());
1014 KnownOne &= KnownOne2;
1015 KnownZero &= KnownZero2;
1016 if (MaxHighOnes > 0)
1018 if (MaxHighZeros > 0)
1022 case Instruction::FPTrunc:
1023 case Instruction::FPExt:
1024 case Instruction::FPToUI:
1025 case Instruction::FPToSI:
1026 case Instruction::SIToFP:
1027 case Instruction::UIToFP:
1029 case Instruction::PtrToInt:
1030 case Instruction::IntToPtr:
1033 case Instruction::ZExt:
1034 case Instruction::Trunc: {
1037 unsigned SrcBitWidth;
1040 SrcBitWidth = Q.DL.getTypeSizeInBits(SrcTy->
getScalarType());
1042 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1049 if (BitWidth > SrcBitWidth)
1053 case Instruction::BitCast: {
1064 case Instruction::SExt: {
1068 KnownZero = KnownZero.
trunc(SrcBitWidth);
1069 KnownOne = KnownOne.
trunc(SrcBitWidth);
1071 KnownZero = KnownZero.
zext(BitWidth);
1072 KnownOne = KnownOne.
zext(BitWidth);
1076 if (KnownZero[SrcBitWidth-1])
1078 else if (KnownOne[SrcBitWidth-1])
1082 case Instruction::Shl: {
1084 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1085 auto KZF = [BitWidth, NSW](
const APInt &KnownZero,
unsigned ShiftAmt) {
1087 (KnownZero << ShiftAmt) |
1091 if (NSW && KnownZero.isNegative())
1092 KZResult.
setBit(BitWidth - 1);
1096 auto KOF = [BitWidth, NSW](
const APInt &KnownOne,
unsigned ShiftAmt) {
1097 APInt KOResult = KnownOne << ShiftAmt;
1098 if (NSW && KnownOne.isNegative())
1099 KOResult.
setBit(BitWidth - 1);
1104 KnownZero2, KnownOne2, Depth, Q, KZF,
1108 case Instruction::LShr: {
1110 auto KZF = [BitWidth](
const APInt &KnownZero,
unsigned ShiftAmt) {
1116 auto KOF = [BitWidth](
const APInt &KnownOne,
unsigned ShiftAmt) {
1121 KnownZero2, KnownOne2, Depth, Q, KZF,
1125 case Instruction::AShr: {
1127 auto KZF = [BitWidth](
const APInt &KnownZero,
unsigned ShiftAmt) {
1131 auto KOF = [BitWidth](
const APInt &KnownOne,
unsigned ShiftAmt) {
1136 KnownZero2, KnownOne2, Depth, Q, KZF,
1140 case Instruction::Sub: {
1141 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1143 KnownZero, KnownOne, KnownZero2, KnownOne2,
Depth,
1148 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
1150 KnownZero, KnownOne, KnownZero2, KnownOne2,
Depth,
1154 case Instruction::SRem:
1158 APInt LowBits = RA - 1;
1163 KnownZero = KnownZero2 & LowBits;
1164 KnownOne = KnownOne2 & LowBits;
1168 if (KnownZero2[BitWidth-1] || ((KnownZero2 & LowBits) == LowBits))
1169 KnownZero |= ~LowBits;
1173 if (KnownOne2[BitWidth-1] && ((KnownOne2 & LowBits) != 0))
1174 KnownOne |= ~LowBits;
1176 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
1183 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
1187 if (LHSKnownZero.isNegative())
1188 KnownZero.
setBit(BitWidth - 1);
1192 case Instruction::URem: {
1194 const APInt &RA = Rem->getValue();
1196 APInt LowBits = (RA - 1);
1198 KnownZero |= ~LowBits;
1199 KnownOne &= LowBits;
1211 KnownOne.clearAllBits();
1216 case Instruction::Alloca: {
1226 case Instruction::GetElementPtr: {
1229 APInt LocalKnownZero(BitWidth, 0), LocalKnownOne(BitWidth, 0);
1232 unsigned TrailZ = LocalKnownZero.countTrailingOnes();
1241 Constant *CIndex = cast<Constant>(Index);
1248 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
1251 TrailZ = std::min<unsigned>(TrailZ,
1261 uint64_t TypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1262 LocalKnownZero = LocalKnownOne =
APInt(GEPOpiBits, 0);
1266 LocalKnownZero.countTrailingOnes()));
1273 case Instruction::PHI: {
1279 for (
unsigned i = 0;
i != 2; ++
i) {
1290 Opcode == Instruction::Sub ||
1293 Opcode == Instruction::Mul) {
1308 APInt KnownZero3(KnownZero), KnownOne3(KnownOne);
1313 KnownZero3.countTrailingOnes()));
1319 if (OverflowOp && OverflowOp->hasNoSignedWrap()) {
1330 if (KnownZero2.
isNegative() && KnownZero3.isNegative())
1331 KnownZero.
setBit(BitWidth - 1);
1333 KnownOne.
setBit(BitWidth - 1);
1338 else if (Opcode == Instruction::Sub && LL == I) {
1340 KnownZero.
setBit(BitWidth - 1);
1341 else if (KnownOne2.
isNegative() && KnownZero3.isNegative())
1342 KnownOne.
setBit(BitWidth - 1);
1346 else if (Opcode == Instruction::Mul && KnownZero2.
isNegative() &&
1347 KnownZero3.isNegative())
1348 KnownZero.
setBit(BitWidth - 1);
1362 if (Depth <
MaxDepth - 1 && !KnownZero && !KnownOne) {
1371 if (IncValue == P)
continue;
1373 KnownZero2 =
APInt(BitWidth, 0);
1374 KnownOne2 =
APInt(BitWidth, 0);
1378 KnownZero &= KnownZero2;
1379 KnownOne &= KnownOne2;
1382 if (!KnownZero && !KnownOne)
1389 case Instruction::Invoke:
1397 KnownZero |= KnownZero2;
1398 KnownOne |= KnownOne2;
1401 switch (II->getIntrinsicID()) {
1403 case Intrinsic::bswap:
1405 KnownZero |= KnownZero2.
byteSwap();
1408 case Intrinsic::ctlz:
1409 case Intrinsic::cttz: {
1410 unsigned LowBits =
Log2_32(BitWidth)+1;
1417 case Intrinsic::ctpop: {
1422 unsigned LeadingZeros =
1424 assert(LeadingZeros <= BitWidth);
1426 KnownOne &= ~KnownZero;
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, KnownZero,
1455 KnownOne, KnownZero2, KnownOne2,
Depth, Q);
1457 case Intrinsic::usub_with_overflow:
1458 case Intrinsic::ssub_with_overflow:
1460 II->getArgOperand(1),
false, KnownZero,
1461 KnownOne, KnownZero2, KnownOne2,
Depth, Q);
1463 case Intrinsic::umul_with_overflow:
1464 case Intrinsic::smul_with_overflow:
1466 KnownZero, KnownOne, KnownZero2, KnownOne2,
Depth,
1491 unsigned Depth,
const Query &Q) {
1492 assert(V &&
"No Value?");
1498 "Not integer or pointer type!");
1504 "V, KnownOne and KnownZero should have same BitWidth");
1510 KnownZero = ~KnownOne;
1514 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
1526 for (
unsigned i = 0, e = CDS->getNumElements();
i != e; ++
i) {
1527 Elt = CDS->getElementAsInteger(
i);
1534 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
1539 for (
unsigned i = 0, e = CV->getNumOperands();
i != e; ++
i) {
1541 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
1547 Elt = ElementCI->getValue();
1558 if (isa<UndefValue>(V))
1563 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
1572 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1573 if (!GA->isInterposable())
1578 if (
const Operator *I = dyn_cast<Operator>(V))
1594 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
1600 unsigned Depth,
const Query &Q) {
1607 APInt ZeroBits(BitWidth, 0);
1608 APInt OneBits(BitWidth, 0);
1610 KnownOne = OneBits[BitWidth - 1];
1611 KnownZero = ZeroBits[BitWidth - 1];
1620 if (
const Constant *
C = dyn_cast<Constant>(V)) {
1621 if (
C->isNullValue())
1624 const APInt *ConstIntOrConstSplatInt;
1626 return ConstIntOrConstSplatInt->
isPowerOf2();
1643 Value *
X =
nullptr, *
Y =
nullptr;
1650 if (
const ZExtInst *ZI = dyn_cast<ZExtInst>(V))
1683 APInt LHSZeroBits(BitWidth, 0), LHSOneBits(BitWidth, 0);
1686 APInt RHSZeroBits(BitWidth, 0), RHSOneBits(BitWidth, 0);
1691 if ((~(LHSZeroBits & RHSZeroBits)).isPowerOf2())
1734 GTI != GTE; ++GTI) {
1736 if (
StructType *STy = GTI.getStructTypeOrNull()) {
1737 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
1741 if (ElementOffset > 0)
1747 if (Q.DL.getTypeAllocSize(GTI.getIndexedType()) == 0)
1752 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
1779 for (
unsigned i = 0;
i < NumRanges; ++
i) {
1781 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 *
i + 0));
1783 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 *
i + 1));
1785 if (Range.contains(Value))
1796 if (
auto *
C = dyn_cast<Constant>(V)) {
1797 if (
C->isNullValue())
1799 if (isa<ConstantInt>(
C))
1805 if (
auto *VecTy = dyn_cast<VectorType>(
C->getType())) {
1806 for (
unsigned i = 0, e = VecTy->getNumElements();
i != e; ++
i) {
1810 if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
1819 if (
auto *I = dyn_cast<Instruction>(V)) {
1823 if (
auto *Ty = dyn_cast<IntegerType>(V->
getType())) {
1824 const APInt ZeroValue(Ty->getBitWidth(), 0);
1847 Value *
X =
nullptr, *
Y =
nullptr;
1852 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
1853 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), Depth, Q);
1863 APInt KnownZero(BitWidth, 0);
1864 APInt KnownOne(BitWidth, 0);
1877 bool XKnownNonNegative, XKnownNegative;
1886 APInt KnownZero(BitWidth, 0);
1887 APInt KnownOne(BitWidth, 0);
1890 auto ShiftVal = Shift->getLimitedValue(BitWidth - 1);
1905 bool XKnownNonNegative, XKnownNegative;
1906 bool YKnownNonNegative, YKnownNegative;
1912 if (XKnownNonNegative && YKnownNonNegative)
1918 if (BitWidth && XKnownNegative && YKnownNegative) {
1919 APInt KnownZero(BitWidth, 0);
1920 APInt KnownOne(BitWidth, 0);
1925 if ((KnownOne & Mask) != 0)
1930 if ((KnownOne & Mask) != 0)
1935 if (XKnownNonNegative &&
1938 if (YKnownNonNegative &&
1952 else if (
const SelectInst *
SI = dyn_cast<SelectInst>(V)) {
1958 else if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
1961 if (PN->getNumIncomingValues() == 2) {
1962 Value *Start = PN->getIncomingValue(0);
1963 Value *Induction = PN->getIncomingValue(1);
1964 if (isa<ConstantInt>(Induction) && !isa<ConstantInt>(Start))
1967 if (!
C->isZero() && !
C->isNegative()) {
1977 bool AllNonZeroConstants =
all_of(PN->operands(), [](Value *V) {
1978 return isa<ConstantInt>(V) && !cast<ConstantInt>(V)->isZeroValue();
1980 if (AllNonZeroConstants)
1984 if (!BitWidth)
return false;
1985 APInt KnownZero(BitWidth, 0);
1986 APInt KnownOne(BitWidth, 0);
1988 return KnownOne != 0;
1996 Value *
Op =
nullptr;
2019 auto BitWidth = Ty->getBitWidth();
2020 APInt KnownZero1(BitWidth, 0);
2021 APInt KnownOne1(BitWidth, 0);
2023 APInt KnownZero2(BitWidth, 0);
2024 APInt KnownOne2(BitWidth, 0);
2027 auto OppositeBits = (KnownZero1 & KnownOne2) | (KnownZero2 & KnownOne1);
2028 if (OppositeBits.getBoolValue())
2047 return (KnownZero & Mask) ==
Mask;
2057 if (!CV || !CV->getType()->isVectorTy())
2060 unsigned MinSignBits = TyBits;
2061 unsigned NumElts = CV->getType()->getVectorNumElements();
2062 for (
unsigned i = 0;
i != NumElts; ++
i) {
2064 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(
i));
2069 APInt EltVal = Elt->getValue();
2087 unsigned FirstAnswer = 1;
2098 case Instruction::SExt:
2102 case Instruction::SDiv: {
2103 const APInt *Denominator;
2120 case Instruction::SRem: {
2121 const APInt *Denominator;
2149 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
2150 return std::max(NumrBits, ResBits);
2155 case Instruction::AShr: {
2160 Tmp += ShAmt->getZExtValue();
2161 if (Tmp > TyBits) Tmp = TyBits;
2165 case Instruction::Shl: {
2171 if (Tmp2 >= TyBits ||
2193 if (Tmp == 1)
return 1;
2201 if (Tmp == 1)
return 1;
2204 if (
const auto *CRHS = dyn_cast<Constant>(U->
getOperand(1)))
2205 if (CRHS->isAllOnesValue()) {
2206 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
2211 if ((KnownZero |
APInt(TyBits, 1)).isAllOnesValue())
2221 if (Tmp2 == 1)
return 1;
2224 case Instruction::Sub:
2226 if (Tmp2 == 1)
return 1;
2229 if (
const auto *CLHS = dyn_cast<Constant>(U->
getOperand(0)))
2230 if (CLHS->isNullValue()) {
2231 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
2235 if ((KnownZero |
APInt(TyBits, 1)).isAllOnesValue())
2249 if (Tmp == 1)
return 1;
2252 case Instruction::PHI: {
2253 const PHINode *PN = cast<PHINode>(U);
2256 if (NumIncomingValues > 4)
break;
2258 if (NumIncomingValues == 0)
break;
2263 for (
unsigned i = 1, e = NumIncomingValues;
i != e; ++
i) {
2264 if (Tmp == 1)
return Tmp;
2271 case Instruction::Trunc:
2276 case Instruction::ExtractElement:
2292 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
2312 bool LookThroughSExt,
unsigned Depth) {
2315 assert(V &&
"No Value?");
2316 assert(Depth <= MaxDepth &&
"Limit Search Depth");
2333 if (CO && CO == BaseVal) {
2344 if (Depth == MaxDepth)
return false;
2347 if (!I)
return false;
2351 case Instruction::SExt:
2352 if (!LookThroughSExt)
return false;
2354 case Instruction::ZExt:
2356 LookThroughSExt, Depth+1);
2357 case Instruction::Shl:
2358 case Instruction::Mul: {
2362 if (I->
getOpcode() == Instruction::Shl) {
2364 if (!Op1CI)
return false;
2373 Value *Mul0 =
nullptr;
2375 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
2376 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
2377 if (Op1C->getType()->getPrimitiveSizeInBits() <
2378 MulC->getType()->getPrimitiveSizeInBits())
2380 if (Op1C->getType()->getPrimitiveSizeInBits() >
2381 MulC->getType()->getPrimitiveSizeInBits())
2389 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
2390 if (Mul0CI->getValue() == 1) {
2397 Value *Mul1 =
nullptr;
2399 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
2400 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
2401 if (Op0C->getType()->getPrimitiveSizeInBits() <
2402 MulC->getType()->getPrimitiveSizeInBits())
2404 if (Op0C->getType()->getPrimitiveSizeInBits() >
2405 MulC->getType()->getPrimitiveSizeInBits())
2413 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
2414 if (Mul1CI->getValue() == 1) {
2457 return Intrinsic::sin;
2461 return Intrinsic::cos;
2465 return Intrinsic::exp;
2467 case LibFunc::exp2f:
2468 case LibFunc::exp2l:
2469 return Intrinsic::exp2;
2473 return Intrinsic::log;
2474 case LibFunc::log10:
2475 case LibFunc::log10f:
2476 case LibFunc::log10l:
2477 return Intrinsic::log10;
2479 case LibFunc::log2f:
2480 case LibFunc::log2l:
2481 return Intrinsic::log2;
2483 case LibFunc::fabsf:
2484 case LibFunc::fabsl:
2485 return Intrinsic::fabs;
2487 case LibFunc::fminf:
2488 case LibFunc::fminl:
2491 case LibFunc::fmaxf:
2492 case LibFunc::fmaxl:
2494 case LibFunc::copysign:
2495 case LibFunc::copysignf:
2496 case LibFunc::copysignl:
2497 return Intrinsic::copysign;
2498 case LibFunc::floor:
2499 case LibFunc::floorf:
2500 case LibFunc::floorl:
2501 return Intrinsic::floor;
2503 case LibFunc::ceilf:
2504 case LibFunc::ceill:
2505 return Intrinsic::ceil;
2506 case LibFunc::trunc:
2507 case LibFunc::truncf:
2508 case LibFunc::truncl:
2509 return Intrinsic::trunc;
2511 case LibFunc::rintf:
2512 case LibFunc::rintl:
2513 return Intrinsic::rint;
2514 case LibFunc::nearbyint:
2515 case LibFunc::nearbyintf:
2516 case LibFunc::nearbyintl:
2517 return Intrinsic::nearbyint;
2519 case LibFunc::roundf:
2520 case LibFunc::roundl:
2525 return Intrinsic::pow;
2527 case LibFunc::sqrtf:
2528 case LibFunc::sqrtl:
2529 if (ICS->hasNoNaNs())
2530 return Intrinsic::sqrt;
2545 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V))
2546 return !CFP->getValueAPF().isNegZero();
2552 if (!I)
return false;
2556 if (FPO->hasNoSignedZeros())
2560 if (I->
getOpcode() == Instruction::FAdd)
2562 if (CFP->isNullValue())
2566 if (isa<SIToFPInst>(I) || isa<UIToFPInst>(
I))
2569 if (
const CallInst *CI = dyn_cast<CallInst>(I)) {
2575 case Intrinsic::sqrt:
2578 case Intrinsic::fabs:
2593 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2594 return !CFP->getValueAPF().isNegative() ||
2595 (!SignBitOnly && CFP->getValueAPF().isZero());
2609 case Instruction::UIToFP:
2611 case Instruction::FMul:
2614 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()))
2618 case Instruction::FAdd:
2619 case Instruction::FDiv:
2620 case Instruction::FRem:
2630 case Instruction::FPExt:
2631 case Instruction::FPTrunc:
2650 case Intrinsic::exp:
2651 case Intrinsic::exp2:
2652 case Intrinsic::fabs:
2653 case Intrinsic::sqrt:
2655 case Intrinsic::powi:
2658 if (CI->getBitWidth() <= 64 && CI->getSExtValue() % 2u == 0)
2663 case Intrinsic::fma:
2664 case Intrinsic::fmuladd:
2667 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()) &&
2695 if (
Constant *
C = dyn_cast<Constant>(V))
2696 if (
C->isNullValue())
2701 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2702 if (CFP->getType()->isFloatTy())
2704 if (CFP->getType()->isDoubleTy())
2711 if (CI->getBitWidth() % 8 == 0) {
2712 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
2714 if (!CI->getValue().isSplat(8))
2723 Value *Elt = CA->getElementAsConstant(0);
2728 for (
unsigned I = 1,
E = CA->getNumElements(); I !=
E; ++
I)
2729 if (CA->getElementAsConstant(I) != Elt)
2769 while (PrevTo != OrigTo) {
2795 "tmp", InsertBefore);
2812 assert(InsertBefore &&
"Must have someplace to insert!");
2817 unsigned IdxSkip = Idxs.
size();
2832 if (idx_range.
empty())
2836 "Not looking at a struct or array?");
2838 "Invalid indices for type?");
2840 if (
Constant *
C = dyn_cast<Constant>(V)) {
2841 C =
C->getAggregateElement(idx_range[0]);
2842 if (!
C)
return nullptr;
2849 const unsigned *req_idx = idx_range.
begin();
2850 for (
const unsigned *
i = I->idx_begin(), *e = I->idx_end();
2851 i != e; ++
i, ++req_idx) {
2852 if (req_idx == idx_range.
end()) {
2892 unsigned size = I->getNumIndices() + idx_range.
size();
2897 Idxs.
append(I->idx_begin(), I->idx_end());
2903 &&
"Number of indices added not correct?");
2917 APInt ByteOffset(BitWidth, 0);
2923 while (Visited.
insert(Ptr).second) {
2935 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
2940 Ptr =
GEP->getPointerOperand();
2943 Ptr = cast<Operator>(
Ptr)->getOperand(0);
2944 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
2945 if (GA->isInterposable())
2947 Ptr = GA->getAliasee();
2969 if (!FirstIdx || !FirstIdx->
isZero())
2979 uint64_t
Offset,
bool TrimAtNul) {
2996 uint64_t StartIdx = 0;
2997 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
GEP->getOperand(2)))
2998 StartIdx = CI->getZExtValue();
3022 if (!Array || !Array->isString())
3029 Str = Array->getAsString();
3031 if (Offset > NumElts)
3035 Str = Str.
substr(Offset);
3059 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
3060 if (!PHIs.
insert(PN).second)
3064 uint64_t LenSoFar = ~0ULL;
3065 for (Value *IncValue : PN->incoming_values()) {
3067 if (Len == 0)
return 0;
3069 if (Len == ~0ULL)
continue;
3071 if (Len != LenSoFar && LenSoFar != ~0ULL)
3083 if (Len1 == 0)
return 0;
3085 if (Len2 == 0)
return 0;
3086 if (Len1 == ~0ULL)
return Len2;
3087 if (Len2 == ~0ULL)
return Len1;
3088 if (Len1 != Len2)
return 0;
3097 return StrData.
size()+1;
3109 return Len == ~0ULL ? 1 : Len;
3123 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3125 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
3133 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
3140 unsigned MaxLookup) {
3143 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
3145 V =
GEP->getPointerOperand();
3148 V = cast<Operator>(V)->getOperand(0);
3149 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
3150 if (GA->isInterposable())
3152 V = GA->getAliasee();
3155 if (Value *RV = CS.getReturnedArgOperand()) {
3177 unsigned MaxLookup) {
3185 if (!Visited.
insert(P).second)
3194 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
3207 for (Value *IncValue : PN->incoming_values())
3213 }
while (!Worklist.
empty());
3220 if (!II)
return false;
3244 case Instruction::UDiv:
3245 case Instruction::URem: {
3252 case Instruction::SDiv:
3253 case Instruction::SRem: {
3255 const APInt *Numerator, *Denominator;
3259 if (*Denominator == 0)
3262 if (*Denominator != -1)
3272 const LoadInst *LI = cast<LoadInst>(Inst);
3284 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
3285 switch (II->getIntrinsicID()) {
3290 case Intrinsic::dbg_declare:
3291 case Intrinsic::dbg_value:
3294 case Intrinsic::bitreverse:
3295 case Intrinsic::bswap:
3296 case Intrinsic::ctlz:
3297 case Intrinsic::ctpop:
3298 case Intrinsic::cttz:
3299 case Intrinsic::objectsize:
3300 case Intrinsic::sadd_with_overflow:
3301 case Intrinsic::smul_with_overflow:
3302 case Intrinsic::ssub_with_overflow:
3303 case Intrinsic::uadd_with_overflow:
3304 case Intrinsic::umul_with_overflow:
3305 case Intrinsic::usub_with_overflow:
3309 case Intrinsic::sqrt:
3310 case Intrinsic::fma:
3311 case Intrinsic::fmuladd:
3315 case Intrinsic::trunc:
3316 case Intrinsic::copysign:
3317 case Intrinsic::fabs:
3324 case Intrinsic::ceil:
3325 case Intrinsic::floor:
3326 case Intrinsic::nearbyint:
3327 case Intrinsic::rint:
3338 case Instruction::VAArg:
3339 case Instruction::Alloca:
3340 case Instruction::Invoke:
3341 case Instruction::PHI:
3344 case Instruction::Br:
3345 case Instruction::IndirectBr:
3347 case Instruction::Unreachable:
3348 case Instruction::Fence:
3349 case Instruction::AtomicRMW:
3350 case Instruction::AtomicCmpXchg:
3351 case Instruction::LandingPad:
3352 case Instruction::Resume:
3353 case Instruction::CatchSwitch:
3354 case Instruction::CatchPad:
3355 case Instruction::CatchRet:
3356 case Instruction::CleanupPad:
3357 case Instruction::CleanupRet:
3371 if (isa<AllocaInst>(V))
return true;
3374 if (
const Argument *
A = dyn_cast<Argument>(V))
3375 return A->hasByValOrInAllocaAttr() ||
A->hasNonNullAttr();
3380 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
3381 return !GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
3382 GV->getType()->getAddressSpace() == 0;
3385 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
3389 if (CS.isReturnNonNull())
3399 assert(!isa<ConstantData>(V) &&
"Did not expect ConstantPointerNull");
3400 assert(CtxI &&
"Context instruction required for analysis");
3401 assert(DT &&
"Dominator tree required for analysis");
3403 unsigned NumUsesExplored = 0;
3404 for (
auto *U : V->
users()) {
3411 if (!
match(const_cast<User *>(U),
3416 for (
auto *CmpU : U->users()) {
3417 if (
const BranchInst *BI = dyn_cast<BranchInst>(CmpU)) {
3418 assert(BI->isConditional() &&
"uses a comparison!");
3426 match(CmpU, m_Intrinsic<Intrinsic::experimental_guard>()) &&
3427 DT->
dominates(cast<Instruction>(CmpU), CtxI)) {
3438 if (isa<ConstantPointerNull>(V) || isa<UndefValue>(V))
3463 APInt LHSKnownZero(BitWidth, 0);
3464 APInt LHSKnownOne(BitWidth, 0);
3465 APInt RHSKnownZero(BitWidth, 0);
3466 APInt RHSKnownOne(BitWidth, 0);
3477 if (ZeroBits >= BitWidth)
3481 APInt LHSMax = ~LHSKnownZero;
3482 APInt RHSMax = ~RHSKnownZero;
3487 LHSMax.
umul_ov(RHSMax, MaxOverflow);
3494 LHSKnownOne.
umul_ov(RHSKnownOne, MinOverflow);
3507 bool LHSKnownNonNegative, LHSKnownNegative;
3508 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, DL, 0,
3510 if (LHSKnownNonNegative || LHSKnownNegative) {
3511 bool RHSKnownNonNegative, RHSKnownNegative;
3512 ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, DL, 0,
3515 if (LHSKnownNegative && RHSKnownNegative) {
3521 if (LHSKnownNonNegative && RHSKnownNonNegative) {
3542 bool LHSKnownNonNegative, LHSKnownNegative;
3543 bool RHSKnownNonNegative, RHSKnownNegative;
3544 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, DL, 0,
3546 ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, DL, 0,
3549 if ((LHSKnownNonNegative && RHSKnownNegative) ||
3550 (LHSKnownNegative && RHSKnownNonNegative)) {
3563 bool LHSOrRHSKnownNonNegative =
3564 (LHSKnownNonNegative || RHSKnownNonNegative);
3565 bool LHSOrRHSKnownNegative = (LHSKnownNegative || RHSKnownNegative);
3566 if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) {
3567 bool AddKnownNonNegative, AddKnownNegative;
3570 if ((AddKnownNonNegative && LHSOrRHSKnownNonNegative) ||
3571 (AddKnownNegative && LHSOrRHSKnownNegative)) {
3583 assert((IID == Intrinsic::sadd_with_overflow ||
3584 IID == Intrinsic::uadd_with_overflow ||
3585 IID == Intrinsic::ssub_with_overflow ||
3586 IID == Intrinsic::usub_with_overflow ||
3587 IID == Intrinsic::smul_with_overflow ||
3588 IID == Intrinsic::umul_with_overflow) &&
3589 "Not an overflow intrinsic!");
3596 if (
const auto *EVI = dyn_cast<ExtractValueInst>(U)) {
3597 assert(EVI->getNumIndices() == 1 &&
"Obvious from CI's type");
3599 if (EVI->getIndices()[0] == 0)
3602 assert(EVI->getIndices()[0] == 1 &&
"Obvious from CI's type");
3604 for (
const auto *U : EVI->users())
3605 if (
const auto *
B = dyn_cast<BranchInst>(U)) {
3606 assert(
B->isConditional() &&
"How else is it using an i1?");
3617 auto AllUsesGuardedByBranch = [&](
const BranchInst *BI) {
3619 if (!NoWrapEdge.isSingleEdge())
3623 for (
const auto *Result : Results) {
3626 if (DT.
dominates(NoWrapEdge, Result->getParent()))
3629 for (
auto &RU : Result->uses())
3637 return any_of(GuardingBranches, AllUsesGuardedByBranch);
3647 Add, DL, AC, CxtI, DT);
3666 if (
const LoadInst *LI = dyn_cast<LoadInst>(I))
3667 return !LI->isVolatile();
3669 return !
SI->isVolatile();
3671 return !CXI->isVolatile();
3673 return !RMWI->isVolatile();
3674 if (
const MemIntrinsic *MII = dyn_cast<MemIntrinsic>(I))
3675 return !MII->isVolatile();
3678 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(I))
3679 return !CRI->unwindsToCaller();
3680 if (
const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(I))
3681 return !CatchSwitch->unwindsToCaller();
3682 if (isa<ResumeInst>(I))
3684 if (isa<ReturnInst>(I))
3690 if (!CS.doesNotThrow())
3709 return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory() ||
3710 match(I, m_Intrinsic<Intrinsic::assume>());
3726 if (&LI == I)
return true;
3729 llvm_unreachable(
"Instruction not contained in its own parent basic block.");
3735 case Instruction::Sub:
3737 case Instruction::Trunc:
3738 case Instruction::BitCast:
3739 case Instruction::AddrSpaceCast:
3745 case Instruction::AShr:
3746 case Instruction::SExt:
3751 case Instruction::Shl: {
3762 auto *OBO = cast<OverflowingBinaryOperator>(
I);
3763 return OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap();
3766 case Instruction::Mul: {
3778 auto *OBO = cast<OverflowingBinaryOperator>(
I);
3779 if (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) {
3780 for (Value *V : OBO->operands()) {
3781 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
3784 return !CI->isZero();
3791 case Instruction::ICmp:
3796 case Instruction::GetElementPtr:
3803 return cast<GEPOperator>(
I)->isInBounds();
3818 case Instruction::AtomicCmpXchg:
3821 case Instruction::AtomicRMW:
3824 case Instruction::UDiv:
3825 case Instruction::SDiv:
3826 case Instruction::URem:
3827 case Instruction::SRem:
3849 YieldsPoison.
insert(PoisonI);
3857 if (&I != PoisonI) {
3859 if (NotPoison !=
nullptr && YieldsPoison.
count(NotPoison))
3866 if (YieldsPoison.
count(&I)) {
3876 if (Visited.
insert(NextBB).second) {
3893 if (
auto *
C = dyn_cast<ConstantFP>(V))
3899 if (
auto *
C = dyn_cast<ConstantFP>(V))
3900 return !
C->isZero();
3906 Value *CmpLHS, Value *CmpRHS,
3907 Value *TrueVal, Value *FalseVal,
3908 Value *&LHS, Value *&RHS) {
3938 if ((CmpLHS == TrueVal &&
match(FalseVal,
m_APInt(C2))) ||
3984 Value *CmpLHS, Value *CmpRHS,
3985 Value *TrueVal, Value *FalseVal,
3986 Value *&LHS, Value *&RHS) {
4006 bool Ordered =
false;
4017 if (LHSSafe && RHSSafe) {
4047 if (TrueVal == CmpRHS && FalseVal == CmpLHS) {
4058 if (TrueVal == CmpLHS && FalseVal == CmpRHS) {
4099 return matchMinMax(Pred, CmpLHS, CmpRHS, TrueVal, FalseVal, LHS, RHS);
4110 if (
auto *CI2 = dyn_cast<CastInst>(V2)) {
4113 if (CI2->getOpcode() == CI->
getOpcode() &&
4115 return CI2->getOperand(0);
4126 if (isa<SExtInst>(CI) && CmpI->
isSigned())
4129 if (isa<TruncInst>(CI))
4132 if (isa<FPTruncInst>(CI))
4135 if (isa<FPExtInst>(CI))
4138 if (isa<FPToUIInst>(CI))
4141 if (isa<FPToSIInst>(CI))
4144 if (isa<UIToFPInst>(CI))
4147 if (isa<SIToFPInst>(CI))
4156 if (CastedBack != C)
4176 if (isa<FPMathOperator>(CmpI))
4187 cast<CastInst>(TrueVal)->getOperand(0),
C,
4191 C, cast<CastInst>(FalseVal)->getOperand(0),
4200 const Value *LHS,
const Value *RHS,
4229 auto MatchNUWAddsToSameValue = [&](
const Value *
A,
const Value *
B,
4239 unsigned BitWidth = CA->getBitWidth();
4240 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
4243 if ((KnownZero & *CA) == *CA && (KnownZero & *CB) == *CB)
4251 const APInt *CLHS, *CRHS;
4252 if (MatchNUWAddsToSameValue(LHS, RHS, X, CLHS, CRHS))
4253 return CLHS->
ule(*CRHS);
4264 const Value *ARHS,
const Value *BLHS,
4293 const Value *BLHS,
const Value *BRHS,
4294 bool &IsSwappedOps) {
4296 bool IsMatchingOps = (ALHS == BLHS && ARHS == BRHS);
4297 IsSwappedOps = (ALHS == BRHS && ARHS == BLHS);
4298 return IsMatchingOps || IsSwappedOps;
4310 bool IsSwappedOps) {
4332 assert(ALHS == BLHS &&
"LHS operands must match.");
4339 if (Intersection.isEmptySet())
4359 if (!InvertAPred && LHS == RHS)
4382 APred, ALHS, ARHS, BPred, BLHS, BRHS, IsSwappedOps))
4391 if (ALHS == BLHS && isa<ConstantInt>(ARHS) && isa<ConstantInt>(BRHS)) {
4393 APred, ALHS, cast<ConstantInt>(ARHS), BPred, BLHS,
4394 cast<ConstantInt>(BRHS)))
void clearAllBits()
Set every bit to 0.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
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")))
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool isImpliedTrueByMatchingCmp(Predicate Pred2)
Determine if Pred1 implies Pred2 is true when two compares have matching operands.
void computeKnownBits(const 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...
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.
This class is the base class for the comparison instructions.
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.
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 APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
LLVM Argument representation.
Value * getAggregateOperand()
uint64_t getZExtValue() const
Get zero extended value.
static void computeKnownBitsFromOperator(const Operator *I, APInt &KnownZero, APInt &KnownOne, unsigned Depth, const Query &Q)
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...
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.
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.
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
void setBit(unsigned bitPosition)
Set a given bit to 1.
uint64_t GetStringLength(const Value *V)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
bool isKnownNotFullPoison(const Instruction *PoisonI)
Return true if this function can prove that if PoisonI is executed and yields a full-poison value (al...
This class represents zero extension of integer types.
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Xor >, BinaryOp_match< RHS, LHS, Instruction::Xor > > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
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.
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)
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.".
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.
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)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
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
static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, unsigned Depth, const Query &Q)
Function Alias Analysis Results
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
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 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.
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.
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...
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::And >, BinaryOp_match< RHS, LHS, Instruction::And > > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
void reserve(size_type N)
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...
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.
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.
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...
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Or >, BinaryOp_match< RHS, LHS, Instruction::Or > > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
StructType * getStructTypeOrNull() const
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static Value * getPointerOperand(Instruction &Inst)
This class represents the LLVM 'select' instruction.
bool noSignedZeros() const
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
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)
void computeKnownBitsFromRangeMetadata(const MDNode &Ranges, APInt &KnownZero, APInt &KnownOne)
Compute known bits from the range metadata.
static bool isAssumeLikeIntrinsic(const Instruction *I)
Class to represent struct types.
BinOp2_match< LHS, RHS, Instruction::LShr, Instruction::AShr > m_Shr(const LHS &L, const RHS &R)
Matches LShr or AShr.
A Use represents the edge between a Value definition and its users.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
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.
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 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 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.
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.
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)
Matches an ICmp with a predicate over LHS and RHS in either order.
static SelectPatternResult matchSelectPattern(CmpInst::Predicate Pred, FastMathFlags FMF, Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for storing to memory.
bool isGEPBasedOnPointerToString(const GEPOperator *GEP)
Returns true if the GEP is based on a pointer to a string (array of i8), and is indexing into this st...
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
APInt ashr(const APInt &LHS, unsigned shiftAmt)
Arithmetic right-shift function.
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.
static unsigned ComputeNumSignBits(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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
Type * getElementType() const
size_t size() const
size - Get the array size.
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 etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
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 getLibFunc(StringRef funcName, LibFunc::Func &F) const
Searches for a particular function name.
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)
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)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
static uint64_t GetStringLengthH(const Value *V, SmallPtrSetImpl< const PHINode * > &PHIs)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
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.
APInt trunc(unsigned width) const
Truncate to new width.
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.
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.
This is an important base class in LLVM.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
const Value * getCondition() const
int64_t getSExtValue() const
Get sign extended value.
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.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
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.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
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...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
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 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.
Type * getSrcTy() const
Return the source type, as a convenience.
unsigned countPopulation() const
Count the number of bits set.
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.
Optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool InvertAPred=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.
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 append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
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)
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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.
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.
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...
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...
static void computeKnownBitsFromShiftOperator(const Operator *I, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, unsigned Depth, const Query &Q, function_ref< APInt(const APInt &, unsigned)> KZF, function_ref< APInt(const APInt &, unsigned)> KOF)
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...
static void computeKnownBitsFromAssume(const Value *V, APInt &KnownZero, APInt &KnownOne, unsigned Depth, const Query &Q)
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...
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.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isTrueWhenEqual() const
This is just a convenience.
LLVM_NODISCARD T pop_back_val()
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
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.
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...
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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.
static cl::opt< unsigned > DomConditionsMaxUses("dom-conditions-max-uses", cl::Hidden, cl::init(20))
Class for arbitrary precision integers.
BasicBlock * getSingleSuccessor()
Return the successor of this block if it has a single successor.
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()
BasicBlock * getSinglePredecessor()
Return the predecessor of this block if it has a single predecessor block.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isFPPredicate() const
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
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.
unsigned countLeadingOnes() const
Count the number of leading one bits.
bool isImpliedFalseByMatchingCmp(Predicate Pred2)
Determine if Pred1 implies Pred2 is false when two compares have matching operands.
static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1, bool NSW, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, unsigned Depth, const Query &Q)
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.
void ComputeSignBit(const Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine whether the sign bit is known to be zero or one.
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...
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.
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)
ImmutableCallSite - establish a view to a call site for examination.
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
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 countTrailingOnes() const
Count the number of trailing one 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 isGuaranteedToExecuteForEveryIteration(const Instruction *I, const Loop *L)
Return true if this function can prove that the instruction I is executed for every iteration of the ...
1 0 1 0 True if unordered or greater than
OverflowResult computeOverflowForUnsignedMul(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given values are known to be non-equal when defined.
OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
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.
BinOp2_match< LHS, RHS, Instruction::SDiv, Instruction::UDiv > m_IDiv(const LHS &L, const RHS &R)
Matches UDiv and SDiv.
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
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
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)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static bool isKnownNonZero(const Value *V, unsigned Depth, const Query &Q)
Return true if the given value is known to be non-zero when defined.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
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.
const Value * getFalseValue() const
Convenience struct for specifying and reasoning about fast-math flags.
StringRef - Represent a constant reference to a string, i.e.
APInt 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)
See if we can compute a simplified version of this instruction.
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 a 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)
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)
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
static IntegerType * getInt8Ty(LLVMContext &C)
const BasicBlock * getParent() const
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...
bool noNaNs() const
Flag queries.
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)
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.