35 using namespace llvm::PatternMatch;
60 for (
unsigned i = 0;
i != NumElts; ++
i) {
80 assert(Op && Op->
isCast() &&
"Can't fold cast of cast without a cast!");
97 nullptr, FakeIntPtrTy,
nullptr);
108 if (
PointerType *DPTy = dyn_cast<PointerType>(DestTy))
109 if (PTy->getAddressSpace() == DPTy->getAddressSpace()
110 && PTy->getElementType()->isSized()) {
115 Type *ElTy = PTy->getElementType();
116 while (ElTy != DPTy->getElementType()) {
117 if (
StructType *STy = dyn_cast<StructType>(ElTy)) {
118 if (STy->getNumElements() == 0)
break;
119 ElTy = STy->getElementType(0);
122 dyn_cast<SequentialType>(ElTy)) {
123 ElTy = STy->getElementType();
130 if (ElTy == DPTy->getElementType())
138 if (
VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
140 assert(DestPTy->getBitWidth() == SrcTy->getBitWidth() &&
141 "Not cast between same sized vectors!");
144 if (isa<ConstantAggregateZero>(V))
154 if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
160 if (isa<ConstantPointerNull>(V))
181 if (
ConstantFP *FP = dyn_cast<ConstantFP>(V)) {
188 if (FP->getType()->isPPC_FP128Ty())
196 FP->getValueAPF().bitcastToAPInt());
215 "Non-byte sized integer input");
217 assert(ByteSize &&
"Must be accessing some piece");
218 assert(ByteStart+ByteSize <= CSize &&
"Extracting invalid piece from input");
219 assert(ByteSize != CSize &&
"Should not extract everything");
223 APInt V = CI->getValue();
225 V = V.
lshr(ByteStart*8);
226 V = V.
trunc(ByteSize*8);
233 if (!CE)
return nullptr;
236 default:
return nullptr;
243 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS))
244 if (RHSC->isAllOnesValue())
266 case Instruction::LShr: {
272 if ((ShAmt & 7) != 0)
277 if (ByteStart >= CSize-ShAmt)
281 if (ByteStart+ByteSize+ShAmt <= CSize)
288 case Instruction::Shl: {
294 if ((ShAmt & 7) != 0)
299 if (ByteStart+ByteSize <= ShAmt)
303 if (ByteStart >= ShAmt)
310 case Instruction::ZExt: {
311 unsigned SrcBitSize =
315 if (ByteStart*8 >= SrcBitSize)
320 if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
325 if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize)
330 if ((ByteStart+ByteSize)*8 < SrcBitSize) {
331 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()),
410 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
419 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
427 unsigned NumElems = STy->getNumElements();
435 for (
unsigned i = 1;
i != NumElems; ++
i)
447 if (!PTy->getElementType()->isIntegerTy(1))
451 PTy->getAddressSpace()),
474 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
482 if (
StructType *STy = dyn_cast<StructType>(Ty))
483 if (!STy->isPacked()) {
484 unsigned NumElems = STy->getNumElements();
492 for (
unsigned i = 1;
i != NumElems; ++
i)
523 if (isa<UndefValue>(V)) {
527 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
528 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
534 opc != Instruction::AddrSpaceCast)
544 }
else if (CE->getOpcode() == Instruction::GetElementPtr &&
547 opc != Instruction::AddrSpaceCast &&
550 !cast<GEPOperator>(CE)->getInRangeIndex().hasValue()) {
553 bool isAllNull =
true;
554 for (
unsigned i = 1, e = CE->getNumOperands();
i != e; ++
i)
555 if (!CE->getOperand(
i)->isNullValue()) {
568 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
572 VectorType *DestVecTy = cast<VectorType>(DestTy);
588 case Instruction::FPTrunc:
589 case Instruction::FPExt:
590 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
592 APFloat Val = FPC->getValueAPF();
604 case Instruction::FPToUI:
605 case Instruction::FPToSI:
606 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
607 const APFloat &V = FPC->getValueAPF();
618 APInt Val(DestBitWidth, x);
622 case Instruction::IntToPtr:
626 case Instruction::PtrToInt:
634 if (CE->getOpcode() == Instruction::GetElementPtr &&
635 CE->getOperand(0)->isNullValue()) {
638 if (CE->getNumOperands() == 2) {
641 bool isOne = isa<ConstantInt>(Idx) && cast<ConstantInt>(Idx)->isOne();
648 }
else if (CE->getNumOperands() == 3 &&
649 CE->getOperand(1)->isNullValue()) {
651 if (
StructType *STy = dyn_cast<StructType>(Ty))
652 if (!STy->isPacked()) {
653 ConstantInt *CI = cast<ConstantInt>(CE->getOperand(2));
655 STy->getNumElements() == 2 &&
656 STy->getElementType(0)->isIntegerTy(1)) {
661 if (Ty->isStructTy() || Ty->isArrayTy()) {
670 case Instruction::UIToFP:
671 case Instruction::SIToFP:
673 const APInt &api = CI->getValue();
686 case Instruction::ZExt:
690 CI->getValue().zext(BitWidth));
693 case Instruction::SExt:
697 CI->getValue().sext(BitWidth));
700 case Instruction::Trunc: {
707 CI->getValue().trunc(DestBitWidth));
713 if ((DestBitWidth & 7) == 0 &&
720 case Instruction::BitCast:
722 case Instruction::AddrSpaceCast:
744 if (V1Element == V2Element) {
746 }
else if (isa<UndefValue>(Cond)) {
747 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
749 if (!isa<ConstantInt>(Cond))
break;
760 if (isa<UndefValue>(Cond)) {
761 if (isa<UndefValue>(V1))
return V1;
764 if (isa<UndefValue>(V1))
return V2;
765 if (isa<UndefValue>(V2))
return V1;
766 if (V1 == V2)
return V1;
768 if (
ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) {
770 if (TrueVal->getOperand(0) == Cond)
773 if (
ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) {
775 if (FalseVal->getOperand(0) == Cond)
784 if (isa<UndefValue>(Val))
789 if (isa<UndefValue>(Idx))
792 if (
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
804 if (isa<UndefValue>(Idx))
808 if (!CIdx)
return nullptr;
811 if (CIdx->uge(NumElts))
817 uint64_t IdxVal = CIdx->getZExtValue();
818 for (
unsigned i = 0;
i != NumElts; ++
i) {
838 if (isa<UndefValue>(Mask))
842 if (isa<ConstantExpr>(Mask))
return nullptr;
848 for (
unsigned i = 0;
i != MaskNumElts; ++
i) {
855 if (
unsigned(Elt) >= SrcNumElts*2)
857 else if (
unsigned(Elt) >= SrcNumElts) {
893 NumElts =
ST->getNumElements();
895 NumElts = cast<SequentialType>(Agg->
getType())->getNumElements();
898 for (
unsigned i = 0;
i != NumElts; ++
i) {
900 if (!C)
return nullptr;
921 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
922 switch (static_cast<Instruction::BinaryOps>(Opcode)) {
924 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
930 case Instruction::Sub:
933 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
936 case Instruction::Mul: {
938 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
949 case Instruction::SDiv:
950 case Instruction::UDiv:
952 if (isa<UndefValue>(C2))
960 case Instruction::URem:
961 case Instruction::SRem:
971 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
974 case Instruction::LShr:
976 if (isa<UndefValue>(C2))
983 case Instruction::AShr:
985 if (isa<UndefValue>(C2))
993 case Instruction::Shl:
995 if (isa<UndefValue>(C2))
1002 case Instruction::FAdd:
1003 case Instruction::FSub:
1004 case Instruction::FMul:
1005 case Instruction::FDiv:
1006 case Instruction::FRem:
1009 case Instruction::BinaryOpsEnd:
1015 assert(!isa<UndefValue>(C1) && !isa<UndefValue>(C2) &&
1016 "Unexpected UndefValue");
1019 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1022 if (CI2->equalsInt(0))
return C1;
1024 case Instruction::Sub:
1025 if (CI2->equalsInt(0))
return C1;
1027 case Instruction::Mul:
1028 if (CI2->equalsInt(0))
return C2;
1029 if (CI2->equalsInt(1))
1032 case Instruction::UDiv:
1033 case Instruction::SDiv:
1034 if (CI2->equalsInt(1))
1036 if (CI2->equalsInt(0))
1039 case Instruction::URem:
1040 case Instruction::SRem:
1041 if (CI2->equalsInt(1))
1043 if (CI2->equalsInt(0))
1047 if (CI2->isZero())
return C2;
1048 if (CI2->isAllOnesValue())
1053 if (CE1->getOpcode() == Instruction::ZExt) {
1054 unsigned DstWidth = CI2->
getType()->getBitWidth();
1058 if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
1063 if (CE1->getOpcode() == Instruction::PtrToInt &&
1064 isa<GlobalValue>(CE1->getOperand(0))) {
1065 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
1069 if (isa<Function>(GV))
1070 GVAlign = std::max(GVAlign, 4U);
1073 unsigned DstWidth = CI2->getType()->getBitWidth();
1078 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
1085 if (CI2->equalsInt(0))
return C1;
1086 if (CI2->isAllOnesValue())
1090 if (CI2->equalsInt(0))
return C1;
1093 switch (CE1->getOpcode()) {
1095 case Instruction::ICmp:
1096 case Instruction::FCmp:
1098 assert(CI2->equalsInt(1));
1102 CE1->getOperand(1));
1106 case Instruction::AShr:
1109 if (CE1->getOpcode() == Instruction::ZExt)
1113 }
else if (isa<ConstantInt>(C1)) {
1119 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
1120 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1121 const APInt &C1V = CI1->getValue();
1122 const APInt &C2V = CI2->getValue();
1128 case Instruction::Sub:
1130 case Instruction::Mul:
1132 case Instruction::UDiv:
1133 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1135 case Instruction::SDiv:
1136 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1140 case Instruction::URem:
1141 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1143 case Instruction::SRem:
1144 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1154 case Instruction::Shl:
1158 case Instruction::LShr:
1162 case Instruction::AShr:
1170 case Instruction::SDiv:
1171 case Instruction::UDiv:
1172 case Instruction::URem:
1173 case Instruction::SRem:
1174 case Instruction::LShr:
1175 case Instruction::AShr:
1176 case Instruction::Shl:
1177 if (CI1->equalsInt(0))
return C1;
1182 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
1183 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
1184 const APFloat &C1V = CFP1->getValueAPF();
1185 const APFloat &C2V = CFP2->getValueAPF();
1190 case Instruction::FAdd:
1193 case Instruction::FSub:
1196 case Instruction::FMul:
1199 case Instruction::FDiv:
1202 case Instruction::FRem:
1211 for (
unsigned i = 0, e = VTy->getNumElements();
i != e; ++
i) {
1232 if (!isa<ConstantExpr>(T) || cast<ConstantExpr>(
T)->getOpcode() != Opcode)
1235 }
else if (isa<ConstantExpr>(C2)) {
1246 case Instruction::Sub:
1248 case Instruction::Mul:
1250 case Instruction::Shl:
1251 case Instruction::LShr:
1252 case Instruction::AShr:
1256 case Instruction::SDiv:
1257 case Instruction::UDiv:
1261 case Instruction::URem:
1262 case Instruction::SRem:
1278 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
1279 if (STy->isOpaque())
return true;
1282 for (
unsigned i = 0, e = STy->getNumElements();
i != e; ++
i)
1286 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
1300 if (C1 == C2)
return 0;
1304 if (!isa<ConstantInt>(C1) || !isa<ConstantInt>(C2))
1308 if (cast<ConstantInt>(C1)->getValue().getActiveBits() > 64 ||
1309 cast<ConstantInt>(C2)->getValue().getActiveBits() > 64)
1314 int64_t C1Val = cast<ConstantInt>(C1)->getSExtValue();
1315 int64_t C2Val = cast<ConstantInt>(C2)->getSExtValue();
1317 if (C1Val == C2Val)
return 0;
1345 "Cannot compare values of different types!");
1350 if (!isa<ConstantExpr>(V1)) {
1351 if (!isa<ConstantExpr>(V2)) {
1380 case Instruction::FPTrunc:
1381 case Instruction::FPExt:
1382 case Instruction::UIToFP:
1383 case Instruction::SIToFP:
1397 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
1398 if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage())
1400 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
1401 Type *Ty = GVar->getValueType();
1413 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
1414 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
1434 "Cannot compare different types of values!");
1437 if (!isa<ConstantExpr>(V1) && !isa<GlobalValue>(V1) &&
1438 !isa<BlockAddress>(V1)) {
1439 if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(
V2) &&
1440 !isa<BlockAddress>(V2)) {
1467 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1468 if (isa<ConstantExpr>(V2)) {
1479 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1481 }
else if (isa<BlockAddress>(V2)) {
1484 assert(isa<ConstantPointerNull>(V2) &&
"Canonicalization guarantee!");
1487 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV))
1490 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1491 if (isa<ConstantExpr>(V2)) {
1502 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1506 if (BA2->getFunction() != BA->getFunction())
1510 assert((isa<ConstantPointerNull>(V2) || isa<GlobalValue>(V2)) &&
1511 "Canonicalization guarantee!");
1521 case Instruction::Trunc:
1522 case Instruction::FPTrunc:
1523 case Instruction::FPExt:
1524 case Instruction::FPToUI:
1525 case Instruction::FPToSI:
1528 case Instruction::UIToFP:
1529 case Instruction::SIToFP:
1530 case Instruction::BitCast:
1531 case Instruction::ZExt:
1532 case Instruction::SExt:
1534 if (CE1Op0->getType()->isFloatingPointTy())
1541 if (CE1->
getOpcode() == Instruction::ZExt) isSigned =
false;
1542 if (CE1->
getOpcode() == Instruction::SExt) isSigned =
true;
1549 case Instruction::GetElementPtr: {
1553 if (isa<ConstantPointerNull>(V2)) {
1556 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1557 if (GV->hasExternalWeakLinkage())
1565 }
else if (isa<ConstantPointerNull>(CE1Op0)) {
1576 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1577 if (isa<ConstantPointerNull>(CE1Op0)) {
1578 if (GV2->hasExternalWeakLinkage())
1586 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1594 "Surprising getelementptr!");
1610 case Instruction::GetElementPtr:
1613 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1615 if (CE1Op0 != CE2Op0) {
1619 cast<GlobalValue>(CE2Op0));
1681 VT->getNumElements());
1693 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1704 if (isIntegerPredicate)
1714 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
1716 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1724 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
1726 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1738 if (isa<ConstantInt>(C2))
1748 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1749 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1750 const APInt &
V2 = cast<ConstantInt>(C2)->getValue();
1764 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1765 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1766 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1828 (isa<ConstantExpr>(C1) || isa<ConstantExpr>(C2))) {
1962 if (CE2->getOpcode() == Instruction::BitCast &&
1971 if ((CE1->getOpcode() == Instruction::SExt &&
1973 (CE1->getOpcode() == Instruction::ZExt &&
1977 if (CE1Inverse == CE1Op0) {
1987 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
2000 template<
typename IndexTy>
2003 if (Idxs.
empty())
return true;
2006 if (cast<Constant>(Idxs[0])->isNullValue())
return true;
2010 if (!cast<ConstantInt>(Idxs[0])->isOne())
2012 for (
unsigned i = 1, e = Idxs.
size();
i != e; ++
i)
2013 if (!cast<Constant>(Idxs[
i])->isNullValue())
2028 if (IndexVal < 0 || (NumElements > 0 && (uint64_t)IndexVal >= NumElements))
2039 if (Idxs.
empty())
return C;
2040 Constant *Idx0 = cast<Constant>(Idxs[0]);
2044 if (isa<UndefValue>(C)) {
2052 for (
unsigned i = 0, e = Idxs.
size();
i != e; ++
i)
2053 if (!cast<Constant>(Idxs[
i])->isNullValue()) {
2061 assert(Ty &&
"Invalid indices for GEP!");
2074 if (CE->getOpcode() == Instruction::GetElementPtr) {
2098 bool PerformFold =
false;
2102 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idx0))
2109 NewIndices.
reserve(Idxs.
size() + CE->getNumOperands());
2110 NewIndices.
append(CE->op_begin() + 1, CE->op_end() - 1);
2114 Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
2118 if (IdxTy != Idx0->
getType()) {
2119 unsigned CommonExtendedWidth =
2122 CommonExtendedWidth = std::max(CommonExtendedWidth, 64U);
2142 if (IRIndex && *IRIndex == CE->getNumOperands() - 2 && !Idx0->
isNullValue())
2146 cast<GEPOperator>(CE)->getSourceElementType(), CE->getOperand(0),
2147 NewIndices, InBounds && cast<GEPOperator>(CE)->isInBounds(),
2165 if (SrcPtrTy && DstPtrTy) {
2170 if (SrcArrayTy && DstArrayTy
2175 Idxs, InBounds, InRangeIndex);
2184 Type *Ty = PointeeTy;
2186 bool Unknown = !isa<ConstantInt>(Idxs[0]);
2187 for (
unsigned i = 1, e = Idxs.
size();
i != e;
2188 Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[
i]), ++
i) {
2195 if (InRangeIndex && i == *InRangeIndex + 1) {
2201 if (isa<StructType>(Ty)) {
2205 auto *STy = cast<SequentialType>(Ty);
2206 if (isa<VectorType>(STy)) {
2214 if (isa<StructType>(Prev)) {
2220 if (CI->getSExtValue() < 0) {
2229 uint64_t NumElements = STy->getArrayNumElements();
2234 Constant *PrevIdx = cast<Constant>(Idxs[i - 1]);
2237 unsigned CommonExtendedWidth =
2239 Div->getType()->getIntegerBitWidth());
2240 CommonExtendedWidth = std::max(CommonExtendedWidth, 64U);
2247 if (!Div->getType()->isIntegerTy(CommonExtendedWidth))
2255 if (!NewIdxs.
empty()) {
2256 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++
i)
2257 if (!NewIdxs[i]) NewIdxs[
i] = cast<Constant>(Idxs[
i]);
2264 if (!Unknown && !InBounds)
2265 if (
auto *GV = dyn_cast<GlobalVariable>(C))
2268 true, InRangeIndex);
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
static Constant * FoldBitCast(Constant *V, Type *DestTy)
APInt ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
Type * getSourceElementType() const
void push_back(const T &Elt)
Type * getIndexedType() const
static ConstantInt * getFalse(LLVMContext &Context)
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
static IntegerType * getInt1Ty(LLVMContext &C)
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
match_zero m_Zero()
Match an arbitrary zero/null constant.
unsigned getNumOperands() const
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices...
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...
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
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)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
bool isSigned() const
Determine if this instruction is using a signed comparison.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
0 1 0 0 True if ordered and less than
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
1 1 1 0 True if unordered or not equal
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
static const fltSemantics & Bogus()
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
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.
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...
Type * getElementType() const
void reserve(size_type N)
bool isSequential() const
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
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)
1 0 0 1 True if unordered or equal
opStatus divide(const APFloat &RHS, roundingMode RM)
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
The address of a basic block.
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...
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static const fltSemantics & x87DoubleExtended()
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.
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 Constant * BitCastConstantVector(Constant *CV, VectorType *DstTy)
Convert the specified vector Constant node to the specified vector type.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
static Constant * get(ArrayRef< Constant * > V)
0 1 0 1 True if ordered and less than or equal
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Type * getVectorElementType() const
LLVM_NODISCARD bool empty() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
APInt shl(unsigned shiftAmt) const
Left-shift function.
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible. ...
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
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...
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static int IdxCompare(Constant *C1, Constant *C2, Type *ElTy)
Compare the two constants as though they were getelementptr indices.
bool isAssociative() const
Return true if the instruction is associative:
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
Class to represent array types.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
unsigned getActiveBits() const
Compute the number of active bits in the value.
opStatus subtract(const APFloat &RHS, roundingMode RM)
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
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...
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
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
Class to represent pointers.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
static const fltSemantics & IEEEsingle()
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.
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, const GlobalValue *GV2)
bool isX86_MMXTy() const
Return true if this is X86 MMX.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
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 trunc(unsigned width) const
Truncate to new width.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
True if this is an instance of VectorType.
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
bool isEquality() const
Return true if this predicate is either EQ or NE.
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...
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ConstantFP - Floating Point Values [float, double].
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static const fltSemantics & IEEEhalf()
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
bool isIntPredicate() const
bool sle(const APInt &RHS) const
Signed less or equal comparison.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
opStatus multiply(const APFloat &RHS, roundingMode RM)
uint64_t getNumElements() const
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
bool isCommutative() const
Return true if the instruction is commutative:
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...
unsigned getIntegerBitWidth() const
Class to represent integer types.
Constant Vector Declarations.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
bool empty() const
empty - Check if the array is empty.
static Constant * getNot(Constant *C)
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
opStatus convertToInteger(integerPart *Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isFP128Ty() const
Return true if this is 'fp128'.
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.
static const fltSemantics & IEEEquad()
LLVMContext & getContext() const
All values hold a context through their type.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
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 srem(const APInt &RHS) const
Function for signed remainder operation.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
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.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static Constant * ExtractConstantBytes(Constant *C, unsigned ByteStart, unsigned ByteSize)
V is an integer constant which only has a subset of its bytes used.
uint64_t getSequentialNumElements() 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.
bool slt(const APInt &RHS) const
Signed less than comparison.
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers...
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
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...
Type * getType() const
All values are typed, get the type of this value.
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
static Constant * getNUWMul(Constant *C1, Constant *C2)
bool isTrueWhenEqual() const
This is just a convenience.
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.
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.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
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...
const fltSemantics & getFltSemantics() const
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
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)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
bool isBoundedSequential() const
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
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...
Class to represent vector types.
Class for arbitrary precision integers.
bool isCast() const
Return true if this is a convert constant expression.
bool isIntegerTy() const
True if this is an instance of IntegerType.
unsigned getVectorNumElements() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
opStatus mod(const APFloat &RHS)
static const fltSemantics & IEEEdouble()
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
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...
bool isGEPWithNoNotionalOverIndexing() const
Return true if this is a getelementptr expression and all the index operands are compile-time known i...
bool isAllOnesValue() const
Determine if all bits are set.
Constant * ConstantFoldCompareInstruction(unsigned short predicate, Constant *C1, Constant *C2)
opStatus add(const APFloat &RHS, roundingMode RM)
static int getMaskValue(Constant *Mask, unsigned Elt)
Return the shuffle mask value for the specified element of the mask.
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
bool isX86_FP80Ty() const
Return true if this is x86 long double.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static IntegerType * getInt32Ty(LLVMContext &C)
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".
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)
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
0 1 1 0 True if ordered and operands are unequal
static const fltSemantics & PPCDoubleDouble()
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
unsigned getAlignment() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Constant * getSRem(Constant *C1, Constant *C2)
bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty...
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.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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.
cmpResult compare(const APFloat &RHS) const
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices...
static APInt getNullValue(unsigned numBits)
Get the '0' value.
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)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
0 0 1 1 True if ordered and greater than or equal
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
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)
static Constant * getXor(Constant *C1, Constant *C2)
gep_type_iterator gep_type_begin(const User *GEP)