50 assert(
Op &&
Op->isCast() &&
"Can't fold cast of cast without a cast!");
52 assert(CastInst::isCast(opc) &&
"Invalid cast opcode");
55 Type *SrcTy =
Op->getOperand(0)->getType();
56 Type *MidTy =
Op->getType();
67 nullptr, FakeIntPtrTy,
nullptr);
71 Type *SrcTy = V->getType();
77 if (
VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
78 if (V->isAllOnesValue())
84 if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
109 if (
FP->getType()->isPPC_FP128Ty())
116 return ConstantInt::get(
FP->getContext(),
117 FP->getValueAPF().bitcastToAPInt());
132 if (isa<PoisonValue>(V))
135 if (isa<UndefValue>(V)) {
139 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
140 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
146 opc != Instruction::AddrSpaceCast)
162 if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
164 cast<FixedVectorType>(DestTy)->getNumElements() ==
165 cast<FixedVectorType>(V->getType())->getNumElements()) {
166 VectorType *DestVecTy = cast<VectorType>(DestTy);
174 cast<VectorType>(DestTy)->getElementCount(), Res);
179 e = cast<FixedVectorType>(V->getType())->getNumElements();
195 case Instruction::FPTrunc:
196 case Instruction::FPExt:
197 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
199 APFloat Val = FPC->getValueAPF();
202 return ConstantFP::get(V->getContext(), Val);
205 case Instruction::FPToUI:
206 case Instruction::FPToSI:
207 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
208 const APFloat &V = FPC->getValueAPF();
210 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
211 APSInt IntVal(DestBitWidth, opc == Instruction::FPToUI);
212 if (APFloat::opInvalidOp ==
213 V.convertToInteger(IntVal, APFloat::rmTowardZero, &
ignored)) {
218 return ConstantInt::get(FPC->getContext(), IntVal);
221 case Instruction::UIToFP:
222 case Instruction::SIToFP:
224 const APInt &api = CI->getValue();
228 APFloat::rmNearestTiesToEven);
229 return ConstantFP::get(V->getContext(), apf);
232 case Instruction::ZExt:
235 return ConstantInt::get(V->getContext(),
239 case Instruction::SExt:
242 return ConstantInt::get(V->getContext(),
246 case Instruction::Trunc: {
247 if (V->getType()->isVectorTy())
250 uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
252 return ConstantInt::get(V->getContext(),
253 CI->getValue().trunc(DestBitWidth));
258 case Instruction::BitCast:
260 case Instruction::AddrSpaceCast:
261 case Instruction::IntToPtr:
262 case Instruction::PtrToInt:
270 if (
Cond->isNullValue())
return V2;
271 if (
Cond->isAllOnesValue())
return V1;
275 auto *V1VTy = CondV->
getType();
278 for (
unsigned i = 0, e = V1VTy->getNumElements(); i != e; ++i) {
281 ConstantInt::get(Ty, i));
283 ConstantInt::get(Ty, i));
284 auto *
Cond = cast<Constant>(CondV->getOperand(i));
285 if (isa<PoisonValue>(
Cond)) {
287 }
else if (V1Element == V2Element) {
289 }
else if (isa<UndefValue>(
Cond)) {
290 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
292 if (!isa<ConstantInt>(
Cond))
break;
293 V =
Cond->isNullValue() ? V2Element : V1Element;
299 if (Result.size() == V1VTy->getNumElements())
303 if (isa<PoisonValue>(
Cond))
306 if (isa<UndefValue>(
Cond)) {
307 if (isa<UndefValue>(V1))
return V1;
311 if (V1 == V2)
return V1;
313 if (isa<PoisonValue>(V1))
315 if (isa<PoisonValue>(V2))
321 if (isa<PoisonValue>(
C))
326 if (isa<ConstantExpr>(
C))
329 if (isa<ConstantInt>(
C) || isa<GlobalVariable>(
C) || isa<ConstantFP>(
C) ||
330 isa<ConstantPointerNull>(
C) || isa<Function>(
C))
333 if (
C->getType()->isVectorTy())
334 return !
C->containsPoisonElement() && !
C->containsConstantExpression();
339 if (isa<UndefValue>(V1) && NotPoison(V2))
return V2;
340 if (isa<UndefValue>(V2) && NotPoison(V1))
return V1;
347 auto *ValVTy = cast<VectorType>(Val->
getType());
351 if (isa<PoisonValue>(Val) || isa<UndefValue>(
Idx))
355 if (isa<UndefValue>(Val))
358 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
362 if (
auto *ValFVTy = dyn_cast<FixedVectorType>(Val->
getType())) {
364 if (CIdx->uge(ValFVTy->getNumElements()))
369 if (
auto *CE = dyn_cast<ConstantExpr>(Val)) {
370 if (
auto *
GEP = dyn_cast<GEPOperator>(CE)) {
372 Ops.
reserve(CE->getNumOperands());
373 for (
unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
375 if (
Op->getType()->isVectorTy()) {
383 return CE->getWithOperands(Ops, ValVTy->getElementType(),
false,
384 GEP->getSourceElementType());
385 }
else if (CE->getOpcode() == Instruction::InsertElement) {
386 if (
const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) {
388 APSInt(CIdx->getValue()))) {
389 return CE->getOperand(1);
401 if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) {
412 if (isa<UndefValue>(
Idx))
417 if (isa<ConstantAggregateZero>(Val) && Elt->
isNullValue())
421 if (!CIdx)
return nullptr;
425 if (isa<ScalableVectorType>(Val->
getType()))
428 auto *ValTy = cast<FixedVectorType>(Val->
getType());
430 unsigned NumElts = ValTy->getNumElements();
431 if (CIdx->
uge(NumElts))
435 Result.reserve(NumElts);
438 for (
unsigned i = 0; i != NumElts; ++i) {
440 Result.push_back(Elt);
453 auto *V1VTy = cast<VectorType>(V1->
getType());
454 unsigned MaskNumElts = Mask.size();
457 Type *EltTy = V1VTy->getElementType();
466 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
472 auto *VTy = VectorType::get(EltTy, MaskEltCount);
474 }
else if (!MaskEltCount.isScalable())
480 if (isa<ScalableVectorType>(V1VTy))
483 unsigned SrcNumElts = V1VTy->getElementCount().getKnownMinValue();
487 for (
unsigned i = 0; i != MaskNumElts; ++i) {
494 if (
unsigned(Elt) >= SrcNumElts*2)
496 else if (
unsigned(Elt) >= SrcNumElts) {
500 ConstantInt::get(Ty, Elt - SrcNumElts));
505 Result.push_back(InElt);
532 NumElts = ST->getNumElements();
534 NumElts = cast<ArrayType>(Agg->
getType())->getNumElements();
537 for (
unsigned i = 0; i != NumElts; ++i) {
539 if (!
C)
return nullptr;
557 bool IsScalableVector = isa<ScalableVectorType>(
C->getType());
558 bool HasScalarUndefOrScalableVectorUndef =
559 (!
C->getType()->isVectorTy() || IsScalableVector) && isa<UndefValue>(
C);
561 if (HasScalarUndefOrScalableVectorUndef) {
563 case Instruction::FNeg:
565 case Instruction::UnaryOpsEnd:
571 assert(!HasScalarUndefOrScalableVectorUndef &&
"Unexpected UndefValue");
573 assert(!isa<ConstantInt>(
C) &&
"Unexpected Integer UnaryOp");
576 const APFloat &CV = CFP->getValueAPF();
580 case Instruction::FNeg:
581 return ConstantFP::get(
C->getContext(),
neg(CV));
583 }
else if (
auto *VTy = dyn_cast<FixedVectorType>(
C->getType())) {
593 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
594 Constant *ExtractIdx = ConstantInt::get(Ty, i);
599 Result.push_back(Res);
616 Opcode, C1->
getType(),
false)) {
622 Opcode, C1->
getType(),
true)) {
628 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
633 bool IsScalableVector = isa<ScalableVectorType>(C1->
getType());
634 bool HasScalarUndefOrScalableVectorUndef =
636 (isa<UndefValue>(C1) || isa<UndefValue>(C2));
637 if (HasScalarUndefOrScalableVectorUndef) {
639 case Instruction::Xor:
640 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
645 case Instruction::Add:
646 case Instruction::Sub:
648 case Instruction::And:
649 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
652 case Instruction::Mul: {
654 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
665 case Instruction::SDiv:
666 case Instruction::UDiv:
673 case Instruction::URem:
674 case Instruction::SRem:
681 case Instruction::Or:
682 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
685 case Instruction::LShr:
687 if (isa<UndefValue>(C2))
691 case Instruction::AShr:
693 if (isa<UndefValue>(C2))
698 case Instruction::Shl:
700 if (isa<UndefValue>(C2))
704 case Instruction::FSub:
709 case Instruction::FAdd:
710 case Instruction::FMul:
711 case Instruction::FDiv:
712 case Instruction::FRem:
714 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
724 case Instruction::BinaryOpsEnd:
730 assert((!HasScalarUndefOrScalableVectorUndef) &&
"Unexpected UndefValue");
733 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
735 case Instruction::Mul:
739 case Instruction::UDiv:
740 case Instruction::SDiv:
744 case Instruction::URem:
745 case Instruction::SRem:
751 case Instruction::And:
757 if (CE1->getOpcode() == Instruction::PtrToInt &&
758 isa<GlobalValue>(CE1->getOperand(0))) {
759 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
776 if (isa<Function>(GV) && !
DL.getFunctionPtrAlign())
778 }
else if (isa<GlobalVariable>(GV)) {
779 GVAlign = cast<GlobalVariable>(GV)->getAlign().valueOrOne();
783 unsigned DstWidth = CI2->getBitWidth();
784 unsigned SrcWidth = std::min(DstWidth,
Log2(GVAlign));
788 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
794 case Instruction::Or:
795 if (CI2->isMinusOne())
799 }
else if (isa<ConstantInt>(C1)) {
807 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
808 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
809 const APInt &C1V = CI1->getValue();
810 const APInt &C2V = CI2->getValue();
814 case Instruction::Add:
815 return ConstantInt::get(CI1->getContext(), C1V + C2V);
816 case Instruction::Sub:
817 return ConstantInt::get(CI1->getContext(), C1V - C2V);
818 case Instruction::Mul:
819 return ConstantInt::get(CI1->getContext(), C1V * C2V);
820 case Instruction::UDiv:
821 assert(!CI2->isZero() &&
"Div by zero handled above");
822 return ConstantInt::get(CI1->getContext(), C1V.
udiv(C2V));
823 case Instruction::SDiv:
824 assert(!CI2->isZero() &&
"Div by zero handled above");
827 return ConstantInt::get(CI1->getContext(), C1V.
sdiv(C2V));
828 case Instruction::URem:
829 assert(!CI2->isZero() &&
"Div by zero handled above");
830 return ConstantInt::get(CI1->getContext(), C1V.
urem(C2V));
831 case Instruction::SRem:
832 assert(!CI2->isZero() &&
"Div by zero handled above");
835 return ConstantInt::get(CI1->getContext(), C1V.
srem(C2V));
836 case Instruction::And:
837 return ConstantInt::get(CI1->getContext(), C1V & C2V);
838 case Instruction::Or:
839 return ConstantInt::get(CI1->getContext(), C1V | C2V);
840 case Instruction::Xor:
841 return ConstantInt::get(CI1->getContext(), C1V ^ C2V);
842 case Instruction::Shl:
844 return ConstantInt::get(CI1->getContext(), C1V.
shl(C2V));
846 case Instruction::LShr:
848 return ConstantInt::get(CI1->getContext(), C1V.
lshr(C2V));
850 case Instruction::AShr:
852 return ConstantInt::get(CI1->getContext(), C1V.
ashr(C2V));
858 case Instruction::SDiv:
859 case Instruction::UDiv:
860 case Instruction::URem:
861 case Instruction::SRem:
862 case Instruction::LShr:
863 case Instruction::AShr:
864 case Instruction::Shl:
865 if (CI1->isZero())
return C1;
870 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
871 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
872 const APFloat &C1V = CFP1->getValueAPF();
873 const APFloat &C2V = CFP2->getValueAPF();
878 case Instruction::FAdd:
879 (void)C3V.
add(C2V, APFloat::rmNearestTiesToEven);
880 return ConstantFP::get(C1->
getContext(), C3V);
881 case Instruction::FSub:
882 (void)C3V.
subtract(C2V, APFloat::rmNearestTiesToEven);
883 return ConstantFP::get(C1->
getContext(), C3V);
884 case Instruction::FMul:
885 (void)C3V.
multiply(C2V, APFloat::rmNearestTiesToEven);
886 return ConstantFP::get(C1->
getContext(), C3V);
887 case Instruction::FDiv:
888 (void)C3V.
divide(C2V, APFloat::rmNearestTiesToEven);
889 return ConstantFP::get(C1->
getContext(), C3V);
890 case Instruction::FRem:
892 return ConstantFP::get(C1->
getContext(), C3V);
895 }
else if (
auto *VTy = dyn_cast<VectorType>(C1->
getType())) {
911 if (
auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
915 for (
unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
916 Constant *ExtractIdx = ConstantInt::get(Ty, i);
929 Result.push_back(Res);
945 if (!isa<ConstantExpr>(
T) || cast<ConstantExpr>(
T)->
getOpcode() != Opcode)
948 }
else if (isa<ConstantExpr>(C2)) {
958 case Instruction::Add:
959 case Instruction::Sub:
961 case Instruction::Shl:
962 case Instruction::LShr:
963 case Instruction::AShr:
967 case Instruction::SDiv:
968 case Instruction::UDiv:
972 case Instruction::URem:
973 case Instruction::SRem:
988 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
989 if (GV->isInterposable() || GV->hasGlobalUnnamedAddr())
991 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
992 Type *Ty = GVar->getValueType();
1004 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
1005 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
1006 return ICmpInst::ICMP_NE;
1007 return ICmpInst::BAD_ICMP_PREDICATE;
1018 "Cannot compare different types of values!");
1019 if (V1 == V2)
return ICmpInst::ICMP_EQ;
1023 return ICmpInst::BAD_ICMP_PREDICATE;
1029 auto GetComplexity = [](
Constant *V) {
1030 if (isa<ConstantExpr>(V))
1032 if (isa<GlobalValue>(V))
1034 if (isa<BlockAddress>(V))
1038 if (GetComplexity(V1) < GetComplexity(V2)) {
1040 if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
1041 return ICmpInst::getSwappedPredicate(SwappedRelation);
1042 return ICmpInst::BAD_ICMP_PREDICATE;
1045 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1047 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1051 if (BA2->getFunction() != BA->getFunction())
1052 return ICmpInst::ICMP_NE;
1053 }
else if (isa<ConstantPointerNull>(V2)) {
1054 return ICmpInst::ICMP_NE;
1056 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1059 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1061 }
else if (isa<BlockAddress>(V2)) {
1062 return ICmpInst::ICMP_NE;
1063 }
else if (isa<ConstantPointerNull>(V2)) {
1069 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV) &&
1071 GV->getType()->getAddressSpace()))
1072 return ICmpInst::ICMP_UGT;
1074 }
else if (
auto *CE1 = dyn_cast<ConstantExpr>(V1)) {
1079 switch (CE1->getOpcode()) {
1080 case Instruction::GetElementPtr: {
1084 if (isa<ConstantPointerNull>(V2)) {
1087 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1090 if (!GV->hasExternalWeakLinkage() && CE1GEP->
isInBounds())
1091 return ICmpInst::ICMP_UGT;
1093 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1094 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1098 return ICmpInst::BAD_ICMP_PREDICATE;
1101 }
else if (
const auto *CE2GEP = dyn_cast<GEPOperator>(V2)) {
1104 const Constant *CE2Op0 = cast<Constant>(CE2GEP->getPointerOperand());
1105 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1107 if (CE1Op0 != CE2Op0) {
1110 cast<GlobalValue>(CE2Op0));
1111 return ICmpInst::BAD_ICMP_PREDICATE;
1122 return ICmpInst::BAD_ICMP_PREDICATE;
1130 VT->getElementCount());
1135 if (Predicate == FCmpInst::FCMP_FALSE)
1138 if (Predicate == FCmpInst::FCMP_TRUE)
1142 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
1145 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1146 bool isIntegerPredicate = ICmpInst::isIntPredicate(Predicate);
1155 if (isIntegerPredicate)
1167 if (Predicate == ICmpInst::ICMP_UGE)
1170 if (Predicate == ICmpInst::ICMP_ULT)
1176 switch (Predicate) {
1177 case ICmpInst::ICMP_EQ:
1178 if (isa<ConstantInt>(C2))
1181 case ICmpInst::ICMP_NE:
1188 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1189 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1190 const APInt &V2 = cast<ConstantInt>(C2)->getValue();
1192 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1193 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1194 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1196 }
else if (
auto *C1VTy = dyn_cast<VectorType>(C1->
getType())) {
1207 if (isa<ScalableVectorType>(C1VTy))
1215 for (
unsigned I = 0, E = C1VTy->getElementCount().getKnownMinValue();
1234 if (Predicate == FCmpInst::FCMP_ONE)
1236 else if (Predicate == FCmpInst::FCMP_UEQ)
1244 case ICmpInst::BAD_ICMP_PREDICATE:
1246 case ICmpInst::ICMP_EQ:
1249 Result = ICmpInst::isTrueWhenEqual(Predicate);
1251 case ICmpInst::ICMP_ULT:
1252 switch (Predicate) {
1253 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_ULE:
1255 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_UGE:
1261 case ICmpInst::ICMP_SLT:
1262 switch (Predicate) {
1263 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SLE:
1265 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SGE:
1271 case ICmpInst::ICMP_UGT:
1272 switch (Predicate) {
1273 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_UGE:
1275 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_ULE:
1281 case ICmpInst::ICMP_SGT:
1282 switch (Predicate) {
1283 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SGE:
1285 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SLE:
1291 case ICmpInst::ICMP_ULE:
1292 if (Predicate == ICmpInst::ICMP_UGT)
1294 if (Predicate == ICmpInst::ICMP_ULT || Predicate == ICmpInst::ICMP_ULE)
1297 case ICmpInst::ICMP_SLE:
1298 if (Predicate == ICmpInst::ICMP_SGT)
1300 if (Predicate == ICmpInst::ICMP_SLT || Predicate == ICmpInst::ICMP_SLE)
1303 case ICmpInst::ICMP_UGE:
1304 if (Predicate == ICmpInst::ICMP_ULT)
1306 if (Predicate == ICmpInst::ICMP_UGT || Predicate == ICmpInst::ICMP_UGE)
1309 case ICmpInst::ICMP_SGE:
1310 if (Predicate == ICmpInst::ICMP_SLT)
1312 if (Predicate == ICmpInst::ICMP_SGT || Predicate == ICmpInst::ICMP_SGE)
1315 case ICmpInst::ICMP_NE:
1316 if (Predicate == ICmpInst::ICMP_EQ)
1318 if (Predicate == ICmpInst::ICMP_NE)
1325 return ConstantInt::get(ResultTy, Result);
1327 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
1332 Predicate = ICmpInst::getSwappedPredicate(Predicate);
1340 std::optional<ConstantRange>
InRange,
1342 if (Idxs.
empty())
return C;
1347 if (isa<PoisonValue>(
C))
1350 if (isa<UndefValue>(
C))
1353 auto IsNoOp = [&]() {
1360 return IdxC->
isNullValue() || isa<UndefValue>(IdxC);
1364 return GEPTy->
isVectorTy() && !
C->getType()->isVectorTy()
1366 cast<VectorType>(GEPTy)->getElementCount(),
C)
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static unsigned foldConstantCastPair(unsigned opc, ConstantExpr *Op, Type *DstTy)
This function determines which opcode to use to fold two constant cast expressions together.
static Constant * foldMaybeUndesirableCast(unsigned opc, Constant *V, Type *DestTy)
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1, const GlobalValue *GV2)
static Constant * FoldBitCast(Constant *V, Type *DestTy)
static ICmpInst::Predicate evaluateICmpRelation(Constant *V1, Constant *V2)
This function determines if there is anything we can decide about the two constants provided.
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 InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
Module.h This file contains the declarations for the Module class.
const SmallVectorImpl< MachineOperand > & Cond
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.
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.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
APInt srem(const APInt &RHS) const
Function for signed remainder operation.
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.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
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.
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.
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)
A constant value that is initialized with an expression using other constant values.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
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 * getXor(Constant *C1, Constant *C2)
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.
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.
ConstantFP - Floating Point Values [float, double].
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 ConstantInt * getFalse(LLVMContext &Context)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
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 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 AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
static Constant * getAllOnesValue(Type *Ty)
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.
This class represents an Operation in the Expression.
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.
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 * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
Module * getParent()
Get the module that this global value is contained inside of...
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.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
void reserve(size_type N)
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.
const fltSemantics & getFltSemantics() const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isPointerTy() const
True if this is an instance of PointerType.
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.
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
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.
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.
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
#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)
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 * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, std::optional< ConstantRange > InRange, ArrayRef< Value * > Idxs)
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
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.