50 if (isa<ScalableVectorType>(DstTy))
56 unsigned NumElts = cast<FixedVectorType>(DstTy)->getNumElements();
57 if (NumElts != cast<FixedVectorType>(CV->
getType())->getNumElements())
60 Type *DstEltTy = DstTy->getElementType();
69 for (
unsigned i = 0; i != NumElts; ++i) {
89 assert(Op && Op->isCast() &&
"Can't fold cast of cast without a cast!");
91 assert(CastInst::isCast(opc) &&
"Invalid cast opcode");
94 Type *SrcTy = Op->getOperand(0)->getType();
95 Type *MidTy = Op->getType();
106 nullptr, FakeIntPtrTy,
nullptr);
110 Type *SrcTy = V->getType();
116 if (
PointerType *PTy = dyn_cast<PointerType>(V->getType()))
117 if (
PointerType *DPTy = dyn_cast<PointerType>(DestTy))
118 if (PTy->getAddressSpace() == DPTy->getAddressSpace() &&
119 !PTy->isOpaque() && !DPTy->isOpaque() &&
120 PTy->getNonOpaquePointerElementType()->isSized()) {
134 PTy->getNonOpaquePointerElementType(), V, IdxList);
139 if (
VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
140 if (
VectorType *SrcTy = dyn_cast<VectorType>(V->getType())) {
141 assert(DestPTy->getPrimitiveSizeInBits() ==
143 "Not cast between same sized vectors!");
146 if (isa<ConstantAggregateZero>(V))
156 if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
162 if (isa<ConstantPointerNull>(V))
190 if (
FP->getType()->isPPC_FP128Ty())
198 FP->getValueAPF().bitcastToAPInt());
215 assert(
C->getType()->isIntegerTy() &&
216 (cast<IntegerType>(
C->getType())->getBitWidth() & 7) == 0 &&
217 "Non-byte sized integer input");
218 unsigned CSize = cast<IntegerType>(
C->getType())->getBitWidth()/8;
219 assert(ByteSize &&
"Must be accessing some piece");
220 assert(ByteStart+ByteSize <= CSize &&
"Extracting invalid piece from input");
221 assert(ByteSize != CSize &&
"Should not extract everything");
225 APInt V = CI->getValue();
227 V.lshrInPlace(ByteStart*8);
228 V = V.trunc(ByteSize*8);
235 if (!CE)
return nullptr;
237 switch (CE->getOpcode()) {
238 default:
return nullptr;
239 case Instruction::Or: {
246 if (RHSC->isMinusOne())
254 case Instruction::And: {
260 if (
RHS->isNullValue())
268 case Instruction::LShr: {
269 ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
274 if ((ShAmt & 7) != 0)
279 if (ShAmt.
uge(CSize - ByteStart))
283 if (ShAmt.
ule(CSize - (ByteStart + ByteSize)))
291 case Instruction::Shl: {
292 ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
297 if ((ShAmt & 7) != 0)
302 if (ShAmt.
uge(ByteStart + ByteSize))
306 if (ShAmt.
ule(ByteStart))
314 case Instruction::ZExt: {
315 unsigned SrcBitSize =
316 cast<IntegerType>(CE->getOperand(0)->getType())->getBitWidth();
319 if (ByteStart*8 >= SrcBitSize)
324 if (ByteStart == 0 && ByteSize*8 == SrcBitSize)
325 return CE->getOperand(0);
329 if ((SrcBitSize&7) == 0 && (ByteStart+ByteSize)*8 <= SrcBitSize)
334 if ((ByteStart+ByteSize)*8 < SrcBitSize) {
335 assert((SrcBitSize&7) &&
"Shouldn't get byte sized case here");
352 if (isa<PoisonValue>(V))
355 if (isa<UndefValue>(V)) {
359 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
360 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
366 opc != Instruction::AddrSpaceCast)
376 }
else if (CE->getOpcode() == Instruction::GetElementPtr &&
379 opc != Instruction::AddrSpaceCast &&
382 !cast<GEPOperator>(CE)->getInRangeIndex() &&
386 !CE->getType()->isVectorTy()) {
389 bool isAllNull =
true;
390 for (
unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
391 if (!CE->getOperand(i)->isNullValue()) {
404 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
406 cast<FixedVectorType>(DestTy)->getNumElements() ==
407 cast<FixedVectorType>(V->getType())->getNumElements()) {
408 VectorType *DestVecTy = cast<VectorType>(DestTy);
411 if (
Constant *Splat = V->getSplatValue()) {
413 cast<VectorType>(DestTy)->getElementCount(),
419 e = cast<FixedVectorType>(V->getType())->getNumElements();
433 case Instruction::FPTrunc:
434 case Instruction::FPExt:
435 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
437 APFloat Val = FPC->getValueAPF();
443 case Instruction::FPToUI:
444 case Instruction::FPToSI:
445 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
446 const APFloat &V = FPC->getValueAPF();
448 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
449 APSInt IntVal(DestBitWidth, opc == Instruction::FPToUI);
450 if (APFloat::opInvalidOp ==
451 V.convertToInteger(IntVal, APFloat::rmTowardZero, &
ignored)) {
459 case Instruction::IntToPtr:
460 if (V->isNullValue())
463 case Instruction::PtrToInt:
465 if (V->isNullValue())
469 case Instruction::UIToFP:
470 case Instruction::SIToFP:
472 const APInt &api = CI->getValue();
476 APFloat::rmNearestTiesToEven);
480 case Instruction::ZExt:
487 case Instruction::SExt:
494 case Instruction::Trunc: {
495 if (V->getType()->isVectorTy())
498 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
501 CI->getValue().trunc(DestBitWidth));
507 if ((DestBitWidth & 7) == 0 &&
508 (cast<IntegerType>(V->getType())->getBitWidth() & 7) == 0)
514 case Instruction::BitCast:
516 case Instruction::AddrSpaceCast:
524 if (
Cond->isNullValue())
return V2;
525 if (
Cond->isAllOnesValue())
return V1;
529 auto *V1VTy = CondV->
getType();
532 for (
unsigned i = 0, e = V1VTy->getNumElements(); i != e; ++i) {
538 auto *
Cond = cast<Constant>(CondV->getOperand(i));
539 if (isa<PoisonValue>(
Cond)) {
541 }
else if (V1Element == V2Element) {
543 }
else if (isa<UndefValue>(
Cond)) {
544 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
546 if (!isa<ConstantInt>(
Cond))
break;
547 V =
Cond->isNullValue() ? V2Element : V1Element;
553 if (Result.size() == V1VTy->getNumElements())
557 if (isa<PoisonValue>(
Cond))
560 if (isa<UndefValue>(
Cond)) {
561 if (isa<UndefValue>(V1))
return V1;
565 if (V1 == V2)
return V1;
567 if (isa<PoisonValue>(V1))
569 if (isa<PoisonValue>(V2))
575 if (isa<PoisonValue>(
C))
580 if (isa<ConstantExpr>(
C))
583 if (isa<ConstantInt>(
C) || isa<GlobalVariable>(
C) || isa<ConstantFP>(
C) ||
584 isa<ConstantPointerNull>(
C) || isa<Function>(
C))
587 if (
C->getType()->isVectorTy())
588 return !
C->containsPoisonElement() && !
C->containsConstantExpression();
593 if (isa<UndefValue>(V1) && NotPoison(V2))
return V2;
594 if (isa<UndefValue>(V2) && NotPoison(V1))
return V1;
601 auto *ValVTy = cast<VectorType>(Val->
getType());
605 if (isa<PoisonValue>(Val) || isa<UndefValue>(
Idx))
609 if (isa<UndefValue>(Val))
612 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
616 if (
auto *ValFVTy = dyn_cast<FixedVectorType>(Val->
getType())) {
618 if (CIdx->uge(ValFVTy->getNumElements()))
623 if (
auto *CE = dyn_cast<ConstantExpr>(Val)) {
624 if (
auto *
GEP = dyn_cast<GEPOperator>(CE)) {
626 Ops.
reserve(CE->getNumOperands());
627 for (
unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
629 if (Op->getType()->isVectorTy()) {
637 return CE->getWithOperands(Ops, ValVTy->getElementType(),
false,
638 GEP->getSourceElementType());
639 }
else if (CE->getOpcode() == Instruction::InsertElement) {
640 if (
const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) {
642 APSInt(CIdx->getValue()))) {
643 return CE->getOperand(1);
655 if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) {
666 if (isa<UndefValue>(
Idx))
671 if (isa<ConstantAggregateZero>(Val) && Elt->
isNullValue())
675 if (!CIdx)
return nullptr;
679 if (isa<ScalableVectorType>(Val->
getType()))
682 auto *ValTy = cast<FixedVectorType>(Val->
getType());
684 unsigned NumElts = ValTy->getNumElements();
685 if (CIdx->
uge(NumElts))
689 Result.reserve(NumElts);
692 for (
unsigned i = 0; i != NumElts; ++i) {
694 Result.push_back(Elt);
707 auto *V1VTy = cast<VectorType>(V1->
getType());
708 unsigned MaskNumElts = Mask.size();
711 Type *EltTy = V1VTy->getElementType();
720 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
726 auto *VTy = VectorType::get(EltTy, MaskEltCount);
728 }
else if (!MaskEltCount.isScalable())
733 if (isa<ScalableVectorType>(V1VTy))
736 unsigned SrcNumElts = V1VTy->getElementCount().getKnownMinValue();
740 for (
unsigned i = 0; i != MaskNumElts; ++i) {
747 if (
unsigned(Elt) >= SrcNumElts*2)
749 else if (
unsigned(Elt) >= SrcNumElts) {
758 Result.push_back(InElt);
785 NumElts = ST->getNumElements();
787 NumElts = cast<ArrayType>(Agg->
getType())->getNumElements();
790 for (
unsigned i = 0; i != NumElts; ++i) {
792 if (!
C)
return nullptr;
810 bool IsScalableVector = isa<ScalableVectorType>(
C->getType());
811 bool HasScalarUndefOrScalableVectorUndef =
812 (!
C->getType()->isVectorTy() || IsScalableVector) && isa<UndefValue>(
C);
814 if (HasScalarUndefOrScalableVectorUndef) {
816 case Instruction::FNeg:
818 case Instruction::UnaryOpsEnd:
824 assert(!HasScalarUndefOrScalableVectorUndef &&
"Unexpected UndefValue");
826 assert(!isa<ConstantInt>(
C) &&
"Unexpected Integer UnaryOp");
829 const APFloat &CV = CFP->getValueAPF();
833 case Instruction::FNeg:
836 }
else if (
auto *VTy = dyn_cast<FixedVectorType>(
C->getType())) {
840 if (
Constant *Splat =
C->getSplatValue())
846 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
852 Result.push_back(Res);
880 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
885 bool IsScalableVector = isa<ScalableVectorType>(C1->
getType());
886 bool HasScalarUndefOrScalableVectorUndef =
888 (isa<UndefValue>(C1) || isa<UndefValue>(C2));
889 if (HasScalarUndefOrScalableVectorUndef) {
891 case Instruction::Xor:
892 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
897 case Instruction::Add:
898 case Instruction::Sub:
900 case Instruction::And:
901 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
904 case Instruction::Mul: {
906 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
917 case Instruction::SDiv:
918 case Instruction::UDiv:
928 case Instruction::URem:
929 case Instruction::SRem:
936 case Instruction::Or:
937 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
940 case Instruction::LShr:
942 if (isa<UndefValue>(C2))
949 case Instruction::AShr:
951 if (isa<UndefValue>(C2))
959 case Instruction::Shl:
961 if (isa<UndefValue>(C2))
968 case Instruction::FSub:
973 case Instruction::FAdd:
974 case Instruction::FMul:
975 case Instruction::FDiv:
976 case Instruction::FRem:
978 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
988 case Instruction::BinaryOpsEnd:
994 assert((!HasScalarUndefOrScalableVectorUndef) &&
"Unexpected UndefValue");
997 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
999 case Instruction::Add:
1000 if (CI2->isZero())
return C1;
1002 case Instruction::Sub:
1003 if (CI2->isZero())
return C1;
1005 case Instruction::Mul:
1006 if (CI2->isZero())
return C2;
1010 case Instruction::UDiv:
1011 case Instruction::SDiv:
1017 case Instruction::URem:
1018 case Instruction::SRem:
1024 case Instruction::And:
1025 if (CI2->isZero())
return C2;
1026 if (CI2->isMinusOne())
1031 if (CE1->getOpcode() == Instruction::ZExt) {
1032 unsigned DstWidth = CI2->
getType()->getBitWidth();
1036 if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits)
1041 if (CE1->getOpcode() == Instruction::PtrToInt &&
1042 isa<GlobalValue>(CE1->getOperand(0))) {
1043 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
1060 if (isa<Function>(GV) && !
DL.getFunctionPtrAlign())
1062 }
else if (isa<GlobalVariable>(GV)) {
1063 GVAlign = cast<GlobalVariable>(GV)->getAlign().valueOrOne();
1067 unsigned DstWidth = CI2->getType()->getBitWidth();
1068 unsigned SrcWidth = std::min(DstWidth,
Log2(GVAlign));
1072 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
1078 case Instruction::Or:
1079 if (CI2->isZero())
return C1;
1080 if (CI2->isMinusOne())
1083 case Instruction::Xor:
1084 if (CI2->isZero())
return C1;
1087 switch (CE1->getOpcode()) {
1089 case Instruction::ICmp:
1090 case Instruction::FCmp:
1096 CE1->getOperand(1));
1100 case Instruction::AShr:
1103 if (CE1->getOpcode() == Instruction::ZExt)
1107 }
else if (isa<ConstantInt>(C1)) {
1113 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
1114 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
1115 const APInt &C1V = CI1->getValue();
1116 const APInt &C2V = CI2->getValue();
1120 case Instruction::Add:
1122 case Instruction::Sub:
1124 case Instruction::Mul:
1126 case Instruction::UDiv:
1127 assert(!CI2->isZero() &&
"Div by zero handled above");
1129 case Instruction::SDiv:
1130 assert(!CI2->isZero() &&
"Div by zero handled above");
1134 case Instruction::URem:
1135 assert(!CI2->isZero() &&
"Div by zero handled above");
1137 case Instruction::SRem:
1138 assert(!CI2->isZero() &&
"Div by zero handled above");
1142 case Instruction::And:
1144 case Instruction::Or:
1146 case Instruction::Xor:
1148 case Instruction::Shl:
1152 case Instruction::LShr:
1156 case Instruction::AShr:
1164 case Instruction::SDiv:
1165 case Instruction::UDiv:
1166 case Instruction::URem:
1167 case Instruction::SRem:
1168 case Instruction::LShr:
1169 case Instruction::AShr:
1170 case Instruction::Shl:
1171 if (CI1->isZero())
return C1;
1176 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
1177 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
1178 const APFloat &C1V = CFP1->getValueAPF();
1179 const APFloat &C2V = CFP2->getValueAPF();
1184 case Instruction::FAdd:
1185 (void)C3V.
add(C2V, APFloat::rmNearestTiesToEven);
1187 case Instruction::FSub:
1188 (void)C3V.
subtract(C2V, APFloat::rmNearestTiesToEven);
1190 case Instruction::FMul:
1191 (void)C3V.
multiply(C2V, APFloat::rmNearestTiesToEven);
1193 case Instruction::FDiv:
1194 (void)C3V.
divide(C2V, APFloat::rmNearestTiesToEven);
1196 case Instruction::FRem:
1201 }
else if (
auto *VTy = dyn_cast<VectorType>(C1->
getType())) {
1217 if (
auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
1221 for (
unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
1235 Result.push_back(Res);
1251 if (!isa<ConstantExpr>(
T) || cast<ConstantExpr>(
T)->
getOpcode() != Opcode)
1254 }
else if (isa<ConstantExpr>(C2)) {
1264 case Instruction::Add:
1265 case Instruction::Sub:
1267 case Instruction::Mul:
1269 case Instruction::Shl:
1270 case Instruction::LShr:
1271 case Instruction::AShr:
1275 case Instruction::SDiv:
1276 case Instruction::UDiv:
1280 case Instruction::URem:
1281 case Instruction::SRem:
1307 "Cannot compare values of different types!");
1311 if (V1 == V2)
return FCmpInst::FCMP_UEQ;
1313 if (!isa<ConstantExpr>(V1)) {
1314 if (!isa<ConstantExpr>(V2)) {
1317 R = dyn_cast<ConstantInt>(
1319 if (R && !R->isZero())
1320 return FCmpInst::FCMP_OEQ;
1321 R = dyn_cast<ConstantInt>(
1323 if (R && !R->isZero())
1324 return FCmpInst::FCMP_OLT;
1325 R = dyn_cast<ConstantInt>(
1327 if (R && !R->isZero())
1328 return FCmpInst::FCMP_OGT;
1331 return FCmpInst::BAD_FCMP_PREDICATE;
1336 if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE)
1337 return FCmpInst::getSwappedPredicate(SwappedRelation);
1343 case Instruction::FPTrunc:
1344 case Instruction::FPExt:
1345 case Instruction::UIToFP:
1346 case Instruction::SIToFP:
1355 return FCmpInst::BAD_FCMP_PREDICATE;
1360 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
1361 if (GV->isInterposable() || GV->hasGlobalUnnamedAddr())
1363 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
1364 Type *Ty = GVar->getValueType();
1376 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
1377 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
1378 return ICmpInst::ICMP_NE;
1379 return ICmpInst::BAD_ICMP_PREDICATE;
1397 "Cannot compare different types of values!");
1398 if (V1 == V2)
return ICmpInst::ICMP_EQ;
1400 if (!isa<ConstantExpr>(V1) && !isa<GlobalValue>(V1) &&
1401 !isa<BlockAddress>(V1)) {
1402 if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(V2) &&
1403 !isa<BlockAddress>(V2)) {
1409 if (R && !R->isZero())
1411 pred =
isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
1413 if (R && !R->isZero())
1415 pred =
isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
1417 if (R && !R->isZero())
1421 return ICmpInst::BAD_ICMP_PREDICATE;
1427 if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
1428 return ICmpInst::getSwappedPredicate(SwappedRelation);
1430 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1431 if (isa<ConstantExpr>(V2)) {
1434 if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
1435 return ICmpInst::getSwappedPredicate(SwappedRelation);
1436 return ICmpInst::BAD_ICMP_PREDICATE;
1442 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1444 }
else if (isa<BlockAddress>(V2)) {
1445 return ICmpInst::ICMP_NE;
1447 assert(isa<ConstantPointerNull>(V2) &&
"Canonicalization guarantee!");
1453 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV) &&
1455 GV->getType()->getAddressSpace()))
1456 return ICmpInst::ICMP_UGT;
1458 }
else if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1459 if (isa<ConstantExpr>(V2)) {
1462 if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
1463 return ICmpInst::getSwappedPredicate(SwappedRelation);
1464 return ICmpInst::BAD_ICMP_PREDICATE;
1470 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1474 if (BA2->getFunction() != BA->getFunction())
1475 return ICmpInst::ICMP_NE;
1478 assert((isa<ConstantPointerNull>(V2) || isa<GlobalValue>(V2)) &&
1479 "Canonicalization guarantee!");
1480 return ICmpInst::ICMP_NE;
1489 case Instruction::Trunc:
1490 case Instruction::FPTrunc:
1491 case Instruction::FPExt:
1492 case Instruction::FPToUI:
1493 case Instruction::FPToSI:
1496 case Instruction::BitCast:
1499 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0))
1500 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2))
1503 case Instruction::UIToFP:
1504 case Instruction::SIToFP:
1505 case Instruction::ZExt:
1506 case Instruction::SExt:
1522 case Instruction::GetElementPtr: {
1526 if (isa<ConstantPointerNull>(V2)) {
1529 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1532 if (!GV->hasExternalWeakLinkage() && CE1GEP->
isInBounds())
1533 return ICmpInst::ICMP_UGT;
1535 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1536 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1540 return ICmpInst::BAD_ICMP_PREDICATE;
1543 }
else if (
const auto *CE2GEP = dyn_cast<GEPOperator>(V2)) {
1546 const Constant *CE2Op0 = cast<Constant>(CE2GEP->getPointerOperand());
1547 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1549 if (CE1Op0 != CE2Op0) {
1552 cast<GlobalValue>(CE2Op0));
1553 return ICmpInst::BAD_ICMP_PREDICATE;
1564 return ICmpInst::BAD_ICMP_PREDICATE;
1569 const GlobalValue *GV = dyn_cast<GlobalValue>(C2);
1577 if (Predicate == ICmpInst::ICMP_EQ)
1579 else if (Predicate == ICmpInst::ICMP_NE)
1591 VT->getElementCount());
1596 if (Predicate == FCmpInst::FCMP_FALSE)
1599 if (Predicate == FCmpInst::FCMP_TRUE)
1603 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
1606 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1607 bool isIntegerPredicate = ICmpInst::isIntPredicate(Predicate);
1616 if (isIntegerPredicate)
1636 if (Predicate == ICmpInst::ICMP_UGE)
1639 if (Predicate == ICmpInst::ICMP_ULT)
1645 switch (Predicate) {
1646 case ICmpInst::ICMP_EQ:
1647 if (isa<ConstantInt>(C2))
1650 case ICmpInst::ICMP_NE:
1657 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1658 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1659 const APInt &V2 = cast<ConstantInt>(C2)->getValue();
1661 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1662 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1663 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1665 }
else if (
auto *C1VTy = dyn_cast<VectorType>(C1->
getType())) {
1671 C1VTy->getElementCount(),
1676 if (isa<ScalableVectorType>(C1VTy))
1684 for (
unsigned I = 0,
E = C1VTy->getElementCount().getKnownMinValue();
1700 (isa<ConstantExpr>(C1) || isa<ConstantExpr>(C2))) {
1704 case FCmpInst::FCMP_UNO:
1705 case FCmpInst::FCMP_ORD:
1706 case FCmpInst::FCMP_UNE:
1707 case FCmpInst::FCMP_ULT:
1708 case FCmpInst::FCMP_UGT:
1709 case FCmpInst::FCMP_ULE:
1710 case FCmpInst::FCMP_UGE:
1711 case FCmpInst::FCMP_TRUE:
1712 case FCmpInst::FCMP_FALSE:
1713 case FCmpInst::BAD_FCMP_PREDICATE:
1715 case FCmpInst::FCMP_OEQ:
1717 (Predicate == FCmpInst::FCMP_UEQ || Predicate == FCmpInst::FCMP_OEQ ||
1718 Predicate == FCmpInst::FCMP_ULE || Predicate == FCmpInst::FCMP_OLE ||
1719 Predicate == FCmpInst::FCMP_UGE || Predicate == FCmpInst::FCMP_OGE);
1721 case FCmpInst::FCMP_OLT:
1723 (Predicate == FCmpInst::FCMP_UNE || Predicate == FCmpInst::FCMP_ONE ||
1724 Predicate == FCmpInst::FCMP_ULT || Predicate == FCmpInst::FCMP_OLT ||
1725 Predicate == FCmpInst::FCMP_ULE || Predicate == FCmpInst::FCMP_OLE);
1727 case FCmpInst::FCMP_OGT:
1729 (Predicate == FCmpInst::FCMP_UNE || Predicate == FCmpInst::FCMP_ONE ||
1730 Predicate == FCmpInst::FCMP_UGT || Predicate == FCmpInst::FCMP_OGT ||
1731 Predicate == FCmpInst::FCMP_UGE || Predicate == FCmpInst::FCMP_OGE);
1733 case FCmpInst::FCMP_OLE:
1735 if (Predicate == FCmpInst::FCMP_UGT || Predicate == FCmpInst::FCMP_OGT)
1737 else if (Predicate == FCmpInst::FCMP_ULT ||
1738 Predicate == FCmpInst::FCMP_OLT)
1741 case FCmpInst::FCMP_OGE:
1743 if (Predicate == FCmpInst::FCMP_ULT || Predicate == FCmpInst::FCMP_OLT)
1745 else if (Predicate == FCmpInst::FCMP_UGT ||
1746 Predicate == FCmpInst::FCMP_OGT)
1749 case FCmpInst::FCMP_ONE:
1751 if (Predicate == FCmpInst::FCMP_OEQ || Predicate == FCmpInst::FCMP_UEQ)
1753 else if (Predicate == FCmpInst::FCMP_ONE ||
1754 Predicate == FCmpInst::FCMP_UNE)
1757 case FCmpInst::FCMP_UEQ:
1759 if (Predicate == FCmpInst::FCMP_ONE)
1761 else if (Predicate == FCmpInst::FCMP_UEQ)
1775 case ICmpInst::BAD_ICMP_PREDICATE:
1777 case ICmpInst::ICMP_EQ:
1780 Result = ICmpInst::isTrueWhenEqual(Predicate);
1782 case ICmpInst::ICMP_ULT:
1783 switch (Predicate) {
1784 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_ULE:
1786 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_UGE:
1792 case ICmpInst::ICMP_SLT:
1793 switch (Predicate) {
1794 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SLE:
1796 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SGE:
1802 case ICmpInst::ICMP_UGT:
1803 switch (Predicate) {
1804 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_UGE:
1806 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_ULE:
1812 case ICmpInst::ICMP_SGT:
1813 switch (Predicate) {
1814 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SGE:
1816 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SLE:
1822 case ICmpInst::ICMP_ULE:
1823 if (Predicate == ICmpInst::ICMP_UGT)
1825 if (Predicate == ICmpInst::ICMP_ULT || Predicate == ICmpInst::ICMP_ULE)
1828 case ICmpInst::ICMP_SLE:
1829 if (Predicate == ICmpInst::ICMP_SGT)
1831 if (Predicate == ICmpInst::ICMP_SLT || Predicate == ICmpInst::ICMP_SLE)
1834 case ICmpInst::ICMP_UGE:
1835 if (Predicate == ICmpInst::ICMP_ULT)
1837 if (Predicate == ICmpInst::ICMP_UGT || Predicate == ICmpInst::ICMP_UGE)
1840 case ICmpInst::ICMP_SGE:
1841 if (Predicate == ICmpInst::ICMP_SLT)
1843 if (Predicate == ICmpInst::ICMP_SGT || Predicate == ICmpInst::ICMP_SGE)
1846 case ICmpInst::ICMP_NE:
1847 if (Predicate == ICmpInst::ICMP_EQ)
1849 if (Predicate == ICmpInst::ICMP_NE)
1864 if (CE2->getOpcode() == Instruction::BitCast &&
1874 if ((CE1->getOpcode() == Instruction::SExt &&
1875 ICmpInst::isSigned(Predicate)) ||
1876 (CE1->getOpcode() == Instruction::ZExt &&
1877 !ICmpInst::isSigned(Predicate))) {
1880 if (CE1Inverse == CE1Op0) {
1890 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
1895 Predicate = ICmpInst::getSwappedPredicate(Predicate);
1903template<
typename IndexTy>
1906 if (Idxs.
empty())
return true;
1909 if (cast<Constant>(Idxs[0])->isNullValue())
return true;
1913 if (
auto *CI = dyn_cast<ConstantInt>(Idxs[0])) {
1917 auto *CV = cast<ConstantDataVector>(Idxs[0]);
1918 CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue());
1919 if (!CI || !CI->isOne())
1923 for (
unsigned i = 1, e = Idxs.
size(); i != e; ++i)
1924 if (!cast<Constant>(Idxs[i])->isNullValue())
1939 if (IndexVal < 0 || (IndexVal != 0 && (
uint64_t)IndexVal >= NumElements))
1951 if (PointeeTy !=
GEP->getResultElementType())
1954 Constant *Idx0 = cast<Constant>(Idxs[0]);
1962 GEP->getSourceElementType(), cast<Constant>(
GEP->getPointerOperand()),
1963 NewIndices, InBounds &&
GEP->isInBounds(),
GEP->getInRangeIndex());
1981 auto *LastIdx = cast<Constant>(
GEP->getOperand(
GEP->getNumOperands()-1));
1982 Type *LastIdxTy = LastIdx->getType();
1988 NewIndices.
append(
GEP->idx_begin(),
GEP->idx_end() - 1);
1992 if (LastIdxTy != Idx0->
getType()) {
1993 unsigned CommonExtendedWidth =
1996 CommonExtendedWidth = std::max(CommonExtendedWidth, 64U);
2010 std::optional<unsigned> IRIndex =
GEP->getInRangeIndex();
2011 if (IRIndex && *IRIndex ==
GEP->getNumIndices() - 1)
2012 IRIndex = std::nullopt;
2015 GEP->getSourceElementType(), cast<Constant>(
GEP->getPointerOperand()),
2016 NewIndices, InBounds &&
GEP->isInBounds(), IRIndex);
2021 std::optional<unsigned> InRangeIndex,
2023 if (Idxs.
empty())
return C;
2028 if (isa<PoisonValue>(
C))
2031 if (isa<UndefValue>(
C))
2035 auto IsNoOp = [&]() {
2038 if (!
C->getType()->getScalarType()->isOpaquePointerTy() && Idxs.
size() != 1)
2047 return IdxC->
isNullValue() || isa<UndefValue>(IdxC);
2051 return GEPTy->
isVectorTy() && !
C->getType()->isVectorTy()
2053 cast<VectorType>(GEPTy)->getElementCount(),
C)
2056 if (
C->isNullValue()) {
2059 if (!isa<UndefValue>(
Idx) && !cast<Constant>(
Idx)->isNullValue()) {
2064 PointerType *PtrTy = cast<PointerType>(
C->getType()->getScalarType());
2067 assert(Ty &&
"Invalid indices for GEP!");
2070 if (
VectorType *VT = dyn_cast<VectorType>(
C->getType()))
2071 GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount());
2076 if (
auto *VT = dyn_cast<VectorType>(
Idx->getType())) {
2077 assert((!isa<VectorType>(GEPTy) || isa<ScalableVectorType>(GEPTy) ==
2078 isa<ScalableVectorType>(VT)) &&
2079 "Mismatched GEPTy vector types");
2080 GEPTy = VectorType::get(OrigGEPTy, VT->getElementCount());
2090 if (
auto *
GEP = dyn_cast<GEPOperator>(CE))
2103 Constant *Idx0 = cast<Constant>(Idxs[0]);
2106 dyn_cast<PointerType>(CE->getOperand(0)->getType());
2107 PointerType *DstPtrTy = dyn_cast<PointerType>(CE->getType());
2108 if (SrcPtrTy && DstPtrTy && !SrcPtrTy->
isOpaque() &&
2114 if (SrcArrayTy && DstArrayTy
2119 Idxs, InBounds, InRangeIndex);
2128 Type *Ty = PointeeTy;
2129 Type *Prev =
C->getType();
2132 !isa<ConstantInt>(Idxs[0]) && !isa<ConstantDataVector>(Idxs[0]);
2133 for (
unsigned i = 1, e = Idxs.
size(); i != e;
2134 Prev = Ty, Ty = (++GEPIter).getIndexedType(), ++i) {
2135 if (!isa<ConstantInt>(Idxs[i]) && !isa<ConstantDataVector>(Idxs[i])) {
2140 if (!isa<ConstantInt>(Idxs[i - 1]) && !isa<ConstantDataVector>(Idxs[i - 1]))
2143 if (InRangeIndex && i == *InRangeIndex + 1) {
2149 if (isa<StructType>(Ty)) {
2153 if (isa<VectorType>(Ty)) {
2158 auto *STy = cast<ArrayType>(Ty);
2159 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Idxs[i])) {
2163 if (CI->isNegative()) {
2169 auto *CV = cast<ConstantDataVector>(Idxs[i]);
2171 for (
unsigned I = 0,
E = CV->getNumElements();
I !=
E; ++
I) {
2172 auto *CI = cast<ConstantInt>(CV->getElementAsConstant(
I));
2174 if (CI->isNegative()) {
2184 if (isa<StructType>(Prev)) {
2192 uint64_t NumElements = STy->getArrayNumElements();
2204 Constant *CurrIdx = cast<Constant>(Idxs[i]);
2206 NewIdxs[i - 1] ? NewIdxs[i - 1] : cast<Constant>(Idxs[i - 1]);
2208 bool IsPrevIdxVector = PrevIdx->getType()->isVectorTy();
2209 bool UseVector = IsCurrIdxVector || IsPrevIdxVector;
2211 if (!IsCurrIdxVector && IsPrevIdxVector)
2213 cast<FixedVectorType>(PrevIdx->getType())->getNumElements(), CurrIdx);
2215 if (!IsPrevIdxVector && IsCurrIdxVector)
2217 cast<FixedVectorType>(CurrIdx->
getType())->getNumElements(), PrevIdx);
2224 ? cast<FixedVectorType>(PrevIdx->getType())->getNumElements()
2225 : cast<FixedVectorType>(CurrIdx->
getType())->getNumElements(),
2236 assert(NewIdxs[i] !=
nullptr && Div !=
nullptr &&
"Should have folded");
2238 unsigned CommonExtendedWidth =
2239 std::max(PrevIdx->getType()->getScalarSizeInBits(),
2241 CommonExtendedWidth = std::max(CommonExtendedWidth, 64U);
2250 ? cast<FixedVectorType>(PrevIdx->getType())->getNumElements()
2251 : cast<FixedVectorType>(CurrIdx->
getType())->getNumElements());
2253 if (!PrevIdx->getType()->isIntOrIntVectorTy(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]);
2273 if (
auto *GV = dyn_cast<GlobalVariable>(
C))
2274 if (!GV->hasExternalWeakLinkage() && GV->getValueType() == PointeeTy &&
2277 true, InRangeIndex);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
SmallVector< MachineOperand, 4 > Cond
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static unsigned foldConstantCastPair(unsigned opc, ConstantExpr *Op, Type *DstTy)
This function determines which opcode to use to fold two constant cast expressions together.
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 ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, const GlobalValue *GV2)
static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2)
This function determines if there is anything we can decide about the two constants provided.
static Constant * constantFoldCompareGlobalToNull(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
static Constant * FoldBitCast(Constant *V, Type *DestTy)
static bool isIndexInRangeOfArrayType(uint64_t NumElements, const ConstantInt *CI)
Test whether a given ConstantInt is in-range for a SequentialType.
static Constant * foldGEPOfGEP(GEPOperator *GEP, Type *PointeeTy, bool InBounds, ArrayRef< Value * > Idxs)
static bool isInBoundsIndices(ArrayRef< IndexTy > Idxs)
Test whether the given sequence of normalized indices is "inbounds".
static Constant * BitCastConstantVector(Constant *CV, VectorType *DstTy)
Convert the specified vector Constant node to the specified vector type.
static Constant * ExtractConstantBytes(Constant *C, unsigned ByteStart, unsigned ByteSize)
V is an integer constant which only has a subset of its bytes used.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
static bool isSigned(unsigned int Opcode)
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
opStatus divide(const APFloat &RHS, roundingMode RM)
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
opStatus subtract(const APFloat &RHS, roundingMode RM)
opStatus add(const APFloat &RHS, roundingMode RM)
opStatus convertFromAPInt(const APInt &Input, bool IsSigned, roundingMode RM)
opStatus multiply(const APFloat &RHS, roundingMode RM)
opStatus mod(const APFloat &RHS)
Class for arbitrary precision integers.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
uint64_t getZExtValue() const
Get zero extended value.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
unsigned getBitWidth() const
Return the number of bits in the APInt.
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
unsigned getSignificantBits() const
Get the minimum bit size for this signed APInt.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
APInt shl(unsigned shiftAmt) const
Left-shift function.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
An arbitrary precision integer that knows its signedness.
static bool isSameValue(const APSInt &I1, const APSInt &I2)
Determine if two APSInts have the same value, zero- or sign-extending as needed.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
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.
Class to represent array types.
Type * getElementType() const
The address of a basic block.
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
This enumeration lists the possible predicates for CmpInst subclasses.
bool isTrueWhenEqual() const
This is just a convenience.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
static ConstantAggregateZero * get(Type *Ty)
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
A constant value that is initialized with an expression using other constant values.
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getNot(Constant *C)
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 Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, std::optional< unsigned > InRangeIndex=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getXor(Constant *C1, Constant *C2)
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
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 bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static Constant * getOr(Constant *C1, Constant *C2)
static Constant * getAnd(Constant *C1, Constant *C2)
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
ConstantFP - Floating Point Values [float, double].
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...
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
This is the shared class of boolean and integer constants.
static ConstantInt * getTrue(LLVMContext &Context)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantInt * getFalse(LLVMContext &Context)
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
bool uge(uint64_t Num) const
This function will return true iff this constant represents a value with active bits bigger than 64 b...
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
Constant Vector Declarations.
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
static Constant * getAllOnesValue(Type *Ty)
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
static bool compare(const APFloat &LHS, const APFloat &RHS, FCmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
bool hasAllZeroIndices() const
Return true if all of the indices of this GEP are zeros.
static Type * getTypeAtIndex(Type *Ty, Value *Idx)
Return the type of the element at the given index of an indexable type.
static Type * getGEPReturnType(Type *ElTy, Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
bool hasExternalWeakLinkage() const
Module * getParent()
Get the module that this global value is contained inside of...
PointerType * getType() const
Global values are always pointers.
static bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
bool isEquality() const
Return true if this predicate is either EQ or NE.
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
A Module instance is used to store all the information related to an LLVM module.
Class to represent pointers.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
const fltSemantics & getFltSemantics() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static IntegerType * getInt1Ty(LLVMContext &C)
bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
Type * getNonOpaquePointerElementType() const
Only use this method in code that is not reachable with opaque pointers, or part of deprecated method...
bool isX86_MMXTy() const
Return true if this is X86 MMX.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isX86_AMXTy() const
Return true if this is X86 AMX.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
LLVMContext & getContext() const
All values hold a context through their type.
Base class of all SIMD vector types.
Type * getElementType() const
bool isSequential() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
auto m_Undef()
Match an arbitrary undef constant.
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, std::optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
gep_type_iterator gep_type_end(const User *GEP)
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
constexpr int PoisonMaskElem
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
constexpr unsigned BitWidth
gep_type_iterator gep_type_begin(const User *GEP)
APFloat neg(APFloat X)
Returns the negated value of the argument.
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
unsigned Log2(Align A)
Returns the log2 of the alignment.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
This struct is a compact representation of a valid (non-zero power of two) alignment.