49 assert(
Op &&
Op->isCast() &&
"Can't fold cast of cast without a cast!");
51 assert(CastInst::isCast(opc) &&
"Invalid cast opcode");
54 Type *SrcTy =
Op->getOperand(0)->getType();
55 Type *MidTy =
Op->getType();
66 nullptr, FakeIntPtrTy,
nullptr);
70 Type *SrcTy = V->getType();
74 if (V->isAllOnesValue())
82 if (isa<VectorType>(DestTy) && !isa<VectorType>(SrcTy))
91 return ConstantFP::get(
101 if (isa<VectorType>(DestTy) && !isa<VectorType>(SrcTy))
118 return ConstantInt::get(DestTy,
FP->getValueAPF().bitcastToAPInt());
133 if (isa<PoisonValue>(V))
136 if (isa<UndefValue>(V)) {
140 if (opc == Instruction::ZExt || opc == Instruction::SExt ||
141 opc == Instruction::UIToFP || opc == Instruction::SIToFP)
147 opc != Instruction::AddrSpaceCast)
163 if (DestTy->
isVectorTy() && V->getType()->isVectorTy() &&
164 cast<VectorType>(DestTy)->getElementCount() ==
165 cast<VectorType>(V->getType())->getElementCount()) {
166 VectorType *DestVecTy = cast<VectorType>(DestTy);
174 cast<VectorType>(DestTy)->getElementCount(), Res);
176 if (isa<ScalableVectorType>(DestTy))
181 e = cast<FixedVectorType>(V->getType())->getNumElements();
197 case Instruction::FPTrunc:
198 case Instruction::FPExt:
199 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
201 APFloat Val = FPC->getValueAPF();
203 APFloat::rmNearestTiesToEven, &
ignored);
204 return ConstantFP::get(DestTy, Val);
207 case Instruction::FPToUI:
208 case Instruction::FPToSI:
209 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
210 const APFloat &V = FPC->getValueAPF();
213 if (APFloat::opInvalidOp ==
214 V.convertToInteger(IntVal, APFloat::rmTowardZero, &
ignored)) {
219 return ConstantInt::get(DestTy, IntVal);
222 case Instruction::UIToFP:
223 case Instruction::SIToFP:
225 const APInt &api = CI->getValue();
229 APFloat::rmNearestTiesToEven);
230 return ConstantFP::get(DestTy, apf);
233 case Instruction::ZExt:
236 return ConstantInt::get(DestTy, CI->getValue().zext(
BitWidth));
239 case Instruction::SExt:
242 return ConstantInt::get(DestTy, CI->getValue().sext(
BitWidth));
245 case Instruction::Trunc: {
248 return ConstantInt::get(DestTy, CI->getValue().trunc(
BitWidth));
253 case Instruction::BitCast:
255 case Instruction::AddrSpaceCast:
256 case Instruction::IntToPtr:
257 case Instruction::PtrToAddr:
258 case Instruction::PtrToInt:
266 if (
Cond->isNullValue())
return V2;
267 if (
Cond->isAllOnesValue())
return V1;
271 auto *V1VTy = CondV->
getType();
274 for (
unsigned i = 0, e = V1VTy->getNumElements(); i != e; ++i) {
277 ConstantInt::get(Ty, i));
279 ConstantInt::get(Ty, i));
280 auto *
Cond = cast<Constant>(CondV->getOperand(i));
281 if (isa<PoisonValue>(
Cond)) {
283 }
else if (V1Element == V2Element) {
285 }
else if (isa<UndefValue>(
Cond)) {
286 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
288 if (!isa<ConstantInt>(
Cond))
break;
289 V =
Cond->isNullValue() ? V2Element : V1Element;
295 if (Result.size() == V1VTy->getNumElements())
299 if (isa<PoisonValue>(
Cond))
302 if (isa<UndefValue>(
Cond)) {
303 if (isa<UndefValue>(V1))
return V1;
307 if (V1 == V2)
return V1;
309 if (isa<PoisonValue>(V1))
311 if (isa<PoisonValue>(V2))
317 if (isa<PoisonValue>(
C))
322 if (isa<ConstantExpr>(
C))
325 if (isa<ConstantInt>(
C) || isa<GlobalVariable>(
C) || isa<ConstantFP>(
C) ||
326 isa<ConstantPointerNull>(
C) || isa<Function>(
C))
329 if (
C->getType()->isVectorTy())
330 return !
C->containsPoisonElement() && !
C->containsConstantExpression();
335 if (isa<UndefValue>(V1) && NotPoison(V2))
return V2;
336 if (isa<UndefValue>(V2) && NotPoison(V1))
return V1;
343 auto *ValVTy = cast<VectorType>(Val->
getType());
347 if (isa<PoisonValue>(Val) || isa<UndefValue>(
Idx))
351 if (isa<UndefValue>(Val))
354 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
358 if (
auto *ValFVTy = dyn_cast<FixedVectorType>(Val->
getType())) {
360 if (CIdx->uge(ValFVTy->getNumElements()))
365 if (
auto *CE = dyn_cast<ConstantExpr>(Val)) {
366 if (
auto *
GEP = dyn_cast<GEPOperator>(CE)) {
368 Ops.
reserve(CE->getNumOperands());
369 for (
unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
371 if (
Op->getType()->isVectorTy()) {
379 return CE->getWithOperands(Ops, ValVTy->getElementType(),
false,
380 GEP->getSourceElementType());
381 }
else if (CE->getOpcode() == Instruction::InsertElement) {
382 if (
const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) {
384 APSInt(CIdx->getValue()))) {
385 return CE->getOperand(1);
397 if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) {
408 if (isa<UndefValue>(
Idx))
413 if (isa<ConstantAggregateZero>(Val) && Elt->
isNullValue())
417 if (!CIdx)
return nullptr;
421 if (isa<ScalableVectorType>(Val->
getType()))
424 auto *ValTy = cast<FixedVectorType>(Val->
getType());
426 unsigned NumElts = ValTy->getNumElements();
427 if (CIdx->
uge(NumElts))
431 Result.reserve(NumElts);
434 for (
unsigned i = 0; i != NumElts; ++i) {
436 Result.push_back(Elt);
449 auto *V1VTy = cast<VectorType>(V1->
getType());
450 unsigned MaskNumElts = Mask.size();
453 Type *EltTy = V1VTy->getElementType();
462 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
469 if (!MaskEltCount.isScalable() || Elt->
isNullValue() || isa<UndefValue>(Elt))
475 if (isa<ScalableVectorType>(V1VTy))
478 unsigned SrcNumElts = V1VTy->getElementCount().getKnownMinValue();
482 for (
unsigned i = 0; i != MaskNumElts; ++i) {
489 if (
unsigned(Elt) >= SrcNumElts*2)
491 else if (
unsigned(Elt) >= SrcNumElts) {
495 ConstantInt::get(Ty, Elt - SrcNumElts));
500 Result.push_back(InElt);
527 NumElts = ST->getNumElements();
529 NumElts = cast<ArrayType>(Agg->
getType())->getNumElements();
532 for (
unsigned i = 0; i != NumElts; ++i) {
534 if (!
C)
return nullptr;
552 bool IsScalableVector = isa<ScalableVectorType>(
C->getType());
553 bool HasScalarUndefOrScalableVectorUndef =
554 (!
C->getType()->isVectorTy() || IsScalableVector) && isa<UndefValue>(
C);
556 if (HasScalarUndefOrScalableVectorUndef) {
558 case Instruction::FNeg:
560 case Instruction::UnaryOpsEnd:
566 assert(!HasScalarUndefOrScalableVectorUndef &&
"Unexpected UndefValue");
568 assert(!isa<ConstantInt>(
C) &&
"Unexpected Integer UnaryOp");
571 const APFloat &CV = CFP->getValueAPF();
575 case Instruction::FNeg:
576 return ConstantFP::get(
C->getType(),
neg(CV));
578 }
else if (
auto *VTy = dyn_cast<VectorType>(
C->getType())) {
584 if (
auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
588 for (
unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
589 Constant *ExtractIdx = ConstantInt::get(Ty, i);
594 Result.push_back(Res);
612 Opcode, C1->
getType(),
false)) {
618 Opcode, C1->
getType(),
true)) {
624 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
629 bool IsScalableVector = isa<ScalableVectorType>(C1->
getType());
630 bool HasScalarUndefOrScalableVectorUndef =
632 (isa<UndefValue>(C1) || isa<UndefValue>(C2));
633 if (HasScalarUndefOrScalableVectorUndef) {
635 case Instruction::Xor:
636 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
641 case Instruction::Add:
642 case Instruction::Sub:
644 case Instruction::And:
645 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
648 case Instruction::Mul: {
650 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
661 case Instruction::SDiv:
662 case Instruction::UDiv:
669 case Instruction::URem:
670 case Instruction::SRem:
677 case Instruction::Or:
678 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
681 case Instruction::LShr:
683 if (isa<UndefValue>(C2))
687 case Instruction::AShr:
689 if (isa<UndefValue>(C2))
694 case Instruction::Shl:
696 if (isa<UndefValue>(C2))
700 case Instruction::FSub:
705 case Instruction::FAdd:
706 case Instruction::FMul:
707 case Instruction::FDiv:
708 case Instruction::FRem:
710 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
720 case Instruction::BinaryOpsEnd:
726 assert((!HasScalarUndefOrScalableVectorUndef) &&
"Unexpected UndefValue");
729 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
735 case Instruction::UDiv:
736 case Instruction::SDiv:
740 case Instruction::URem:
741 case Instruction::SRem:
747 case Instruction::And:
748 assert(!CI2->isZero() &&
"And zero handled above");
751 if (CE1->getOpcode() == Instruction::PtrToInt &&
752 isa<GlobalValue>(CE1->getOperand(0))) {
753 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
770 if (isa<Function>(GV) && !
DL.getFunctionPtrAlign())
772 }
else if (isa<GlobalVariable>(GV)) {
773 GVAlign = cast<GlobalVariable>(GV)->getAlign().valueOrOne();
777 unsigned DstWidth = CI2->getBitWidth();
778 unsigned SrcWidth = std::min(DstWidth,
Log2(GVAlign));
782 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
789 }
else if (isa<ConstantInt>(C1)) {
797 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
798 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
799 const APInt &C1V = CI1->getValue();
800 const APInt &C2V = CI2->getValue();
804 case Instruction::Add:
805 return ConstantInt::get(C1->
getType(), C1V + C2V);
806 case Instruction::Sub:
807 return ConstantInt::get(C1->
getType(), C1V - C2V);
808 case Instruction::Mul:
809 return ConstantInt::get(C1->
getType(), C1V * C2V);
810 case Instruction::UDiv:
811 assert(!CI2->isZero() &&
"Div by zero handled above");
812 return ConstantInt::get(CI1->getType(), C1V.
udiv(C2V));
813 case Instruction::SDiv:
814 assert(!CI2->isZero() &&
"Div by zero handled above");
817 return ConstantInt::get(CI1->getType(), C1V.
sdiv(C2V));
818 case Instruction::URem:
819 assert(!CI2->isZero() &&
"Div by zero handled above");
820 return ConstantInt::get(C1->
getType(), C1V.
urem(C2V));
821 case Instruction::SRem:
822 assert(!CI2->isZero() &&
"Div by zero handled above");
825 return ConstantInt::get(C1->
getType(), C1V.
srem(C2V));
826 case Instruction::And:
827 return ConstantInt::get(C1->
getType(), C1V & C2V);
828 case Instruction::Or:
829 return ConstantInt::get(C1->
getType(), C1V | C2V);
830 case Instruction::Xor:
831 return ConstantInt::get(C1->
getType(), C1V ^ C2V);
832 case Instruction::Shl:
834 return ConstantInt::get(C1->
getType(), C1V.
shl(C2V));
836 case Instruction::LShr:
838 return ConstantInt::get(C1->
getType(), C1V.
lshr(C2V));
840 case Instruction::AShr:
842 return ConstantInt::get(C1->
getType(), C1V.
ashr(C2V));
850 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
851 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
852 const APFloat &C1V = CFP1->getValueAPF();
853 const APFloat &C2V = CFP2->getValueAPF();
858 case Instruction::FAdd:
859 (void)C3V.
add(C2V, APFloat::rmNearestTiesToEven);
860 return ConstantFP::get(C1->
getType(), C3V);
861 case Instruction::FSub:
862 (void)C3V.
subtract(C2V, APFloat::rmNearestTiesToEven);
863 return ConstantFP::get(C1->
getType(), C3V);
864 case Instruction::FMul:
865 (void)C3V.
multiply(C2V, APFloat::rmNearestTiesToEven);
866 return ConstantFP::get(C1->
getType(), C3V);
867 case Instruction::FDiv:
868 (void)C3V.
divide(C2V, APFloat::rmNearestTiesToEven);
869 return ConstantFP::get(C1->
getType(), C3V);
870 case Instruction::FRem:
872 return ConstantFP::get(C1->
getType(), C3V);
877 if (
auto *VTy = dyn_cast<VectorType>(C1->
getType())) {
893 if (
auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
897 for (
unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
898 Constant *ExtractIdx = ConstantInt::get(Ty, i);
906 Result.push_back(Res);
922 if (!isa<ConstantExpr>(
T) || cast<ConstantExpr>(
T)->
getOpcode() != Opcode)
925 }
else if (isa<ConstantExpr>(C2)) {
935 case Instruction::Add:
936 case Instruction::Sub:
938 case Instruction::Shl:
939 case Instruction::LShr:
940 case Instruction::AShr:
944 case Instruction::SDiv:
945 case Instruction::UDiv:
949 case Instruction::URem:
950 case Instruction::SRem:
965 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
966 if (GV->isInterposable() || GV->hasGlobalUnnamedAddr())
968 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
969 Type *Ty = GVar->getValueType();
981 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
982 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
983 return ICmpInst::ICMP_NE;
984 return ICmpInst::BAD_ICMP_PREDICATE;
995 "Cannot compare different types of values!");
996 if (V1 == V2)
return ICmpInst::ICMP_EQ;
1000 return ICmpInst::BAD_ICMP_PREDICATE;
1006 auto GetComplexity = [](
Constant *V) {
1007 if (isa<ConstantExpr>(V))
1009 if (isa<GlobalValue>(V))
1011 if (isa<BlockAddress>(V))
1015 if (GetComplexity(V1) < GetComplexity(V2)) {
1017 if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
1018 return ICmpInst::getSwappedPredicate(SwappedRelation);
1019 return ICmpInst::BAD_ICMP_PREDICATE;
1022 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1024 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1028 if (BA2->getFunction() != BA->getFunction())
1029 return ICmpInst::ICMP_NE;
1030 }
else if (isa<ConstantPointerNull>(V2)) {
1031 return ICmpInst::ICMP_NE;
1033 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1036 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1038 }
else if (isa<BlockAddress>(V2)) {
1039 return ICmpInst::ICMP_NE;
1040 }
else if (isa<ConstantPointerNull>(V2)) {
1046 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV) &&
1048 GV->getType()->getAddressSpace()))
1049 return ICmpInst::ICMP_UGT;
1051 }
else if (
auto *CE1 = dyn_cast<ConstantExpr>(V1)) {
1056 switch (CE1->getOpcode()) {
1057 case Instruction::GetElementPtr: {
1061 if (isa<ConstantPointerNull>(V2)) {
1064 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1067 if (!GV->hasExternalWeakLinkage() && CE1GEP->
isInBounds())
1068 return ICmpInst::ICMP_UGT;
1070 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1071 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1075 return ICmpInst::BAD_ICMP_PREDICATE;
1078 }
else if (
const auto *CE2GEP = dyn_cast<GEPOperator>(V2)) {
1081 const Constant *CE2Op0 = cast<Constant>(CE2GEP->getPointerOperand());
1082 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1084 if (CE1Op0 != CE2Op0) {
1087 cast<GlobalValue>(CE2Op0));
1088 return ICmpInst::BAD_ICMP_PREDICATE;
1099 return ICmpInst::BAD_ICMP_PREDICATE;
1107 VT->getElementCount());
1112 if (Predicate == FCmpInst::FCMP_FALSE)
1115 if (Predicate == FCmpInst::FCMP_TRUE)
1119 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
1122 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1123 bool isIntegerPredicate = ICmpInst::isIntPredicate(Predicate);
1132 if (isIntegerPredicate)
1144 if (Predicate == ICmpInst::ICMP_UGE)
1147 if (Predicate == ICmpInst::ICMP_ULT)
1153 switch (Predicate) {
1154 case ICmpInst::ICMP_EQ:
1155 if (isa<ConstantExpr>(C1))
1158 case ICmpInst::ICMP_NE:
1165 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1166 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1167 const APInt &V2 = cast<ConstantInt>(C2)->getValue();
1169 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1170 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1171 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1173 }
else if (
auto *C1VTy = dyn_cast<VectorType>(C1->
getType())) {
1184 if (isa<ScalableVectorType>(C1VTy))
1192 for (
unsigned I = 0, E = C1VTy->getElementCount().getKnownMinValue();
1211 if (Predicate == FCmpInst::FCMP_ONE)
1213 else if (Predicate == FCmpInst::FCMP_UEQ)
1221 case ICmpInst::BAD_ICMP_PREDICATE:
1223 case ICmpInst::ICMP_EQ:
1226 Result = ICmpInst::isTrueWhenEqual(Predicate);
1228 case ICmpInst::ICMP_ULT:
1229 switch (Predicate) {
1230 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_ULE:
1232 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_UGE:
1238 case ICmpInst::ICMP_SLT:
1239 switch (Predicate) {
1240 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SLE:
1242 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SGE:
1248 case ICmpInst::ICMP_UGT:
1249 switch (Predicate) {
1250 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_UGE:
1252 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_ULE:
1258 case ICmpInst::ICMP_SGT:
1259 switch (Predicate) {
1260 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SGE:
1262 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SLE:
1268 case ICmpInst::ICMP_ULE:
1269 if (Predicate == ICmpInst::ICMP_UGT)
1271 if (Predicate == ICmpInst::ICMP_ULT || Predicate == ICmpInst::ICMP_ULE)
1274 case ICmpInst::ICMP_SLE:
1275 if (Predicate == ICmpInst::ICMP_SGT)
1277 if (Predicate == ICmpInst::ICMP_SLT || Predicate == ICmpInst::ICMP_SLE)
1280 case ICmpInst::ICMP_UGE:
1281 if (Predicate == ICmpInst::ICMP_ULT)
1283 if (Predicate == ICmpInst::ICMP_UGT || Predicate == ICmpInst::ICMP_UGE)
1286 case ICmpInst::ICMP_SGE:
1287 if (Predicate == ICmpInst::ICMP_SLT)
1289 if (Predicate == ICmpInst::ICMP_SGT || Predicate == ICmpInst::ICMP_SGE)
1292 case ICmpInst::ICMP_NE:
1293 if (Predicate == ICmpInst::ICMP_EQ)
1295 if (Predicate == ICmpInst::ICMP_NE)
1302 return ConstantInt::get(ResultTy, Result);
1304 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
1309 Predicate = ICmpInst::getSwappedPredicate(Predicate);
1317 std::optional<ConstantRange>
InRange,
1319 if (Idxs.
empty())
return C;
1324 if (isa<PoisonValue>(
C))
1327 if (isa<UndefValue>(
C))
1330 auto IsNoOp = [&]() {
1337 return IdxC->
isNullValue() || isa<UndefValue>(IdxC);
1341 return GEPTy->
isVectorTy() && !
C->getType()->isVectorTy()
1343 cast<VectorType>(GEPTy)->getElementCount(),
C)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
Module.h This file contains the declarations for the Module class.
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
const SmallVectorImpl< MachineOperand > & Cond
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)
LLVM_ABI 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.
LLVM_ABI APInt udiv(const APInt &RHS) const
Unsigned division operation.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
unsigned getBitWidth() const
Return the number of bits in the APInt.
LLVM_ABI APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
LLVM_ABI 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 LLVM_ABI 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 LLVM_ABI bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
A constant value that is initialized with an expression using other constant values.
static LLVM_ABI Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
static LLVM_ABI Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty, bool AllowLHSConstant=false)
Return the absorbing element for the given binary operation, i.e.
static LLVM_ABI Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static LLVM_ABI Constant * getNot(Constant *C)
static LLVM_ABI Constant * getXor(Constant *C1, Constant *C2)
static LLVM_ABI 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 LLVM_ABI bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI 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 LLVM_ABI Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI 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 LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
Constant Vector Declarations.
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
LLVM_ABI Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
LLVM_ABI 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 LLVM_ABI 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 LLVM_ABI 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.
LLVM_ABI bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
Class to represent integer types.
static LLVM_ABI 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 LLVM_ABI 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.
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.
LLVM_ABI bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
bool isPointerTy() const
True if this is an instance of PointerType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
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 isX86_AMXTy() const
Return true if this is X86 AMX.
LLVM_ABI const fltSemantics & getFltSemantics() const
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
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.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static LLVM_ABI 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.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
LLVM_ABI 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.
LLVM_ABI Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
LLVM_ABI Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
LLVM_ABI Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
LLVM_ABI Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, std::optional< ConstantRange > InRange, ArrayRef< Value * > Idxs)
LLVM_ABI Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices.
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
constexpr int PoisonMaskElem
LLVM_ABI 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.
LLVM_ABI Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
LLVM_ABI 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.
LLVM_ABI Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
LLVM_ABI Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
This struct is a compact representation of a valid (non-zero power of two) alignment.