34 using namespace llvm::PatternMatch;
52 if (
ConstantInt *CLHS = dyn_cast<ConstantInt>(Op0)) {
56 if (!CLHS->getValue().isNegative()) {
66 if ((KnownZero2 & MaskV) == MaskV) {
67 unsigned NLZ2 = CLHS->getValue().countLeadingZeros();
81 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
83 assert((LHSKnownZero & LHSKnownOne) == 0 &&
84 "Bits known to be one AND zero?");
85 unsigned LHSKnownZeroOut = LHSKnownZero.countTrailingOnes();
88 assert((KnownZero2 & KnownOne2) == 0 &&
"Bits known to be one AND zero?");
93 if (LHSKnownZeroOut > RHSKnownZeroOut) {
96 KnownZero |= KnownZero2 & Mask;
97 KnownOne |= KnownOne2 & Mask;
102 std::min(LHSKnownZeroOut,
105 }
else if (RHSKnownZeroOut >= LHSKnownZeroOut) {
107 KnownZero |= LHSKnownZero & Mask;
108 KnownOne |= LHSKnownOne & Mask;
116 if (LHSKnownZero.isNegative() && KnownZero2.
isNegative())
119 else if (LHSKnownOne.isNegative() && KnownOne2.isNegative())
123 if (LHSKnownZero.isNegative() && KnownOne2.isNegative())
126 else if (LHSKnownOne.isNegative() && KnownZero2.
isNegative())
140 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
141 assert((KnownZero2 & KnownOne2) == 0 &&
"Bits known to be one AND zero?");
143 bool isKnownNegative =
false;
144 bool isKnownNonNegative =
false;
149 isKnownNonNegative =
true;
151 bool isKnownNonNegativeOp1 = KnownZero.
isNegative();
152 bool isKnownNonNegativeOp0 = KnownZero2.
isNegative();
153 bool isKnownNegativeOp1 = KnownOne.isNegative();
154 bool isKnownNegativeOp0 = KnownOne2.isNegative();
156 isKnownNonNegative = (isKnownNegativeOp1 && isKnownNegativeOp0) ||
157 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
160 if (!isKnownNonNegative)
161 isKnownNegative = (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
163 (isKnownNegativeOp0 && isKnownNonNegativeOp1 &&
172 KnownOne.clearAllBits();
177 BitWidth) - BitWidth;
179 TrailZ = std::min(TrailZ, BitWidth);
180 LeadZ = std::min(LeadZ, BitWidth);
189 if (isKnownNonNegative && !KnownOne.isNegative())
190 KnownZero.
setBit(BitWidth - 1);
191 else if (isKnownNegative && !KnownZero.
isNegative())
192 KnownOne.setBit(BitWidth - 1);
198 assert(NumRanges >= 1);
201 unsigned MinLeadingZeros = BitWidth;
202 for (
unsigned i = 0; i < NumRanges; ++i) {
206 if (Range.isWrappedSet())
209 MinLeadingZeros = std::min(LeadingZeros, MinLeadingZeros);
231 assert(V &&
"No Value?");
232 assert(Depth <=
MaxDepth &&
"Limit Search Depth");
237 "Not integer or pointer type!");
244 "V, Mask, KnownOne and KnownZero should have same BitWidth");
248 KnownOne = CI->getValue();
249 KnownZero = ~KnownOne;
253 if (isa<ConstantPointerNull>(V) ||
254 isa<ConstantAggregateZero>(V)) {
267 for (
unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) {
268 Elt = CDS->getElementAsInteger(i);
277 unsigned Align = GV->getAlignment();
278 if (Align == 0 && TD) {
280 Type *ObjectType = GVar->getType()->getElementType();
285 if (!GVar->isDeclaration() && !GVar->isWeakForLinker())
303 if (GA->mayBeOverridden()) {
311 if (
Argument *
A = dyn_cast<Argument>(V)) {
314 if (
A->hasByValAttr()) {
316 Align =
A->getParamAlignment();
317 }
else if (TD &&
A->hasStructRetAttr()) {
319 Type *EltTy = cast<PointerType>(
A->getType())->getElementType();
338 APInt KnownZero2(KnownZero), KnownOne2(KnownOne);
349 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
350 assert((KnownZero2 & KnownOne2) == 0 &&
"Bits known to be one AND zero?");
353 KnownOne &= KnownOne2;
355 KnownZero |= KnownZero2;
361 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
362 assert((KnownZero2 & KnownOne2) == 0 &&
"Bits known to be one AND zero?");
365 KnownZero &= KnownZero2;
367 KnownOne |= KnownOne2;
373 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
374 assert((KnownZero2 & KnownOne2) == 0 &&
"Bits known to be one AND zero?");
377 APInt KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2);
379 KnownOne = (KnownZero & KnownOne2) | (KnownOne & KnownZero2);
380 KnownZero = KnownZeroOut;
383 case Instruction::Mul: {
384 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
386 KnownZero, KnownOne, KnownZero2, KnownOne2,
TD, Depth);
389 case Instruction::UDiv: {
394 unsigned LeadZ = KnownZero2.countLeadingOnes();
396 KnownOne2.clearAllBits();
397 KnownZero2.clearAllBits();
399 unsigned RHSUnknownLeadingOnes = KnownOne2.countLeadingZeros();
400 if (RHSUnknownLeadingOnes != BitWidth)
401 LeadZ = std::min(BitWidth,
402 LeadZ + BitWidth - RHSUnknownLeadingOnes - 1);
411 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
412 assert((KnownZero2 & KnownOne2) == 0 &&
"Bits known to be one AND zero?");
415 KnownOne &= KnownOne2;
416 KnownZero &= KnownZero2;
418 case Instruction::FPTrunc:
419 case Instruction::FPExt:
420 case Instruction::FPToUI:
421 case Instruction::FPToSI:
422 case Instruction::SIToFP:
423 case Instruction::UIToFP:
425 case Instruction::PtrToInt:
426 case Instruction::IntToPtr:
430 case Instruction::ZExt:
431 case Instruction::Trunc: {
434 unsigned SrcBitWidth;
441 if (!SrcBitWidth)
return;
444 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
451 if (BitWidth > SrcBitWidth)
455 case Instruction::BitCast: {
466 case Instruction::SExt: {
470 KnownZero = KnownZero.
trunc(SrcBitWidth);
471 KnownOne = KnownOne.
trunc(SrcBitWidth);
473 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
474 KnownZero = KnownZero.
zext(BitWidth);
475 KnownOne = KnownOne.
zext(BitWidth);
479 if (KnownZero[SrcBitWidth-1])
481 else if (KnownOne[SrcBitWidth-1])
485 case Instruction::Shl:
488 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth);
490 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
491 KnownZero <<= ShiftAmt;
492 KnownOne <<= ShiftAmt;
497 case Instruction::LShr:
501 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth);
505 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
513 case Instruction::AShr:
517 uint64_t ShiftAmt = SA->getLimitedValue(BitWidth-1);
521 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
526 if (KnownZero[BitWidth-ShiftAmt-1])
527 KnownZero |= HighBits;
528 else if (KnownOne[BitWidth-ShiftAmt-1])
529 KnownOne |= HighBits;
533 case Instruction::Sub: {
534 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
536 KnownZero, KnownOne, KnownZero2, KnownOne2,
TD,
540 case Instruction::Add: {
541 bool NSW = cast<OverflowingBinaryOperator>(
I)->hasNoSignedWrap();
543 KnownZero, KnownOne, KnownZero2, KnownOne2,
TD,
547 case Instruction::SRem:
551 APInt LowBits = RA - 1;
555 KnownZero = KnownZero2 & LowBits;
556 KnownOne = KnownOne2 & LowBits;
560 if (KnownZero2[BitWidth-1] || ((KnownZero2 & LowBits) == LowBits))
561 KnownZero |= ~LowBits;
565 if (KnownOne2[BitWidth-1] && ((KnownOne2 & LowBits) != 0))
566 KnownOne |= ~LowBits;
568 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
575 APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
579 if (LHSKnownZero.isNegative())
580 KnownZero.
setBit(BitWidth - 1);
584 case Instruction::URem: {
586 APInt RA = Rem->getValue();
588 APInt LowBits = (RA - 1);
591 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
592 KnownZero |= ~LowBits;
604 KnownZero2.countLeadingOnes());
605 KnownOne.clearAllBits();
610 case Instruction::Alloca: {
613 if (Align == 0 && TD)
620 case Instruction::GetElementPtr: {
623 APInt LocalKnownZero(BitWidth, 0), LocalKnownOne(BitWidth, 0);
626 unsigned TrailZ = LocalKnownZero.countTrailingOnes();
629 for (
unsigned i = 1, e = I->
getNumOperands(); i != e; ++i, ++GTI) {
631 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
637 Constant *CIndex = cast<Constant>(Index);
644 unsigned Idx = cast<ConstantInt>(Index)->getZExtValue();
647 TrailZ = std::min<unsigned>(TrailZ,
652 if (!IndexedTy->
isSized())
return;
654 uint64_t TypeSize = TD ? TD->getTypeAllocSize(IndexedTy) : 1;
655 LocalKnownZero = LocalKnownOne =
APInt(GEPOpiBits, 0);
657 TrailZ = std::min(TrailZ,
659 LocalKnownZero.countTrailingOnes()));
672 for (
unsigned i = 0; i != 2; ++i) {
682 if (Opcode == Instruction::Add ||
683 Opcode == Instruction::Sub ||
686 Opcode == Instruction::Mul) {
701 APInt KnownZero3(KnownZero), KnownOne3(KnownOne);
705 std::min(KnownZero2.countTrailingOnes(),
706 KnownZero3.countTrailingOnes()));
718 if (Depth <
MaxDepth - 1 && !KnownZero && !KnownOne) {
729 KnownZero2 =
APInt(BitWidth, 0);
730 KnownOne2 =
APInt(BitWidth, 0);
735 KnownZero &= KnownZero2;
736 KnownOne &= KnownOne2;
739 if (!KnownZero && !KnownOne)
747 switch (II->getIntrinsicID()) {
751 unsigned LowBits =
Log2_32(BitWidth)+1;
759 unsigned LowBits =
Log2_32(BitWidth)+1;
769 case Instruction::ExtractValue:
774 switch (II->getIntrinsicID()) {
779 II->getArgOperand(1),
false, KnownZero,
780 KnownOne, KnownZero2, KnownOne2,
TD, Depth);
785 II->getArgOperand(1),
false, KnownZero,
786 KnownOne, KnownZero2, KnownOne2,
TD, Depth);
791 false, KnownZero, KnownOne,
792 KnownZero2, KnownOne2,
TD, Depth);
810 APInt ZeroBits(BitWidth, 0);
811 APInt OneBits(BitWidth, 0);
813 KnownOne = OneBits[BitWidth - 1];
814 KnownZero = ZeroBits[BitWidth - 1];
822 if (
Constant *
C = dyn_cast<Constant>(V)) {
823 if (
C->isNullValue())
826 return CI->getValue().isPowerOf2();
850 if (
ZExtInst *ZI = dyn_cast<ZExtInst>(V))
883 APInt LHSZeroBits(BitWidth, 0), LHSOneBits(BitWidth, 0);
886 APInt RHSZeroBits(BitWidth, 0), RHSOneBits(BitWidth, 0);
891 if ((~(LHSZeroBits & RHSZeroBits)).isPowerOf2())
939 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
940 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
944 if (ElementOffset > 0)
955 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
981 if (
Constant *
C = dyn_cast<Constant>(V)) {
982 if (
C->isNullValue())
984 if (isa<ConstantInt>(
C))
1012 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
1013 return isKnownNonZero(cast<Instruction>(V)->getOperand(0), TD, Depth);
1023 APInt KnownZero(BitWidth, 0);
1024 APInt KnownOne(BitWidth, 0);
1037 bool XKnownNonNegative, XKnownNegative;
1048 bool XKnownNonNegative, XKnownNegative;
1049 bool YKnownNonNegative, YKnownNegative;
1055 if (XKnownNonNegative && YKnownNonNegative)
1061 if (BitWidth && XKnownNegative && YKnownNegative) {
1062 APInt KnownZero(BitWidth, 0);
1063 APInt KnownOne(BitWidth, 0);
1068 if ((KnownOne & Mask) != 0)
1073 if ((KnownOne & Mask) != 0)
1093 else if (
SelectInst *SI = dyn_cast<SelectInst>(V)) {
1099 if (!BitWidth)
return false;
1100 APInt KnownZero(BitWidth, 0);
1101 APInt KnownOne(BitWidth, 0);
1103 return KnownOne != 0;
1119 assert((KnownZero & KnownOne) == 0 &&
"Bits known to be one AND zero?");
1120 return (KnownZero & Mask) == Mask;
1136 "ComputeNumSignBits requires a DataLayout object to operate "
1137 "on non-integer values!");
1142 unsigned FirstAnswer = 1;
1153 case Instruction::SExt:
1157 case Instruction::AShr: {
1162 Tmp += ShAmt->getZExtValue();
1163 if (Tmp > TyBits) Tmp = TyBits;
1167 case Instruction::Shl: {
1173 if (Tmp2 >= TyBits ||
1186 FirstAnswer = std::min(Tmp, Tmp2);
1195 if (Tmp == 1)
return 1;
1197 return std::min(Tmp, Tmp2);
1199 case Instruction::Add:
1203 if (Tmp == 1)
return 1;
1207 if (CRHS->isAllOnesValue()) {
1208 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
1213 if ((KnownZero |
APInt(TyBits, 1)).isAllOnesValue())
1218 if (KnownZero.isNegative())
1223 if (Tmp2 == 1)
return 1;
1224 return std::min(Tmp, Tmp2)-1;
1226 case Instruction::Sub:
1228 if (Tmp2 == 1)
return 1;
1232 if (CLHS->isNullValue()) {
1233 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
1237 if ((KnownZero |
APInt(TyBits, 1)).isAllOnesValue())
1242 if (KnownZero.isNegative())
1251 if (Tmp == 1)
return 1;
1252 return std::min(Tmp, Tmp2)-1;
1255 PHINode *PN = cast<PHINode>(U);
1263 if (Tmp == 1)
return Tmp;
1270 case Instruction::Trunc:
1278 APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
1282 if (KnownZero.isNegative()) {
1305 bool LookThroughSExt,
unsigned Depth) {
1308 assert(V &&
"No Value?");
1309 assert(Depth <= MaxDepth &&
"Limit Search Depth");
1326 if (CO && CO == BaseVal) {
1337 if (Depth == MaxDepth)
return false;
1340 if (!I)
return false;
1344 case Instruction::SExt:
1345 if (!LookThroughSExt)
return false;
1347 case Instruction::ZExt:
1349 LookThroughSExt, Depth+1);
1350 case Instruction::Shl:
1351 case Instruction::Mul: {
1355 if (I->
getOpcode() == Instruction::Shl) {
1357 if (!Op1CI)
return false;
1368 if (
Constant *Op1C = dyn_cast<Constant>(Op1))
1369 if (
Constant *MulC = dyn_cast<Constant>(Mul0)) {
1370 if (Op1C->getType()->getPrimitiveSizeInBits() <
1371 MulC->getType()->getPrimitiveSizeInBits())
1373 if (Op1C->getType()->getPrimitiveSizeInBits() >
1374 MulC->getType()->getPrimitiveSizeInBits())
1382 if (
ConstantInt *Mul0CI = dyn_cast<ConstantInt>(Mul0))
1383 if (Mul0CI->getValue() == 1) {
1392 if (
Constant *Op0C = dyn_cast<Constant>(Op0))
1393 if (
Constant *MulC = dyn_cast<Constant>(Mul1)) {
1394 if (Op0C->getType()->getPrimitiveSizeInBits() <
1395 MulC->getType()->getPrimitiveSizeInBits())
1397 if (Op0C->getType()->getPrimitiveSizeInBits() >
1398 MulC->getType()->getPrimitiveSizeInBits())
1406 if (
ConstantInt *Mul1CI = dyn_cast<ConstantInt>(Mul1))
1407 if (Mul1CI->getValue() == 1) {
1427 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V))
1428 return !CFP->getValueAPF().isNegZero();
1434 if (I == 0)
return false;
1438 if (FPO->hasNoSignedZeros())
1442 if (I->
getOpcode() == Instruction::FAdd)
1444 if (CFP->isNullValue())
1448 if (isa<SIToFPInst>(I) || isa<UIToFPInst>(
I))
1456 if (
const CallInst *CI = dyn_cast<CallInst>(I))
1457 if (
const Function *
F = CI->getCalledFunction()) {
1458 if (
F->isDeclaration()) {
1460 if (
F->getName() ==
"abs")
return true;
1462 if (
F->getName() ==
"fabs")
return true;
1463 if (
F->getName() ==
"fabsf")
return true;
1464 if (
F->getName() ==
"fabsl")
return true;
1465 if (
F->getName() ==
"sqrt" ||
F->getName() ==
"sqrtf" ||
1466 F->getName() ==
"sqrtl")
1484 if (
Constant *
C = dyn_cast<Constant>(V))
1485 if (
C->isNullValue())
1490 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
1491 if (CFP->getType()->isFloatTy())
1493 if (CFP->getType()->isDoubleTy())
1501 unsigned Width = CI->getBitWidth();
1505 APInt Val = CI->getValue();
1509 Val2 = Val.
lshr(NextWidth);
1524 Value *Elt = CA->getElementAsConstant(0);
1529 for (
unsigned I = 1, E = CA->getNumElements();
I != E; ++
I)
1530 if (CA->getElementAsConstant(
I) != Elt)
1570 while (PrevTo != OrigTo) {
1596 "tmp", InsertBefore);
1613 assert(InsertBefore &&
"Must have someplace to insert!");
1618 unsigned IdxSkip = Idxs.
size();
1633 if (idx_range.
empty())
1637 "Not looking at a struct or array?");
1639 "Invalid indices for type?");
1641 if (
Constant *
C = dyn_cast<Constant>(V)) {
1642 C =
C->getAggregateElement(idx_range[0]);
1643 if (
C == 0)
return 0;
1650 const unsigned *req_idx = idx_range.
begin();
1651 for (
const unsigned *i =
I->idx_begin(), *e =
I->idx_end();
1652 i != e; ++i, ++req_idx) {
1653 if (req_idx == idx_range.
end()) {
1693 unsigned size =
I->getNumIndices() + idx_range.
size();
1698 Idxs.
append(
I->idx_begin(),
I->idx_end());
1703 assert(Idxs.
size() == size
1704 &&
"Number of indices added not correct?");
1721 APInt ByteOffset(BitWidth, 0);
1726 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(Ptr)) {
1728 APInt GEPOffset(BitWidth, 0);
1729 if (!GEP->accumulateConstantOffset(*DL, GEPOffset))
1732 ByteOffset += GEPOffset;
1735 Ptr = GEP->getPointerOperand();
1737 Ptr = cast<Operator>(Ptr)->getOperand(0);
1738 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(Ptr)) {
1739 if (GA->mayBeOverridden())
1741 Ptr = GA->getAliasee();
1755 uint64_t Offset,
bool TrimAtNul) {
1763 if (
const GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
1765 if (GEP->getNumOperands() != 3)
1769 PointerType *PT = cast<PointerType>(GEP->getOperand(0)->getType());
1771 if (AT == 0 || !AT->getElementType()->isIntegerTy(8))
1777 if (FirstIdx == 0 || !FirstIdx->
isZero())
1783 uint64_t StartIdx = 0;
1784 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(2)))
1809 if (Array == 0 || !Array->
isString())
1818 if (Offset > NumElts)
1822 Str = Str.
substr(Offset);
1845 if (
PHINode *PN = dyn_cast<PHINode>(V)) {
1850 uint64_t LenSoFar = ~0ULL;
1851 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
1853 if (Len == 0)
return 0;
1855 if (Len == ~0ULL)
continue;
1857 if (Len != LenSoFar && LenSoFar != ~0ULL)
1867 if (
SelectInst *SI = dyn_cast<SelectInst>(V)) {
1869 if (Len1 == 0)
return 0;
1871 if (Len2 == 0)
return 0;
1872 if (Len1 == ~0ULL)
return Len2;
1873 if (Len2 == ~0ULL)
return Len1;
1874 if (Len1 != Len2)
return 0;
1883 return StrData.
size()+1;
1895 return Len == ~0ULL ? 1 : Len;
1902 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
1903 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
1904 V = GEP->getPointerOperand();
1906 V = cast<Operator>(V)->getOperand(0);
1907 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1908 if (GA->mayBeOverridden())
1910 V = GA->getAliasee();
1931 unsigned MaxLookup) {
1942 if (
SelectInst *SI = dyn_cast<SelectInst>(P)) {
1944 Worklist.
push_back(SI->getFalseValue());
1948 if (
PHINode *PN = dyn_cast<PHINode>(P)) {
1949 for (
unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
1950 Worklist.
push_back(PN->getIncomingValue(i));
1955 }
while (!Worklist.
empty());
1965 if (!II)
return false;
1988 case Instruction::UDiv:
1989 case Instruction::URem:
1992 case Instruction::SDiv:
1993 case Instruction::SRem: {
2002 APInt KnownZero(BitWidth, 0);
2003 APInt KnownOne(BitWidth, 0);
2014 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) {
2015 switch (II->getIntrinsicID()) {
2046 case Instruction::VAArg:
2047 case Instruction::Alloca:
2048 case Instruction::Invoke:
2052 case Instruction::Br:
2053 case Instruction::IndirectBr:
2054 case Instruction::Switch:
2055 case Instruction::Unreachable:
2056 case Instruction::Fence:
2057 case Instruction::LandingPad:
2058 case Instruction::AtomicRMW:
2059 case Instruction::AtomicCmpXchg:
2060 case Instruction::Resume:
2069 if (isa<AllocaInst>(V))
return true;
2072 if (
const Argument *
A = dyn_cast<Argument>(V))
2073 return A->hasByValAttr();
2076 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
2077 return !GV->hasExternalWeakLinkage();
void clearAllBits()
Set every bit to 0.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
void push_back(const T &Elt)
Type * getIndexedType() const
class_match< Value > m_Value()
m_Value() - Match an arbitrary value and ignore it.
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
cst_pred_ty< is_sign_bit > m_SignBit()
m_SignBit() - Match an integer or vector with only the sign bit(s) set.
uint64_t GetStringLength(Value *V)
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.
void GetUnderlyingObjects(Value *V, SmallVectorImpl< Value * > &Objects, const DataLayout *TD=0, unsigned MaxLookup=6)
size_t size() const
size - Get the string size.
Value * isBytewiseValue(Value *V)
unsigned getScalarSizeInBits()
Intrinsic::ID getIntrinsicID() const
Constant * getSplatValue() const
void setBit(unsigned bitPosition)
Set a given bit to 1.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
This class represents zero extension of integer types.
unsigned getNumOperands() const
unsigned getNumOperands() const
getNumOperands - Return number of MDNode operands.
bool hasNoSignedWrap() const
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout *TD=0, unsigned Depth=0)
unsigned getPointerTypeSizeInBits(Type *) const
size_t find(char C, size_t From=0) const
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout *TD)
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
gep_type_iterator gep_type_end(const User *GEP)
bool isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI=0)
StringRef substr(size_t Start, size_t N=npos) const
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
void setAllBits()
Set every bit to 1.
MDNode - a tuple of other values.
static IntegerType * getInt64Ty(LLVMContext &C)
const Constant * getInitializer() const
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
LoopInfoBase< BlockT, LoopT > * LI
static Constant * getNullValue(Type *Ty)
Value * getOperand(unsigned i) const LLVM_READONLY
getOperand - Return specified operand.
ArrayType * getType() const
bool isNegative() const
Determine sign of this APInt.
bool match(Val *V, const Pattern &P)
Value * GetUnderlyingObject(Value *V, const DataLayout *TD=0, unsigned MaxLookup=6)
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
Value * FindInsertedValue(Value *V, ArrayRef< unsigned > idx_range, Instruction *InsertBefore=0)
const StructLayout * getStructLayout(StructType *Ty) const
const APInt & getValue() const
Return the constant's value.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Exact_match< T > m_Exact(const T &SubPattern)
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
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)
m_Shr - Matches LShr or AShr.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type 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...
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 zero extended value.
void computeMaskedBitsLoad(const MDNode &Ranges, APInt &KnownZero)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
enable_if_c< std::numeric_limits< T >::is_integer &&!std::numeric_limits< T >::is_signed, std::size_t >::type 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...
bool hasDefinitiveInitializer() const
Type * getElementType() const
size_t size() const
size - Get the array size.
void ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout *TD=0, unsigned Depth=0)
unsigned getNumIncomingValues() const
uint64_t getElementOffset(unsigned Idx) const
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
static void ComputeMaskedBitsAddSub(bool Add, Value *Op0, Value *Op1, bool NSW, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, const DataLayout *TD, unsigned Depth)
bool isIntOrIntVectorTy() const
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
Value * hasConstantValue() const
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
Type * getElementType(unsigned N) const
LLVM Constant Representation.
PointerType * getType() const
int64_t getSExtValue() const
Get sign extended value.
StringRef getAsString() const
bool onlyUsedByLifetimeMarkers(const Value *V)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
unsigned getAlignment() const
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
bool isZeroValue() const
Return true if the value is negative zero or null value.
specificval_ty m_Specific(const Value *V)
m_Specific - Match if we have a specific specified value.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * getPointerOperand()
Value * getOperand(unsigned i) const
Value * getPointerOperand()
bool empty() const
empty - Check if the array is empty.
void append(in_iter in_start, in_iter in_end)
static UndefValue * get(Type *T)
Value * SimplifyInstruction(Instruction *I, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
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)
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
unsigned getPreferredAlignment(const GlobalVariable *GV) const
neg_match< LHS > m_Neg(const LHS &L)
m_Neg - Match an integer negate.
bool isSafeToSpeculativelyExecute(const Value *V, const DataLayout *TD=0)
unsigned getABITypeAlignment(Type *Ty) const
static Constant * getBitCast(Constant *C, Type *Ty)
static ManagedStatic< LeakDetectorImpl< void > > Objects
Class for constant integers.
Value * getIncomingValue(unsigned i) const
uint64_t getTypeAllocSize(Type *Ty) const
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isKnownToBeAPowerOfTwo(Value *V, bool OrZero=false, unsigned Depth=0)
Value * stripPointerCasts()
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
static ConstantInt * getTrue(LLVMContext &Context)
unsigned Log2_32(uint32_t Value)
Class for arbitrary precision integers.
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
unsigned getOpcode() const
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, const DataLayout *TD=0, unsigned Depth=0)
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=0)
bool isDereferenceablePointer() const
unsigned countLeadingOnes() const
Count the number of leading one bits.
static IntegerType * getInt32Ty(LLVMContext &C)
static Constant * getZExt(Constant *C, Type *Ty)
bool ComputeMultiple(Value *V, unsigned Base, Value *&Multiple, bool LookThroughSExt=false, unsigned Depth=0)
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.
unsigned getPointerAddressSpace() const
const Type * getScalarType() const
uint64_t getArrayNumElements() const
unsigned ComputeNumSignBits(Value *Op, const DataLayout *TD=0, unsigned Depth=0)
bool getConstantStringInfo(const Value *V, StringRef &Str, uint64_t Offset=0, bool TrimAtNul=true)
BinOp2_match< LHS, RHS, Instruction::SDiv, Instruction::UDiv > m_IDiv(const LHS &L, const RHS &R)
m_IDiv - Matches UDiv and SDiv.
static uint64_t GetStringLengthH(Value *V, SmallPtrSet< PHINode *, 32 > &PHIs)
bool CannotBeNegativeZero(const Value *V, unsigned Depth=0)
static bool isGEPKnownNonNull(GEPOperator *GEP, const DataLayout *DL, unsigned Depth)
Test whether a GEP's result is known to be non-null.
LLVM Value Representation.
cst_pred_ty< is_one > m_One()
m_One() - Match an integer 1 or a vector with all elements equal to 1.
bool isKnownNonZero(Value *V, const DataLayout *TD=0, unsigned Depth=0)
uint64_t getTypeSizeInBits(Type *Ty) const
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool isPowerOf2_32(uint32_t Value)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
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.
static IntegerType * getInt8Ty(LLVMContext &C)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
bool hasNoUnsignedWrap() const
static void ComputeMaskedBitsMul(Value *Op0, Value *Op1, bool NSW, APInt &KnownZero, APInt &KnownOne, APInt &KnownZero2, APInt &KnownOne2, const DataLayout *TD, unsigned Depth)
gep_type_iterator gep_type_begin(const User *GEP)