37 using namespace llvm::PatternMatch;
62 for (
unsigned i = 0; i != NumElts; ++i) {
82 assert(Op && Op->
isCast() &&
"Can't fold cast of cast without a cast!");
83 assert(DstTy && DstTy->
isFirstClassType() &&
"Invalid cast destination type");
99 nullptr, FakeIntPtrTy,
nullptr);
110 if (
PointerType *DPTy = dyn_cast<PointerType>(DestTy))
111 if (PTy->getAddressSpace() == DPTy->getAddressSpace()
112 && DPTy->getElementType()->isSized()) {
117 Type *ElTy = PTy->getElementType();
118 while (ElTy != DPTy->getElementType()) {
119 if (
StructType *STy = dyn_cast<StructType>(ElTy)) {
120 if (STy->getNumElements() == 0)
break;
121 ElTy = STy->getElementType(0);
124 dyn_cast<SequentialType>(ElTy)) {
126 ElTy = STy->getElementType();
133 if (ElTy == DPTy->getElementType())
141 if (
VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
143 assert(DestPTy->getBitWidth() == SrcTy->getBitWidth() &&
144 "Not cast between same sized vectors!");
147 if (isa<ConstantAggregateZero>(V))
157 if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
163 if (isa<ConstantPointerNull>(V))
184 if (
ConstantFP *FP = dyn_cast<ConstantFP>(V)) {
191 if (FP->getType()->isPPC_FP128Ty())
195 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");
353 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
359 if (
StructType *STy = dyn_cast<StructType>(Ty))
360 if (!STy->isPacked()) {
361 unsigned NumElems = STy->getNumElements();
369 for (
unsigned i = 1; i != NumElems; ++i)
384 if (!PTy->getElementType()->isIntegerTy(1))
387 PTy->getAddressSpace()),
412 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
421 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
429 unsigned NumElems = STy->getNumElements();
437 for (
unsigned i = 1; i != NumElems; ++i)
438 if (MemberAlign !=
getFoldedAlignOf(STy->getElementType(i), DestTy,
true)) {
449 if (!PTy->getElementType()->isIntegerTy(1))
453 PTy->getAddressSpace()),
477 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
485 if (
StructType *STy = dyn_cast<StructType>(Ty))
486 if (!STy->isPacked()) {
487 unsigned NumElems = STy->getNumElements();
495 for (
unsigned i = 1; i != NumElems; ++i)
526 if (isa<UndefValue>(V)) {
530 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
531 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
546 }
else if (CE->getOpcode() == Instruction::GetElementPtr &&
549 opc != Instruction::AddrSpaceCast) {
552 bool isAllNull =
true;
553 for (
unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
554 if (!CE->getOperand(i)->isNullValue()) {
567 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
571 VectorType *DestVecTy = cast<VectorType>(DestTy);
587 case Instruction::FPTrunc:
588 case Instruction::FPExt:
589 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
591 APFloat Val = FPC->getValueAPF();
603 case Instruction::FPToUI:
604 case Instruction::FPToSI:
605 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
606 const APFloat &V = FPC->getValueAPF();
609 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
617 APInt Val(DestBitWidth, x);
621 case Instruction::IntToPtr:
625 case Instruction::PtrToInt:
633 if (CE->getOpcode() == Instruction::GetElementPtr &&
634 CE->getOperand(0)->isNullValue()) {
637 if (CE->getNumOperands() == 2) {
640 bool isOne = isa<ConstantInt>(Idx) && cast<ConstantInt>(Idx)->isOne();
647 }
else if (CE->getNumOperands() == 3 &&
648 CE->getOperand(1)->isNullValue()) {
650 if (
StructType *STy = dyn_cast<StructType>(Ty))
651 if (!STy->isPacked()) {
652 ConstantInt *CI = cast<ConstantInt>(CE->getOperand(2));
654 STy->getNumElements() == 2 &&
655 STy->getElementType(0)->isIntegerTy(1)) {
660 if (Ty->isStructTy() || Ty->isArrayTy()) {
669 case Instruction::UIToFP:
670 case Instruction::SIToFP:
672 APInt api = CI->getValue();
685 case Instruction::ZExt:
687 uint32_t BitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
689 CI->getValue().zext(BitWidth));
692 case Instruction::SExt:
694 uint32_t BitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
696 CI->getValue().sext(BitWidth));
699 case Instruction::Trunc: {
703 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->
getBitWidth();
706 CI->getValue().trunc(DestBitWidth));
712 if ((DestBitWidth & 7) == 0 &&
719 case Instruction::BitCast:
721 case Instruction::AddrSpaceCast:
743 if (V1Element == V2Element) {
745 }
else if (isa<UndefValue>(Cond)) {
746 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
748 if (!isa<ConstantInt>(Cond))
break;
759 if (isa<UndefValue>(Cond)) {
760 if (isa<UndefValue>(V1))
return V1;
763 if (isa<UndefValue>(V1))
return V2;
764 if (isa<UndefValue>(V2))
return V1;
765 if (V1 == V2)
return V1;
767 if (
ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) {
769 if (TrueVal->getOperand(0) == Cond)
772 if (
ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) {
774 if (FalseVal->getOperand(0) == Cond)
783 if (isa<UndefValue>(Val))
788 if (isa<UndefValue>(Idx))
791 if (
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
803 if (isa<UndefValue>(Idx))
807 if (!CIdx)
return nullptr;
810 if (CIdx->uge(NumElts))
816 uint64_t IdxVal = CIdx->getZExtValue();
817 for (
unsigned i = 0; i != NumElts; ++i) {
837 if (isa<UndefValue>(Mask))
841 if (isa<ConstantExpr>(Mask))
return nullptr;
847 for (
unsigned i = 0; i != MaskNumElts; ++i) {
854 if (
unsigned(Elt) >= SrcNumElts*2)
856 else if (
unsigned(Elt) >= SrcNumElts) {
892 NumElts =
ST->getNumElements();
894 NumElts = AT->getNumElements();
899 for (
unsigned i = 0; i != NumElts; ++i) {
901 if (!C)
return nullptr;
920 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
923 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
928 case Instruction::Add:
929 case Instruction::Sub:
932 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
935 case Instruction::Mul: {
937 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
948 case Instruction::SDiv:
949 case Instruction::UDiv:
959 case Instruction::URem:
960 case Instruction::SRem:
970 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
973 case Instruction::LShr:
975 if (isa<UndefValue>(C2))
982 case Instruction::AShr:
984 if (isa<UndefValue>(C2))
992 case Instruction::Shl:
994 if (isa<UndefValue>(C2))
1005 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1007 case Instruction::Add:
1008 if (CI2->equalsInt(0))
return C1;
1010 case Instruction::Sub:
1011 if (CI2->equalsInt(0))
return C1;
1013 case Instruction::Mul:
1014 if (CI2->equalsInt(0))
return C2;
1015 if (CI2->equalsInt(1))
1018 case Instruction::UDiv:
1019 case Instruction::SDiv:
1020 if (CI2->equalsInt(1))
1022 if (CI2->equalsInt(0))
1025 case Instruction::URem:
1026 case Instruction::SRem:
1027 if (CI2->equalsInt(1))
1029 if (CI2->equalsInt(0))
1033 if (CI2->isZero())
return C2;
1034 if (CI2->isAllOnesValue())
1039 if (CE1->getOpcode() == Instruction::ZExt) {
1040 unsigned DstWidth = CI2->
getType()->getBitWidth();
1044 if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
1049 if (CE1->getOpcode() == Instruction::PtrToInt &&
1050 isa<GlobalValue>(CE1->getOperand(0))) {
1051 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
1055 if (isa<Function>(GV))
1056 GVAlign = std::max(GVAlign, 4U);
1059 unsigned DstWidth = CI2->getType()->getBitWidth();
1064 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
1071 if (CI2->equalsInt(0))
return C1;
1072 if (CI2->isAllOnesValue())
1076 if (CI2->equalsInt(0))
return C1;
1079 switch (CE1->getOpcode()) {
1081 case Instruction::ICmp:
1082 case Instruction::FCmp:
1084 assert(CI2->equalsInt(1));
1088 CE1->getOperand(1));
1092 case Instruction::AShr:
1095 if (CE1->getOpcode() == Instruction::ZExt)
1099 }
else if (isa<ConstantInt>(C1)) {
1106 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
1107 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1108 const APInt &C1V = CI1->getValue();
1109 const APInt &C2V = CI2->getValue();
1113 case Instruction::Add:
1115 case Instruction::Sub:
1117 case Instruction::Mul:
1119 case Instruction::UDiv:
1120 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1122 case Instruction::SDiv:
1123 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1127 case Instruction::URem:
1128 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1130 case Instruction::SRem:
1131 assert(!CI2->isNullValue() &&
"Div by zero handled above");
1141 case Instruction::Shl:
1145 case Instruction::LShr:
1149 case Instruction::AShr:
1157 case Instruction::SDiv:
1158 case Instruction::UDiv:
1159 case Instruction::URem:
1160 case Instruction::SRem:
1161 case Instruction::LShr:
1162 case Instruction::AShr:
1163 case Instruction::Shl:
1164 if (CI1->equalsInt(0))
return C1;
1169 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
1170 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
1171 APFloat C1V = CFP1->getValueAPF();
1172 APFloat C2V = CFP2->getValueAPF();
1177 case Instruction::FAdd:
1180 case Instruction::FSub:
1183 case Instruction::FMul:
1186 case Instruction::FDiv:
1189 case Instruction::FRem:
1198 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
1219 if (!isa<ConstantExpr>(T) || cast<ConstantExpr>(
T)->getOpcode() != Opcode)
1222 }
else if (isa<ConstantExpr>(C2)) {
1232 case Instruction::Add:
1233 case Instruction::Sub:
1235 case Instruction::Mul:
1237 case Instruction::Shl:
1238 case Instruction::LShr:
1239 case Instruction::AShr:
1243 case Instruction::SDiv:
1244 case Instruction::UDiv:
1248 case Instruction::URem:
1249 case Instruction::SRem:
1265 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
1266 if (STy->isOpaque())
return true;
1269 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
1273 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
1287 if (C1 == C2)
return 0;
1291 if (!isa<ConstantInt>(C1) || !isa<ConstantInt>(C2))
1295 if (cast<ConstantInt>(C1)->getValue().getActiveBits() > 64 ||
1296 cast<ConstantInt>(C2)->getValue().getActiveBits() > 64)
1301 int64_t C1Val = cast<ConstantInt>(C1)->getSExtValue();
1302 int64_t C2Val = cast<ConstantInt>(C2)->getSExtValue();
1304 if (C1Val == C2Val)
return 0;
1332 "Cannot compare values of different types!");
1337 if (!isa<ConstantExpr>(V1)) {
1338 if (!isa<ConstantExpr>(V2)) {
1367 case Instruction::FPTrunc:
1368 case Instruction::FPExt:
1369 case Instruction::UIToFP:
1370 case Instruction::SIToFP:
1384 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
1385 if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage())
1387 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
1388 Type *Ty = GVar->getValueType();
1400 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
1401 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
1421 "Cannot compare different types of values!");
1424 if (!isa<ConstantExpr>(V1) && !isa<GlobalValue>(V1) &&
1425 !isa<BlockAddress>(V1)) {
1426 if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(
V2) &&
1427 !isa<BlockAddress>(V2)) {
1454 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1455 if (isa<ConstantExpr>(V2)) {
1466 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1468 }
else if (isa<BlockAddress>(V2)) {
1471 assert(isa<ConstantPointerNull>(V2) &&
"Canonicalization guarantee!");
1474 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV))
1477 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1478 if (isa<ConstantExpr>(V2)) {
1489 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1493 if (BA2->getFunction() != BA->getFunction())
1497 assert((isa<ConstantPointerNull>(V2) || isa<GlobalValue>(V2)) &&
1498 "Canonicalization guarantee!");
1508 case Instruction::Trunc:
1509 case Instruction::FPTrunc:
1510 case Instruction::FPExt:
1511 case Instruction::FPToUI:
1512 case Instruction::FPToSI:
1515 case Instruction::UIToFP:
1516 case Instruction::SIToFP:
1517 case Instruction::BitCast:
1518 case Instruction::ZExt:
1519 case Instruction::SExt:
1524 if (CE1->
getOpcode() == Instruction::ZExt) isSigned =
false;
1525 if (CE1->
getOpcode() == Instruction::SExt) isSigned =
true;
1532 case Instruction::GetElementPtr: {
1536 if (isa<ConstantPointerNull>(V2)) {
1539 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1540 if (GV->hasExternalWeakLinkage())
1548 }
else if (isa<ConstantPointerNull>(CE1Op0)) {
1559 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1560 if (isa<ConstantPointerNull>(CE1Op0)) {
1561 if (GV2->hasExternalWeakLinkage())
1569 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1577 "Surprising getelementptr!");
1593 case Instruction::GetElementPtr:
1596 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1598 if (CE1Op0 != CE2Op0) {
1602 cast<GlobalValue>(CE2Op0));
1664 VT->getNumElements());
1676 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1687 if (isIntegerPredicate)
1697 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
1699 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1707 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
1709 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1721 if (isa<ConstantInt>(C2))
1731 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1732 APInt V1 = cast<ConstantInt>(C1)->getValue();
1733 APInt V2 = cast<ConstantInt>(C2)->getValue();
1747 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1748 APFloat C1V = cast<ConstantFP>(C1)->getValueAPF();
1749 APFloat C2V = cast<ConstantFP>(C2)->getValueAPF();
1811 (isa<ConstantExpr>(C1) || isa<ConstantExpr>(C2))) {
1944 if (CE2->getOpcode() == Instruction::BitCast &&
1957 if (CE1Inverse == CE1Op0) {
1967 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
1981 template<
typename IndexTy>
1984 if (Idxs.
empty())
return true;
1987 if (cast<Constant>(Idxs[0])->isNullValue())
return true;
1991 if (!cast<ConstantInt>(Idxs[0])->isOne())
1993 for (
unsigned i = 1, e = Idxs.
size(); i != e; ++i)
1994 if (!cast<Constant>(Idxs[i])->isNullValue())
2002 if (
const PointerType *PTy = dyn_cast<PointerType>(STy))
2004 return PTy->getElementType()->isSized();
2006 uint64_t NumElements = 0;
2008 if (
const ArrayType *ATy = dyn_cast<ArrayType>(STy))
2009 NumElements = ATy->getNumElements();
2010 else if (
const VectorType *VTy = dyn_cast<VectorType>(STy))
2011 NumElements = VTy->getNumElements();
2013 assert((isa<ArrayType>(STy) || NumElements > 0) &&
2014 "didn't expect non-array type to have zero elements!");
2023 if (IndexVal < 0 || (NumElements > 0 && (uint64_t)IndexVal >= NumElements))
2030 template<
typename IndexTy>
2034 if (Idxs.
empty())
return C;
2035 Constant *Idx0 = cast<Constant>(Idxs[0]);
2039 if (isa<UndefValue>(C)) {
2042 cast<PointerType>(Ptr->
getScalarType())->getElementType(), Idxs);
2043 assert(Ty &&
"Invalid indices for GEP!");
2049 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2050 if (!cast<Constant>(Idxs[i])->isNullValue()) {
2057 cast<PointerType>(Ptr->
getScalarType())->getElementType(), Idxs);
2058 assert(Ty &&
"Invalid indices for GEP!");
2069 if (CE->getOpcode() == Instruction::GetElementPtr) {
2070 Type *LastTy =
nullptr;
2093 bool PerformFold =
false;
2096 else if (
SequentialType *STy = dyn_cast_or_null<SequentialType>(LastTy))
2097 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idx0))
2102 NewIndices.
reserve(Idxs.
size() + CE->getNumOperands());
2103 NewIndices.
append(CE->op_begin() + 1, CE->op_end() - 1);
2107 Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
2111 if (IdxTy != Idx0->
getType()) {
2112 unsigned CommonExtendedWidth =
2115 CommonExtendedWidth = std::max(CommonExtendedWidth, 64U);
2131 cast<GEPOperator>(CE)->getSourceElementType(), CE->getOperand(0),
2132 NewIndices, inBounds && cast<GEPOperator>(CE)->isInBounds());
2149 if (SrcPtrTy && DstPtrTy) {
2154 if (SrcArrayTy && DstArrayTy
2158 SrcArrayTy, (
Constant *)CE->getOperand(0), Idxs, inBounds);
2167 Type *Ty = PointeeTy;
2169 bool Unknown = !isa<ConstantInt>(Idxs[0]);
2170 for (
unsigned i = 1, e = Idxs.
size(); i != e;
2171 Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
2172 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
2173 if (isa<ArrayType>(Ty) || isa<VectorType>(Ty))
2174 if (CI->getSExtValue() > 0 &&
2176 if (isa<SequentialType>(Prev)) {
2180 uint64_t NumElements = 0;
2181 if (
const ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2182 NumElements = ATy->getNumElements();
2184 NumElements = cast<VectorType>(Ty)->getNumElements();
2189 Constant *PrevIdx = cast<Constant>(Idxs[i-1]);
2192 unsigned CommonExtendedWidth =
2194 Div->getType()->getIntegerBitWidth());
2195 CommonExtendedWidth = std::max(CommonExtendedWidth, 64U);
2203 if (!Div->getType()->isIntegerTy(CommonExtendedWidth))
2221 if (!NewIdxs.
empty()) {
2222 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2223 if (!NewIdxs[i]) NewIdxs[i] = cast<Constant>(Idxs[i]);
2229 if (!Unknown && !inBounds)
2230 if (
auto *GV = dyn_cast<GlobalVariable>(C))
static int getMaskValue(Constant *Mask, unsigned i)
getMaskValue - Return the index from the shuffle mask for the specified output result.
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 LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
opStatus divide(const APFloat &, roundingMode)
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)
static const fltSemantics IEEEdouble
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)
getFoldedOffsetOf - Return a ConstantExpr with type DestTy for offsetof on Ty and FieldNo...
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)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
gep_type_iterator gep_type_end(const User *GEP)
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
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
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
1 1 1 0 True if unordered or not equal
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)
getFoldedAlignOf - Return a ConstantExpr with type DestTy for alignof on Ty, with any known factors f...
void reserve(size_type N)
static const fltSemantics Bogus
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
static Constant * getNullValue(Type *Ty)
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
1 0 0 1 True if unordered or equal
APInt LLVM_ATTRIBUTE_UNUSED_RESULT urem(const APInt &RHS) const
Unsigned remainder operation.
BlockAddress - The address of a basic block.
bool match(Val *V, const Pattern &P)
static const fltSemantics x87DoubleExtended
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
const APInt & getValue() const
Return the constant as an APInt value reference.
StructType - Class to represent struct types.
opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, bool *) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2, bool isSigned)
evaluateICmpRelation - This function determines if there is anything we can decide about the two cons...
static Constant * BitCastConstantVector(Constant *CV, VectorType *DstTy)
BitCastConstantVector - Convert the specified vector Constant node to the specified vector type...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT 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
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static const fltSemantics IEEEquad
static Constant * ConstantFoldGetElementPtrImpl(Type *PointeeTy, Constant *C, bool inBounds, ArrayRef< IndexTy > Idxs)
Type * getVectorElementType() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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...
ConstantExpr - 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...
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
static int IdxCompare(Constant *C1, Constant *C2, Type *ElTy)
IdxCompare - Compare the two constants as though they were getelementptr indices. ...
bool isAssociative() const
isAssociative - Return true if the instruction is associative:
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
ArrayType - 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
isFirstClassType - 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.
bool isFloatingPointTy() const
isFloatingPointTy - Return true if this is one of the six floating point types
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const
Left-shift function.
unsigned getNumElements() const
Return the number of elements in the Vector type.
bool isPPC_FP128Ty() const
isPPC_FP128Ty - Return true if this is powerpc long double.
Type * getElementType() const
size_t size() const
size - Get the array size.
PointerType - Class to represent pointers.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
opStatus mod(const APFloat &, roundingMode)
C fmod, or llvm frem.
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, const GlobalValue *GV2)
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
bool isX86_MMXTy() const
isX86_MMXTy - 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)
get() - Static factory methods - Return objects of the specified value
APInt LLVM_ATTRIBUTE_UNUSED_RESULT trunc(unsigned width) const
Truncate to new width.
cmpResult compare(const APFloat &) const
IEEE comparison with another floating point number (NaNs compare unordered, 0==-0).
The instances of the Type class are immutable: once they are created, they are never changed...
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
bool sge(const APInt &RHS) const
Signed greather or equal comparison.
bool isEquality() const
isEquality - 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)
getFoldedSizeOf - Return a ConstantExpr with type DestTy for sizeof on Ty, with any known factors fac...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isFloatTy() const
isFloatTy - 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 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.
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT 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
isCommutative - 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...
Class to represent integer types.
ConstantVector - 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
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to th...
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
isFP128Ty - Return true if this is 'fp128'.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
1 1 0 1 True if unordered, less than, or equal
static const fltSemantics IEEEhalf
APInt LLVM_ATTRIBUTE_UNUSED_RESULT srem(const APInt &RHS) const
Function for signed remainder operation.
Constant * ConstantFoldGetElementPtr(Constant *C, bool inBounds, ArrayRef< Constant * > Idxs)
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
SequentialType - This is the superclass of the array, pointer 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)
ExtractConstantBytes - V is an integer constant which only has a subset of its bytes used...
static const fltSemantics PPCDoubleDouble
unsigned getIntegerBitWidth() const
This is the shared class of boolean and integer constants.
bool slt(const APInt &RHS) const
Signed less than comparison.
unsigned getVectorNumElements() const
opStatus add(const APFloat &, roundingMode)
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.
opStatus multiply(const APFloat &, roundingMode)
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)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
const fltSemantics & getFltSemantics() const
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
static bool isMaybeZeroSizedType(Type *Ty)
isZeroSizedType - This type is zero sized if its an array or structure of zero sized types...
static ConstantInt * getTrue(LLVMContext &Context)
bool isAllOnesValue() const
isAllOnesValue - 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...
VectorType - 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
isIntegerTy - True if this is an instance of IntegerType.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
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)
static const fltSemantics IEEEsingle
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
bool isX86_FP80Ty() const
isX86_FP80Ty - Return true if this is x86 long double.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT 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 isInBoundsIndices(ArrayRef< IndexTy > Idxs)
isInBoundsIndices - 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)
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
0 1 1 0 True if ordered and operands are unequal
1 0 1 0 True if unordered or greater than
unsigned getAlignment() const
static Constant * getSRem(Constant *C1, Constant *C2)
bool isEmptyTy() const
isEmptyTy - Return true if this type is empty, that is, it has no elements or all its elements are em...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - 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)
VectorType::get - This static method is the primary way to construct an VectorType.
static bool isUnordered(unsigned short predicate)
Determine if the predicate is an unordered operation.
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)
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
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.
opStatus subtract(const APFloat &, roundingMode)
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)
evaluateFCmpRelation - This function determines if there is anything we can decide about the two cons...
0 0 0 0 Always false (always folded)
static Constant * getXor(Constant *C1, Constant *C2)
static bool isIndexInRangeOfSequentialType(const SequentialType *STy, const ConstantInt *CI)
Test whether a given ConstantInt is in-range for a SequentialType.
gep_type_iterator gep_type_begin(const User *GEP)