36 using namespace llvm::PatternMatch;
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))
182 if (
ConstantFP *FP = dyn_cast<ConstantFP>(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;
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 =
316 if (ByteStart*8 >= SrcBitSize)
321 if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
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()) {
551 bool isAllNull =
true;
552 for (
unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
553 if (!CE->getOperand(i)->isNullValue()) {
566 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
570 VectorType *DestVecTy = cast<VectorType>(DestTy);
586 case Instruction::FPTrunc:
587 case Instruction::FPExt:
588 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
590 APFloat Val = FPC->getValueAPF();
602 case Instruction::FPToUI:
603 case Instruction::FPToSI:
604 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
605 const APFloat &V = FPC->getValueAPF();
608 APSInt IntVal(DestBitWidth, opc == Instruction::FPToUI);
618 case Instruction::IntToPtr:
622 case Instruction::PtrToInt:
630 if (CE->getOpcode() == Instruction::GetElementPtr &&
631 CE->getOperand(0)->isNullValue()) {
634 if (CE->getNumOperands() == 2) {
637 bool isOne = isa<ConstantInt>(Idx) && cast<ConstantInt>(Idx)->isOne();
644 }
else if (CE->getNumOperands() == 3 &&
645 CE->getOperand(1)->isNullValue()) {
647 if (
StructType *STy = dyn_cast<StructType>(Ty))
648 if (!STy->isPacked()) {
649 ConstantInt *CI = cast<ConstantInt>(CE->getOperand(2));
651 STy->getNumElements() == 2 &&
652 STy->getElementType(0)->isIntegerTy(1)) {
657 if (Ty->isStructTy() || Ty->isArrayTy()) {
666 case Instruction::UIToFP:
667 case Instruction::SIToFP:
669 const APInt &api = CI->getValue();
682 case Instruction::ZExt:
686 CI->getValue().zext(BitWidth));
689 case Instruction::SExt:
693 CI->getValue().sext(BitWidth));
696 case Instruction::Trunc: {
703 CI->getValue().trunc(DestBitWidth));
709 if ((DestBitWidth & 7) == 0 &&
716 case Instruction::BitCast:
718 case Instruction::AddrSpaceCast:
740 if (V1Element == V2Element) {
742 }
else if (isa<UndefValue>(Cond)) {
743 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
745 if (!isa<ConstantInt>(Cond))
break;
756 if (isa<UndefValue>(Cond)) {
757 if (isa<UndefValue>(V1))
return V1;
760 if (isa<UndefValue>(V1))
return V2;
761 if (isa<UndefValue>(V2))
return V1;
762 if (V1 == V2)
return V1;
764 if (
ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) {
766 if (TrueVal->getOperand(0) == Cond)
769 if (
ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) {
771 if (FalseVal->getOperand(0) == Cond)
780 if (isa<UndefValue>(Val))
785 if (isa<UndefValue>(Idx))
788 if (
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
800 if (isa<UndefValue>(Idx))
804 if (!CIdx)
return nullptr;
807 if (CIdx->uge(NumElts))
813 uint64_t IdxVal = CIdx->getZExtValue();
814 for (
unsigned i = 0; i != NumElts; ++i) {
834 if (isa<UndefValue>(Mask))
838 if (isa<ConstantExpr>(Mask))
return nullptr;
844 for (
unsigned i = 0; i != MaskNumElts; ++i) {
851 if (
unsigned(Elt) >= SrcNumElts*2)
853 else if (
unsigned(Elt) >= SrcNumElts) {
889 NumElts =
ST->getNumElements();
891 NumElts = cast<SequentialType>(Agg->
getType())->getNumElements();
894 for (
unsigned i = 0; i != NumElts; ++i) {
896 if (!C)
return nullptr;
917 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
918 switch (static_cast<Instruction::BinaryOps>(Opcode)) {
919 case Instruction::Xor:
920 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
926 case Instruction::Sub:
928 case Instruction::And:
929 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
932 case Instruction::Mul: {
934 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
945 case Instruction::SDiv:
946 case Instruction::UDiv:
948 if (isa<UndefValue>(C2))
956 case Instruction::URem:
957 case Instruction::SRem:
966 case Instruction::Or:
967 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
970 case Instruction::LShr:
972 if (isa<UndefValue>(C2))
979 case Instruction::AShr:
981 if (isa<UndefValue>(C2))
989 case Instruction::Shl:
991 if (isa<UndefValue>(C2))
998 case Instruction::FAdd:
999 case Instruction::FSub:
1000 case Instruction::FMul:
1001 case Instruction::FDiv:
1002 case Instruction::FRem:
1005 case Instruction::BinaryOpsEnd:
1011 assert(!isa<UndefValue>(C1) && !isa<UndefValue>(C2) &&
1012 "Unexpected UndefValue");
1015 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1018 if (CI2->isZero())
return C1;
1020 case Instruction::Sub:
1021 if (CI2->isZero())
return C1;
1023 case Instruction::Mul:
1024 if (CI2->isZero())
return C2;
1028 case Instruction::UDiv:
1029 case Instruction::SDiv:
1035 case Instruction::URem:
1036 case Instruction::SRem:
1042 case Instruction::And:
1043 if (CI2->isZero())
return C2;
1044 if (CI2->isMinusOne())
1049 if (CE1->getOpcode() == Instruction::ZExt) {
1050 unsigned DstWidth = CI2->
getType()->getBitWidth();
1054 if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
1059 if (CE1->getOpcode() == Instruction::PtrToInt &&
1060 isa<GlobalValue>(CE1->getOperand(0))) {
1061 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
1065 if (isa<Function>(GV))
1069 unsigned DstWidth = CI2->getType()->getBitWidth();
1074 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
1080 case Instruction::Or:
1081 if (CI2->isZero())
return C1;
1082 if (CI2->isMinusOne())
1085 case Instruction::Xor:
1086 if (CI2->isZero())
return C1;
1089 switch (CE1->getOpcode()) {
1091 case Instruction::ICmp:
1092 case Instruction::FCmp:
1098 CE1->getOperand(1));
1102 case Instruction::AShr:
1105 if (CE1->getOpcode() == Instruction::ZExt)
1109 }
else if (isa<ConstantInt>(C1)) {
1115 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
1116 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1117 const APInt &C1V = CI1->getValue();
1118 const APInt &C2V = CI2->getValue();
1124 case Instruction::Sub:
1126 case Instruction::Mul:
1128 case Instruction::UDiv:
1129 assert(!CI2->isZero() &&
"Div by zero handled above");
1131 case Instruction::SDiv:
1132 assert(!CI2->isZero() &&
"Div by zero handled above");
1136 case Instruction::URem:
1137 assert(!CI2->isZero() &&
"Div by zero handled above");
1139 case Instruction::SRem:
1140 assert(!CI2->isZero() &&
"Div by zero handled above");
1144 case Instruction::And:
1146 case Instruction::Or:
1148 case Instruction::Xor:
1150 case Instruction::Shl:
1154 case Instruction::LShr:
1158 case Instruction::AShr:
1166 case Instruction::SDiv:
1167 case Instruction::UDiv:
1168 case Instruction::URem:
1169 case Instruction::SRem:
1170 case Instruction::LShr:
1171 case Instruction::AShr:
1172 case Instruction::Shl:
1173 if (CI1->isZero())
return C1;
1178 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
1179 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
1180 const APFloat &C1V = CFP1->getValueAPF();
1181 const APFloat &C2V = CFP2->getValueAPF();
1186 case Instruction::FAdd:
1189 case Instruction::FSub:
1192 case Instruction::FMul:
1195 case Instruction::FDiv:
1198 case Instruction::FRem:
1207 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
1213 if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv ||
1214 Opcode == Instruction::SRem || Opcode == Instruction::URem) &&
1233 if (!isa<ConstantExpr>(T) || cast<ConstantExpr>(
T)->getOpcode() != Opcode)
1236 }
else if (isa<ConstantExpr>(C2)) {
1247 case Instruction::Sub:
1249 case Instruction::Mul:
1251 case Instruction::Shl:
1252 case Instruction::LShr:
1253 case Instruction::AShr:
1257 case Instruction::SDiv:
1258 case Instruction::UDiv:
1262 case Instruction::URem:
1263 case Instruction::SRem:
1279 if (
StructType *STy = dyn_cast<StructType>(Ty)) {
1280 if (STy->isOpaque())
return true;
1283 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
1287 }
else if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
1301 if (C1 == C2)
return 0;
1305 if (!isa<ConstantInt>(C1) || !isa<ConstantInt>(C2))
1309 if (cast<ConstantInt>(C1)->getValue().getActiveBits() > 64 ||
1310 cast<ConstantInt>(C2)->getValue().getActiveBits() > 64)
1315 int64_t C1Val = cast<ConstantInt>(C1)->getSExtValue();
1316 int64_t C2Val = cast<ConstantInt>(C2)->getSExtValue();
1318 if (C1Val == C2Val)
return 0;
1346 "Cannot compare values of different types!");
1351 if (!isa<ConstantExpr>(V1)) {
1352 if (!isa<ConstantExpr>(V2)) {
1381 case Instruction::FPTrunc:
1382 case Instruction::FPExt:
1383 case Instruction::UIToFP:
1384 case Instruction::SIToFP:
1398 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
1399 if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage())
1401 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
1402 Type *Ty = GVar->getValueType();
1414 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
1415 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
1435 "Cannot compare different types of values!");
1438 if (!isa<ConstantExpr>(V1) && !isa<GlobalValue>(V1) &&
1439 !isa<BlockAddress>(V1)) {
1440 if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(
V2) &&
1441 !isa<BlockAddress>(V2)) {
1468 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1469 if (isa<ConstantExpr>(V2)) {
1480 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1482 }
else if (isa<BlockAddress>(V2)) {
1485 assert(isa<ConstantPointerNull>(V2) &&
"Canonicalization guarantee!");
1488 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV))
1491 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1492 if (isa<ConstantExpr>(V2)) {
1503 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1507 if (BA2->getFunction() != BA->getFunction())
1511 assert((isa<ConstantPointerNull>(V2) || isa<GlobalValue>(V2)) &&
1512 "Canonicalization guarantee!");
1522 case Instruction::Trunc:
1523 case Instruction::FPTrunc:
1524 case Instruction::FPExt:
1525 case Instruction::FPToUI:
1526 case Instruction::FPToSI:
1529 case Instruction::UIToFP:
1530 case Instruction::SIToFP:
1531 case Instruction::BitCast:
1532 case Instruction::ZExt:
1533 case Instruction::SExt:
1535 if (CE1Op0->getType()->isFloatingPointTy())
1542 if (CE1->
getOpcode() == Instruction::ZExt) isSigned =
false;
1543 if (CE1->
getOpcode() == Instruction::SExt) isSigned =
true;
1550 case Instruction::GetElementPtr: {
1554 if (isa<ConstantPointerNull>(V2)) {
1557 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1558 if (GV->hasExternalWeakLinkage())
1566 }
else if (isa<ConstantPointerNull>(CE1Op0)) {
1577 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1578 if (isa<ConstantPointerNull>(CE1Op0)) {
1579 if (GV2->hasExternalWeakLinkage())
1587 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1595 "Surprising getelementptr!");
1611 case Instruction::GetElementPtr:
1614 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1616 if (CE1Op0 != CE2Op0) {
1620 cast<GlobalValue>(CE2Op0));
1682 VT->getNumElements());
1694 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1705 if (isIntegerPredicate)
1715 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
1717 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1725 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
1727 if (!isa<GlobalAlias>(GV) && !GV->hasExternalWeakLinkage()) {
1739 if (isa<ConstantInt>(C2))
1749 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1750 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1751 const APInt &
V2 = cast<ConstantInt>(C2)->getValue();
1765 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1766 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1767 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1829 (isa<ConstantExpr>(C1) || isa<ConstantExpr>(C2))) {
1963 if (CE2->getOpcode() == Instruction::BitCast &&
1972 if ((CE1->getOpcode() == Instruction::SExt &&
1974 (CE1->getOpcode() == Instruction::ZExt &&
1978 if (CE1Inverse == CE1Op0) {
1988 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
2001 template<
typename IndexTy>
2004 if (Idxs.
empty())
return true;
2007 if (cast<Constant>(Idxs[0])->isNullValue())
return true;
2011 if (!cast<ConstantInt>(Idxs[0])->isOne())
2013 for (
unsigned i = 1, e = Idxs.
size(); i != e; ++i)
2014 if (!cast<Constant>(Idxs[i])->isNullValue())
2029 if (IndexVal < 0 || (NumElements > 0 && (uint64_t)IndexVal >= NumElements))
2040 if (Idxs.
empty())
return C;
2042 if (isa<UndefValue>(C)) {
2048 Constant *Idx0 = cast<Constant>(Idxs[0]);
2049 if (Idxs.
size() == 1 && (Idx0->
isNullValue() || isa<UndefValue>(Idx0)))
2054 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2055 if (!isa<UndefValue>(Idxs[i]) &&
2056 !cast<Constant>(Idxs[i])->isNullValue()) {
2064 assert(Ty &&
"Invalid indices for GEP!");
2077 if (CE->getOpcode() == Instruction::GetElementPtr) {
2102 bool PerformFold =
false;
2106 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idx0))
2110 !CE->getOperand(CE->getNumOperands() - 1)
2116 NewIndices.
reserve(Idxs.
size() + CE->getNumOperands());
2117 NewIndices.
append(CE->op_begin() + 1, CE->op_end() - 1);
2121 Constant *Combined = CE->getOperand(CE->getNumOperands()-1);
2125 if (IdxTy != Idx0->
getType()) {
2126 unsigned CommonExtendedWidth =
2129 CommonExtendedWidth =
std::max(CommonExtendedWidth, 64U);
2149 if (IRIndex && *IRIndex == CE->getNumOperands() - 2 && !Idx0->
isNullValue())
2153 cast<GEPOperator>(CE)->getSourceElementType(), CE->getOperand(0),
2154 NewIndices, InBounds && cast<GEPOperator>(CE)->isInBounds(),
2172 if (SrcPtrTy && DstPtrTy) {
2177 if (SrcArrayTy && DstArrayTy
2182 Idxs, InBounds, InRangeIndex);
2191 Type *Ty = PointeeTy;
2193 bool Unknown = !isa<ConstantInt>(Idxs[0]);
2194 for (
unsigned i = 1, e = Idxs.
size(); i != e;
2195 Prev = Ty, Ty = cast<CompositeType>(Ty)->getTypeAtIndex(Idxs[i]), ++i) {
2202 if (InRangeIndex && i == *InRangeIndex + 1) {
2208 if (isa<StructType>(Ty)) {
2212 auto *STy = cast<SequentialType>(Ty);
2213 if (isa<VectorType>(STy)) {
2221 if (isa<StructType>(Prev)) {
2227 if (CI->getSExtValue() < 0) {
2236 uint64_t NumElements = STy->getArrayNumElements();
2241 Constant *PrevIdx = NewIdxs[i-1] ? NewIdxs[i-1] :
2242 cast<Constant>(Idxs[i - 1]);
2245 unsigned CommonExtendedWidth =
2247 Div->getType()->getIntegerBitWidth());
2248 CommonExtendedWidth =
std::max(CommonExtendedWidth, 64U);
2255 if (!Div->getType()->isIntegerTy(CommonExtendedWidth))
2263 if (!NewIdxs.
empty()) {
2264 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i)
2265 if (!NewIdxs[i]) NewIdxs[i] = cast<Constant>(Idxs[i]);
2272 if (!Unknown && !InBounds)
2273 if (
auto *GV = dyn_cast<GlobalVariable>(C))
2276 true, InRangeIndex);
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static const fltSemantics & IEEEquad() LLVM_READNONE
static Constant * FoldBitCast(Constant *V, Type *DestTy)
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)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
match_zero m_Zero()
Match an arbitrary zero/null constant.
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 tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
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)
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.
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
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
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 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...
static const fltSemantics & IEEEdouble() LLVM_READNONE
opStatus convertToInteger(MutableArrayRef< integerPart > Input, unsigned int Width, bool IsSigned, roundingMode RM, bool *IsExact) const
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
Type * getElementType() const
size_t size() const
size - Get the array size.
Class to represent pointers.
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)
Attempt to constant fold a shufflevector instruction with the specified operands and indices...
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)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ConstantFP - Floating Point Values [float, double].
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
bool isIntPredicate() const
bool sle(const APInt &RHS) const
Signed less or equal comparison.
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
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...
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
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...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
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.
LLVMContext & getContext() const
All values hold a context through their type.
static wasm::ValType getType(const TargetRegisterClass *RC)
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
1 1 0 1 True if unordered, less than, or equal
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 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.
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.
static const fltSemantics & IEEEhalf() LLVM_READNONE
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.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
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)
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)
Return 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)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
llvm_unreachable("Unknown RegBank!")
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...
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
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.
match_one m_One()
Match an integer 1 or a vector with all elements equal to 1.
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
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
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
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
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
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
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)
bool slt(const APInt &RHS) const
Signed less than comparison.