61 for (
unsigned i = 0; i != NumElts; ++i) {
81 assert(Op && Op->
isCast() &&
"Can't fold cast of cast without a cast!");
98 nullptr, FakeIntPtrTy,
nullptr);
109 if (
PointerType *DPTy = dyn_cast<PointerType>(DestTy))
110 if (PTy->getAddressSpace() == DPTy->getAddressSpace()
111 && PTy->getElementType()->isSized()) {
116 Type *ElTy = PTy->getElementType();
117 while (ElTy != DPTy->getElementType()) {
118 if (
StructType *STy = dyn_cast<StructType>(ElTy)) {
119 if (STy->getNumElements() == 0)
break;
120 ElTy = STy->getElementType(0);
123 dyn_cast<SequentialType>(ElTy)) {
124 ElTy = STy->getElementType();
131 if (ElTy == DPTy->getElementType())
139 if (
VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
141 assert(DestPTy->getBitWidth() == SrcTy->getBitWidth() &&
142 "Not cast between same sized vectors!");
145 if (isa<ConstantAggregateZero>(V))
155 if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
161 if (isa<ConstantPointerNull>(V))
189 if (
FP->getType()->isPPC_FP128Ty())
197 FP->getValueAPF().bitcastToAPInt());
216 "Non-byte sized integer input");
218 assert(ByteSize &&
"Must be accessing some piece");
219 assert(ByteStart+ByteSize <= CSize &&
"Extracting invalid piece from input");
220 assert(ByteSize != CSize &&
"Should not extract everything");
224 APInt V = CI->getValue();
227 V = V.
trunc(ByteSize*8);
234 if (!CE)
return nullptr;
236 switch (CE->getOpcode()) {
237 default:
return nullptr;
238 case Instruction::Or: {
244 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS))
245 if (RHSC->isMinusOne())
253 case Instruction::And: {
267 case Instruction::LShr: {
273 if ((ShAmt & 7) != 0)
278 if (ByteStart >= CSize-ShAmt)
282 if (ByteStart+ByteSize+ShAmt <= CSize)
289 case Instruction::Shl: {
295 if ((ShAmt & 7) != 0)
300 if (ByteStart+ByteSize <= ShAmt)
304 if (ByteStart >= ShAmt)
311 case Instruction::ZExt: {
312 unsigned SrcBitSize =
313 cast<IntegerType>(CE->getOperand(0)->getType())->
getBitWidth();
316 if (ByteStart*8 >= SrcBitSize)
321 if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
322 return CE->getOperand(0);
326 if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize)
331 if ((ByteStart+ByteSize)*8 < SrcBitSize) {
332 assert((SrcBitSize&7) &&
"Shouldn't get byte sized case here");
352 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
358 if (
StructType *STy = dyn_cast<StructType>(Ty))
359 if (!STy->isPacked()) {
360 unsigned NumElems = STy->getNumElements();
368 for (
unsigned i = 1; i != NumElems; ++i)
383 if (!PTy->getElementType()->isIntegerTy(1))
386 PTy->getAddressSpace()),
409 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
418 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
426 unsigned NumElems = STy->getNumElements();
434 for (
unsigned i = 1; i != NumElems; ++i)
435 if (MemberAlign !=
getFoldedAlignOf(STy->getElementType(i), DestTy,
true)) {
446 if (!PTy->getElementType()->isIntegerTy(1))
450 PTy->getAddressSpace()),
472 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
480 if (
StructType *STy = dyn_cast<StructType>(Ty))
481 if (!STy->isPacked()) {
482 unsigned NumElems = STy->getNumElements();
490 for (
unsigned i = 1; i != NumElems; ++i)
521 if (isa<UndefValue>(V)) {
525 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
526 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
532 opc != Instruction::AddrSpaceCast)
542 }
else if (CE->getOpcode() == Instruction::GetElementPtr &&
545 opc != Instruction::AddrSpaceCast &&
548 !cast<GEPOperator>(CE)->getInRangeIndex().hasValue() &&
552 !CE->getType()->isVectorTy()) {
555 bool isAllNull =
true;
556 for (
unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
557 if (!CE->getOperand(i)->isNullValue()) {
570 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
574 VectorType *DestVecTy = cast<VectorType>(DestTy);
590 case Instruction::FPTrunc:
591 case Instruction::FPExt:
592 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
594 APFloat Val = FPC->getValueAPF();
606 case Instruction::FPToUI:
607 case Instruction::FPToSI:
608 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
609 const APFloat &V = FPC->getValueAPF();
612 APSInt IntVal(DestBitWidth, opc == Instruction::FPToUI);
622 case Instruction::IntToPtr:
626 case Instruction::PtrToInt:
634 if (CE->getOpcode() == Instruction::GetElementPtr &&
635 CE->getOperand(0)->isNullValue()) {
647 if (CE->getNumOperands() == 2) {
650 bool isOne = isa<ConstantInt>(Idx) && cast<ConstantInt>(Idx)->isOne();
657 }
else if (CE->getNumOperands() == 3 &&
658 CE->getOperand(1)->isNullValue()) {
660 if (
StructType *STy = dyn_cast<StructType>(Ty))
661 if (!STy->isPacked()) {
662 ConstantInt *CI = cast<ConstantInt>(CE->getOperand(2));
664 STy->getNumElements() == 2 &&
665 STy->getElementType(0)->isIntegerTy(1)) {
670 if (Ty->isStructTy() || Ty->isArrayTy()) {
679 case Instruction::UIToFP:
680 case Instruction::SIToFP:
682 const APInt &api = CI->getValue();
690 case Instruction::ZExt:
694 CI->getValue().zext(BitWidth));
697 case Instruction::SExt:
701 CI->getValue().sext(BitWidth));
704 case Instruction::Trunc: {
711 CI->getValue().trunc(DestBitWidth));
717 if ((DestBitWidth & 7) == 0 &&
724 case Instruction::BitCast:
726 case Instruction::AddrSpaceCast:
748 if (V1Element == V2Element) {
750 }
else if (isa<UndefValue>(Cond)) {
751 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
753 if (!isa<ConstantInt>(Cond))
break;
764 if (isa<UndefValue>(Cond)) {
765 if (isa<UndefValue>(V1))
return V1;
768 if (isa<UndefValue>(V1))
return V2;
769 if (isa<UndefValue>(V2))
return V1;
770 if (V1 == V2)
return V1;
772 if (
ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) {
774 if (TrueVal->getOperand(0) == Cond)
777 if (
ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) {
779 if (FalseVal->getOperand(0) == Cond)
788 if (isa<UndefValue>(Val))
793 if (isa<UndefValue>(Idx))
796 if (
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
808 if (isa<UndefValue>(Idx))
812 if (!CIdx)
return nullptr;
815 if (CIdx->uge(NumElts))
821 uint64_t IdxVal = CIdx->getZExtValue();
822 for (
unsigned i = 0; i != NumElts; ++i) {
842 if (isa<UndefValue>(Mask))
846 if (isa<ConstantExpr>(Mask))
return nullptr;
852 for (
unsigned i = 0; i != MaskNumElts; ++i) {
859 if (
unsigned(Elt) >= SrcNumElts*2)
861 else if (
unsigned(Elt) >= SrcNumElts) {
897 NumElts =
ST->getNumElements();
899 NumElts = cast<SequentialType>(Agg->
getType())->getNumElements();
902 for (
unsigned i = 0; i != NumElts; ++i) {
904 if (!C)
return nullptr;
925 (isa<UndefValue>(C1) || isa<UndefValue>(C2));
926 if (HasScalarUndef) {
927 switch (static_cast<Instruction::BinaryOps>(Opcode)) {
928 case Instruction::Xor:
929 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
935 case Instruction::Sub:
937 case Instruction::And:
938 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
941 case Instruction::Mul: {
943 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
954 case Instruction::SDiv:
955 case Instruction::UDiv:
957 if (isa<UndefValue>(C2))
965 case Instruction::URem:
966 case Instruction::SRem:
975 case Instruction::Or:
976 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
979 case Instruction::LShr:
981 if (isa<UndefValue>(C2))
988 case Instruction::AShr:
990 if (isa<UndefValue>(C2))
998 case Instruction::Shl:
1000 if (isa<UndefValue>(C2))
1007 case Instruction::FAdd:
1008 case Instruction::FSub:
1009 case Instruction::FMul:
1010 case Instruction::FDiv:
1011 case Instruction::FRem:
1013 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
1023 case Instruction::BinaryOpsEnd:
1029 assert(!HasScalarUndef &&
"Unexpected UndefValue");
1032 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1035 if (CI2->isZero())
return C1;
1037 case Instruction::Sub:
1038 if (CI2->isZero())
return C1;
1040 case Instruction::Mul:
1041 if (CI2->isZero())
return C2;
1045 case Instruction::UDiv:
1046 case Instruction::SDiv:
1052 case Instruction::URem:
1053 case Instruction::SRem:
1059 case Instruction::And:
1060 if (CI2->isZero())
return C2;
1061 if (CI2->isMinusOne())
1066 if (CE1->getOpcode() == Instruction::ZExt) {
1067 unsigned DstWidth = CI2->
getType()->getBitWidth();
1071 if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
1076 if (CE1->getOpcode() == Instruction::PtrToInt &&
1077 isa<GlobalValue>(CE1->getOperand(0))) {
1078 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
1082 if (isa<Function>(GV))
1086 unsigned DstWidth = CI2->getType()->getBitWidth();
1087 unsigned SrcWidth = std::min(DstWidth,
Log2_32(GVAlign));
1091 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
1097 case Instruction::Or:
1098 if (CI2->isZero())
return C1;
1099 if (CI2->isMinusOne())
1102 case Instruction::Xor:
1103 if (CI2->isZero())
return C1;
1106 switch (CE1->getOpcode()) {
1108 case Instruction::ICmp:
1109 case Instruction::FCmp:
1115 CE1->getOperand(1));
1119 case Instruction::AShr:
1122 if (CE1->getOpcode() == Instruction::ZExt)
1126 }
else if (isa<ConstantInt>(C1)) {
1132 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
1133 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1134 const APInt &C1V = CI1->getValue();
1135 const APInt &C2V = CI2->getValue();
1141 case Instruction::Sub:
1143 case Instruction::Mul:
1145 case Instruction::UDiv:
1146 assert(!CI2->isZero() &&
"Div by zero handled above");
1148 case Instruction::SDiv:
1149 assert(!CI2->isZero() &&
"Div by zero handled above");
1153 case Instruction::URem:
1154 assert(!CI2->isZero() &&
"Div by zero handled above");
1156 case Instruction::SRem:
1157 assert(!CI2->isZero() &&
"Div by zero handled above");
1161 case Instruction::And:
1163 case Instruction::Or:
1165 case Instruction::Xor:
1167 case Instruction::Shl:
1171 case Instruction::LShr:
1175 case Instruction::AShr:
1183 case Instruction::SDiv:
1184 case Instruction::UDiv:
1185 case Instruction::URem:
1186 case Instruction::SRem:
1187 case Instruction::LShr:
1188 case Instruction::AShr:
1189 case Instruction::Shl:
1190 if (CI1->isZero())
return C1;
1195 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
1196 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
1197 const APFloat &C1V = CFP1->getValueAPF();
1198 const APFloat &C2V = CFP2->getValueAPF();
1203 case Instruction::FAdd:
1206 case Instruction::FSub:
1209 case Instruction::FMul:
1212 case Instruction::FDiv:
1215 case Instruction::FRem:
1224 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
1248 if (!isa<ConstantExpr>(T) || cast<ConstantExpr>(
T)->
getOpcode() != Opcode)
1251 }
else if (isa<ConstantExpr>(C2)) {
1262 case Instruction::Sub:
1264 case Instruction::Mul:
1266 case Instruction::Shl:
1267 case Instruction::LShr:
1268 case Instruction::AShr:
1272 case Instruction::SDiv:
1273 case Instruction::UDiv:
1277 case Instruction::URem:
1278 case Instruction::SRem:
1294 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
1295 if (STy->isOpaque())
return true;
1298 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
1302 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
1316 if (C1 == C2)
return 0;
1320 if (!isa<ConstantInt>(C1) || !isa<ConstantInt>(C2))
1324 if (cast<ConstantInt>(C1)->getValue().getActiveBits() > 64 ||
1325 cast<ConstantInt>(C2)->getValue().getActiveBits() > 64)
1330 int64_t C1Val = cast<ConstantInt>(C1)->getSExtValue();
1331 int64_t C2Val = cast<ConstantInt>(C2)->getSExtValue();
1333 if (C1Val == C2Val)
return 0;
1361 "Cannot compare values of different types!");
1366 if (!isa<ConstantExpr>(V1)) {
1367 if (!isa<ConstantExpr>(V2)) {
1396 case Instruction::FPTrunc:
1397 case Instruction::FPExt:
1398 case Instruction::UIToFP:
1399 case Instruction::SIToFP:
1413 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
1414 if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage())
1416 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
1417 Type *Ty = GVar->getValueType();
1429 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
1430 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
1450 "Cannot compare different types of values!");
1453 if (!isa<ConstantExpr>(V1) && !isa<GlobalValue>(V1) &&
1454 !isa<BlockAddress>(V1)) {
1455 if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(
V2) &&
1456 !isa<BlockAddress>(V2)) {
1483 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1484 if (isa<ConstantExpr>(V2)) {
1495 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1497 }
else if (isa<BlockAddress>(V2)) {
1500 assert(isa<ConstantPointerNull>(V2) &&
"Canonicalization guarantee!");
1506 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV) &&
1508 GV->getType()->getAddressSpace()))
1511 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1512 if (isa<ConstantExpr>(V2)) {
1523 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1527 if (BA2->getFunction() != BA->getFunction())
1531 assert((isa<ConstantPointerNull>(V2) || isa<GlobalValue>(V2)) &&
1532 "Canonicalization guarantee!");
1542 case Instruction::Trunc:
1543 case Instruction::FPTrunc:
1544 case Instruction::FPExt:
1545 case Instruction::FPToUI:
1546 case Instruction::FPToSI:
1549 case Instruction::UIToFP:
1550 case Instruction::SIToFP:
1551 case Instruction::BitCast:
1552 case Instruction::ZExt:
1553 case Instruction::SExt:
1555 if (CE1Op0->getType()->isFloatingPointTy())
1561 if (CE1->
getOpcode() == Instruction::ZExt) isSigned =
false;
1562 if (CE1->
getOpcode() == Instruction::SExt) isSigned =
true;
1569 case Instruction::GetElementPtr: {
1573 if (isa<ConstantPointerNull>(V2)) {
1576 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1577 if (GV->hasExternalWeakLinkage())
1585 }
else if (isa<ConstantPointerNull>(CE1Op0)) {
1596 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1597 if (isa<ConstantPointerNull>(CE1Op0)) {
1598 if (GV2->hasExternalWeakLinkage())
1606 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1614 "Surprising getelementptr!");
1630 case Instruction::GetElementPtr:
1633 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1635 if (CE1Op0 != CE2Op0) {
1639 cast<GlobalValue>(CE2Op0));
1702 VT->getNumElements());
1714 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1725 if (isIntegerPredicate)
1735 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
1737 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage() &&
1739 GV->getType()->getAddressSpace())) {
1747 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
1749 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage() &&
1751 GV->getType()->getAddressSpace())) {
1763 if (isa<ConstantInt>(C2))
1773 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1774 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1775 const APInt &
V2 = cast<ConstantInt>(C2)->getValue();
1789 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1790 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1791 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1853 (isa<ConstantExpr>(C1) || isa<ConstantExpr>(C2))) {
1987 if (CE2->getOpcode() == Instruction::BitCast &&
1996 if ((CE1->getOpcode() == Instruction::SExt &&
1998 (CE1->getOpcode() == Instruction::ZExt &&
2002 if (CE1Inverse == CE1Op0) {
2012 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
2025 template<
typename IndexTy>
2028 if (Idxs.
empty())
return true;
2031 if (cast<Constant>(Idxs[0])->isNullValue())
return true;
2035 if (
auto *CI = dyn_cast<ConstantInt>(Idxs[0])) {
2039 auto *CV = cast<ConstantDataVector>(Idxs[0]);
2040 CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue());
2041 if (!CI || !CI->isOne())
2045 for (
unsigned i = 1, e = Idxs.
size(); i != e; ++i)
2046 if (!cast<Constant>(Idxs[i])->isNullValue())
2061 if (IndexVal < 0 || (NumElements > 0 && (uint64_t)IndexVal >= NumElements))
2072 if (Idxs.
empty())
return C;
2077 if (isa<UndefValue>(C))
2080 Constant *Idx0 = cast<Constant>(Idxs[0]);
2081 if (Idxs.
size() == 1 && (Idx0->
isNullValue() || isa<UndefValue>(Idx0)))
2084 cast<VectorType>(GEPTy)->getNumElements(), C)
2089 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2090 if (!isa<UndefValue>(Idxs[i]) &&
2091 !cast<Constant>(Idxs[i])->isNullValue()) {
2099 assert(Ty &&
"Invalid indices for GEP!");
2107 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i) {
2108 if (
auto *VT = dyn_cast<VectorType>(Idxs[i]->
getType())) {
2123 if (CE->getOpcode() == Instruction::GetElementPtr) {
2148 bool PerformFold =
false;
2152 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idx0))
2156 !CE->getOperand(CE->getNumOperands() - 1)
2162 NewIndices.
reserve(Idxs.
size() + CE->getNumOperands());
2163 NewIndices.
append(CE->op_begin() + 1, CE->op_end() - 1);
2167 Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
2171 if (IdxTy != Idx0->
getType()) {
2172 unsigned CommonExtendedWidth =
2175 CommonExtendedWidth =
std::max(CommonExtendedWidth, 64U);
2195 if (IRIndex && *IRIndex == CE->getNumOperands() - 2 && !Idx0->
isNullValue())
2199 cast<GEPOperator>(CE)->getSourceElementType(), CE->getOperand(0),
2200 NewIndices, InBounds && cast<GEPOperator>(CE)->isInBounds(),
2218 if (SrcPtrTy && DstPtrTy) {
2223 if (SrcArrayTy && DstArrayTy
2228 Idxs, InBounds, InRangeIndex);
2237 Type *Ty = PointeeTy;
2240 !isa<ConstantInt>(Idxs[0]) && !isa<ConstantDataVector>(Idxs[0]);
2241 for (
unsigned i = 1, e = Idxs.
size(); i != e;
2242 Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
2243 if (!isa<ConstantInt>(Idxs[i]) && !isa<ConstantDataVector>(Idxs[i])) {
2248 if (!isa<ConstantInt>(Idxs[i - 1]) && !isa<ConstantDataVector>(Idxs[i - 1]))
2251 if (InRangeIndex && i == *InRangeIndex + 1) {
2257 if (isa<StructType>(Ty)) {
2261 auto *STy = cast<SequentialType>(Ty);
2262 if (isa<VectorType>(STy)) {
2267 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
2271 if (CI->getSExtValue() < 0) {
2277 auto *CV = cast<ConstantDataVector>(Idxs[i]);
2279 for (
unsigned I = 0,
E = CV->getNumElements();
I !=
E; ++
I) {
2280 auto *CI = cast<ConstantInt>(CV->getElementAsConstant(
I));
2282 if (CI->getSExtValue() < 0) {
2287 if (InRange || Unknown)
2292 if (isa<StructType>(Prev)) {
2302 uint64_t NumElements = STy->getArrayNumElements();
2306 Constant *CurrIdx = cast<Constant>(Idxs[i]);
2308 NewIdxs[i - 1] ? NewIdxs[i - 1] : cast<Constant>(Idxs[i - 1]);
2310 bool IsPrevIdxVector = PrevIdx->getType()->isVectorTy();
2311 bool UseVector = IsCurrIdxVector || IsPrevIdxVector;
2313 if (!IsCurrIdxVector && IsPrevIdxVector)
2315 PrevIdx->getType()->getVectorNumElements(), CurrIdx);
2317 if (!IsPrevIdxVector && IsCurrIdxVector)
2325 IsPrevIdxVector ? PrevIdx->getType()->getVectorNumElements()
2333 unsigned CommonExtendedWidth =
2334 std::max(PrevIdx->getType()->getScalarSizeInBits(),
2336 CommonExtendedWidth =
std::max(CommonExtendedWidth, 64U);
2343 ExtendedTy, IsPrevIdxVector
2344 ? PrevIdx->getType()->getVectorNumElements()
2347 if (!PrevIdx->getType()->isIntOrIntVectorTy(CommonExtendedWidth))
2357 if (!NewIdxs.
empty()) {
2358 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2359 if (!NewIdxs[i]) NewIdxs[i] = cast<Constant>(Idxs[i]);
2366 if (!Unknown && !InBounds)
2367 if (
auto *GV = dyn_cast<GlobalVariable>(C))
2370 true, InRangeIndex);
bool isBoundedSequential() const
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
Type * getVectorElementType() const
static const fltSemantics & IEEEquad() LLVM_READNONE
static Constant * FoldBitCast(Constant *V, Type *DestTy)
static ConstantInt * getFalse(LLVMContext &Context)
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
static IntegerType * getInt1Ty(LLVMContext &C)
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
This class represents lattice values for constants.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
void push_back(const T &Elt)
bool isFP128Ty() const
Return true if this is 'fp128'.
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices...
bool slt(const APInt &RHS) const
Signed less than comparison.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static Constant * getFoldedOffsetOf(Type *Ty, Constant *FieldNo, Type *DestTy, bool Folded)
Return a ConstantExpr with type DestTy for offsetof on Ty and FieldNo, with any known factors factore...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
gep_type_iterator gep_type_end(const User *GEP)
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
0 1 0 0 True if ordered and less than
LLVMContext & getContext() const
All values hold a context through their type.
1 1 1 0 True if unordered or not equal
bool sgt(const APInt &RHS) const
Signed greather than comparison.
APInt trunc(unsigned width) const
Truncate to new width.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
bool isVectorTy() const
True if this is an instance of VectorType.
static Constant * getFoldedAlignOf(Type *Ty, Type *DestTy, bool Folded)
Return a ConstantExpr with type DestTy for alignof on Ty, with any known factors factored out...
void reserve(size_type N)
bool sle(const APInt &RHS) const
Signed less or equal comparison.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
static Constant * get(ArrayType *T, ArrayRef< Constant *> V)
unsigned getBitWidth() const
Return the number of bits in the APInt.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
1 0 0 1 True if unordered or equal
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
opStatus divide(const APFloat &RHS, roundingMode RM)
The address of a basic block.
bool match(Val *V, const Pattern &P)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
APInt shl(unsigned shiftAmt) const
Left-shift function.
Class to represent struct types.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, bool isSigned)
This function determines if there is anything we can decide about the two constants provided...
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
static Constant * BitCastConstantVector(Constant *CV, VectorType *DstTy)
Convert the specified vector Constant node to the specified vector type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
0 1 0 1 True if ordered and less than or equal
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
uint64_t getNumElements() const
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
A constant value that is initialized with an expression using other constant values.
static unsigned foldConstantCastPair(unsigned opc, ConstantExpr *Op, Type *DstTy)
This function determines which opcode to use to fold two constant cast expressions together...
Type * getType() const
All values are typed, get the type of this value.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
static int IdxCompare(Constant *C1, Constant *C2, Type *ElTy)
Compare the two constants as though they were getelementptr indices.
Class to represent array types.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
const APInt & getValue() const
Return the constant as an APInt value reference.
bool isGEPWithNoNotionalOverIndexing() const
Return true if this is a getelementptr expression and all the index operands are compile-time known i...
opStatus subtract(const APFloat &RHS, roundingMode RM)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static const fltSemantics & IEEEdouble() LLVM_READNONE
unsigned getAlignment() const
Value * getOperand(unsigned i) const
Class to represent pointers.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, const GlobalValue *GV2)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and indices...
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
bool isAllOnesValue() const
Determine if all bits are set.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
The instances of the Type class are immutable: once they are created, they are never changed...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
static Constant * getFoldedSizeOf(Type *Ty, Type *DestTy, bool Folded)
Return a ConstantExpr with type DestTy for sizeof on Ty, with any known factors factored out...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Constant * getAnd(Constant *C1, Constant *C2)
ConstantFP - Floating Point Values [float, double].
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
bool isMinSignedValue() const
Determine if this is the smallest signed value.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
opStatus multiply(const APFloat &RHS, roundingMode RM)
static Constant * get(StructType *T, ArrayRef< Constant *> V)
0 1 1 1 True if ordered (no nans)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
bool isX86_MMXTy() const
Return true if this is X86 MMX.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
Class to represent integer types.
Constant Vector Declarations.
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static Constant * getNot(Constant *C)
static Constant * getAllOnesValue(Type *Ty)
1 1 1 1 Always true (always folded)
Type * getIndexedType() const
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static wasm::ValType getType(const TargetRegisterClass *RC)
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
static int getMaskValue(const Constant *Mask, unsigned Elt)
Return the shuffle mask value for the specified element of the mask.
1 1 0 1 True if unordered, less than, or equal
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
This is the superclass of the array and vector type classes.
0 0 1 0 True if ordered and greater than
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static const fltSemantics & IEEEsingle() LLVM_READNONE
static Constant * ExtractConstantBytes(Constant *C, unsigned ByteStart, unsigned ByteSize)
V is an integer constant which only has a subset of its bytes used.
unsigned getNumOperands() const
static bool isIndexInRangeOfArrayType(uint64_t NumElements, const ConstantInt *CI)
Test whether a given ConstantInt is in-range for a SequentialType.
This is the shared class of boolean and integer constants.
static const fltSemantics & IEEEhalf() LLVM_READNONE
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
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...
static Constant * getNUWMul(Constant *C1, Constant *C2)
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine how a pair of casts can be eliminated, if they can be at all.
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.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
static bool isMaybeZeroSizedType(Type *Ty)
This type is zero-sized if it's an array or structure of zero-sized types.
static ConstantInt * getTrue(LLVMContext &Context)
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
bool isCommutative() const
Return true if the instruction is commutative:
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
unsigned getVectorNumElements() const
bool isIntPredicate() const
bool isTrueWhenEqual() const
This is just a convenience.
Class to represent vector types.
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
opStatus mod(const APFloat &RHS)
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...
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isSequential() const
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Constant * ConstantFoldCompareInstruction(unsigned short predicate, Constant *C1, Constant *C2)
opStatus add(const APFloat &RHS, roundingMode RM)
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
static Type * getIndexedType(Type *Ty, ArrayRef< Value *> IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned getIntegerBitWidth() const
uint64_t getSequentialNumElements() const
LLVM_NODISCARD bool empty() const
static Constant * getOffsetOf(StructType *STy, unsigned FieldNo)
getOffsetOf constant expr - computes the offset of a struct field in a target independent way (Note: ...
unsigned greater or equal
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
static bool isInBoundsIndices(ArrayRef< IndexTy > Idxs)
Test whether the given sequence of normalized indices is "inbounds".
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList)
Create an "inbounds" getelementptr.
bool isEquality() const
Return true if this predicate is either EQ or NE.
static Instruction::CastOps getCastOpcode(const Value *Val, bool SrcIsSigned, Type *Ty, bool DstIsSigned)
Returns the opcode necessary to cast Val into Ty using usual casting rules.
static Constant * getOr(Constant *C1, Constant *C2)
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices...
0 1 1 0 True if ordered and operands are unequal
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
1 0 1 0 True if unordered or greater than
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value *> Idxs)
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value *> IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
static Constant * getSRem(Constant *C1, Constant *C2)
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
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 isCast() const
Return true if this is a convert constant expression.
Type * getElementType() const
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Type * getSourceElementType() const
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices...
bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty...
static APInt getNullValue(unsigned numBits)
Get the '0' value.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
0 0 1 1 True if ordered and greater than or equal
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static Constant * get(ArrayRef< Constant *> V)
Type * getElementType() const
static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2)
This function determines if there is anything we can decide about the two constants provided...
0 0 0 0 Always false (always folded)
bool empty() const
empty - Check if the array is empty.
cmpResult compare(const APFloat &RHS) const
static Constant * getXor(Constant *C1, Constant *C2)
const fltSemantics & getFltSemantics() const
gep_type_iterator gep_type_begin(const User *GEP)
static Constant * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.