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 ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
165 cast<FixedVectorType>(DestTy)->getNumElements() ==
166 cast<FixedVectorType>(V->getType())->getNumElements()) {
167 VectorType *DestVecTy = cast<VectorType>(DestTy);
175 cast<VectorType>(DestTy)->getElementCount(), Res);
180 e = cast<FixedVectorType>(V->getType())->getNumElements();
196 case Instruction::FPTrunc:
197 case Instruction::FPExt:
198 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
200 APFloat Val = FPC->getValueAPF();
202 APFloat::rmNearestTiesToEven, &
ignored);
203 return ConstantFP::get(DestTy, Val);
206 case Instruction::FPToUI:
207 case Instruction::FPToSI:
208 if (
ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
209 const APFloat &V = FPC->getValueAPF();
212 if (APFloat::opInvalidOp ==
213 V.convertToInteger(IntVal, APFloat::rmTowardZero, &
ignored)) {
218 return ConstantInt::get(DestTy, IntVal);
221 case Instruction::UIToFP:
222 case Instruction::SIToFP:
224 const APInt &api = CI->getValue();
228 APFloat::rmNearestTiesToEven);
229 return ConstantFP::get(DestTy, apf);
232 case Instruction::ZExt:
235 return ConstantInt::get(DestTy, CI->getValue().zext(
BitWidth));
238 case Instruction::SExt:
241 return ConstantInt::get(DestTy, CI->getValue().sext(
BitWidth));
244 case Instruction::Trunc: {
247 return ConstantInt::get(DestTy, CI->getValue().trunc(
BitWidth));
252 case Instruction::BitCast:
254 case Instruction::AddrSpaceCast:
255 case Instruction::IntToPtr:
256 case Instruction::PtrToInt:
264 if (
Cond->isNullValue())
return V2;
265 if (
Cond->isAllOnesValue())
return V1;
269 auto *V1VTy = CondV->
getType();
272 for (
unsigned i = 0, e = V1VTy->getNumElements(); i != e; ++i) {
275 ConstantInt::get(Ty, i));
277 ConstantInt::get(Ty, i));
278 auto *
Cond = cast<Constant>(CondV->getOperand(i));
279 if (isa<PoisonValue>(
Cond)) {
281 }
else if (V1Element == V2Element) {
283 }
else if (isa<UndefValue>(
Cond)) {
284 V = isa<UndefValue>(V1Element) ? V1Element : V2Element;
286 if (!isa<ConstantInt>(
Cond))
break;
287 V =
Cond->isNullValue() ? V2Element : V1Element;
293 if (Result.size() == V1VTy->getNumElements())
297 if (isa<PoisonValue>(
Cond))
300 if (isa<UndefValue>(
Cond)) {
301 if (isa<UndefValue>(V1))
return V1;
305 if (V1 == V2)
return V1;
307 if (isa<PoisonValue>(V1))
309 if (isa<PoisonValue>(V2))
315 if (isa<PoisonValue>(
C))
320 if (isa<ConstantExpr>(
C))
323 if (isa<ConstantInt>(
C) || isa<GlobalVariable>(
C) || isa<ConstantFP>(
C) ||
324 isa<ConstantPointerNull>(
C) || isa<Function>(
C))
327 if (
C->getType()->isVectorTy())
328 return !
C->containsPoisonElement() && !
C->containsConstantExpression();
333 if (isa<UndefValue>(V1) && NotPoison(V2))
return V2;
334 if (isa<UndefValue>(V2) && NotPoison(V1))
return V1;
341 auto *ValVTy = cast<VectorType>(Val->
getType());
345 if (isa<PoisonValue>(Val) || isa<UndefValue>(
Idx))
349 if (isa<UndefValue>(Val))
352 auto *CIdx = dyn_cast<ConstantInt>(
Idx);
356 if (
auto *ValFVTy = dyn_cast<FixedVectorType>(Val->
getType())) {
358 if (CIdx->uge(ValFVTy->getNumElements()))
363 if (
auto *CE = dyn_cast<ConstantExpr>(Val)) {
364 if (
auto *
GEP = dyn_cast<GEPOperator>(CE)) {
366 Ops.
reserve(CE->getNumOperands());
367 for (
unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) {
369 if (
Op->getType()->isVectorTy()) {
377 return CE->getWithOperands(Ops, ValVTy->getElementType(),
false,
378 GEP->getSourceElementType());
379 }
else if (CE->getOpcode() == Instruction::InsertElement) {
380 if (
const auto *IEIdx = dyn_cast<ConstantInt>(CE->getOperand(2))) {
382 APSInt(CIdx->getValue()))) {
383 return CE->getOperand(1);
395 if (CIdx->getValue().ult(ValVTy->getElementCount().getKnownMinValue())) {
406 if (isa<UndefValue>(
Idx))
411 if (isa<ConstantAggregateZero>(Val) && Elt->
isNullValue())
415 if (!CIdx)
return nullptr;
419 if (isa<ScalableVectorType>(Val->
getType()))
422 auto *ValTy = cast<FixedVectorType>(Val->
getType());
424 unsigned NumElts = ValTy->getNumElements();
425 if (CIdx->
uge(NumElts))
429 Result.reserve(NumElts);
432 for (
unsigned i = 0; i != NumElts; ++i) {
434 Result.push_back(Elt);
447 auto *V1VTy = cast<VectorType>(V1->
getType());
448 unsigned MaskNumElts = Mask.size();
451 Type *EltTy = V1VTy->getElementType();
460 if (
all_of(Mask, [](
int Elt) {
return Elt == 0; })) {
466 auto *VTy = VectorType::get(EltTy, MaskEltCount);
468 }
else if (!MaskEltCount.isScalable())
474 if (isa<ScalableVectorType>(V1VTy))
477 unsigned SrcNumElts = V1VTy->getElementCount().getKnownMinValue();
481 for (
unsigned i = 0; i != MaskNumElts; ++i) {
488 if (
unsigned(Elt) >= SrcNumElts*2)
490 else if (
unsigned(Elt) >= SrcNumElts) {
494 ConstantInt::get(Ty, Elt - SrcNumElts));
499 Result.push_back(InElt);
526 NumElts = ST->getNumElements();
528 NumElts = cast<ArrayType>(Agg->
getType())->getNumElements();
531 for (
unsigned i = 0; i != NumElts; ++i) {
533 if (!
C)
return nullptr;
551 bool IsScalableVector = isa<ScalableVectorType>(
C->getType());
552 bool HasScalarUndefOrScalableVectorUndef =
553 (!
C->getType()->isVectorTy() || IsScalableVector) && isa<UndefValue>(
C);
555 if (HasScalarUndefOrScalableVectorUndef) {
557 case Instruction::FNeg:
559 case Instruction::UnaryOpsEnd:
565 assert(!HasScalarUndefOrScalableVectorUndef &&
"Unexpected UndefValue");
567 assert(!isa<ConstantInt>(
C) &&
"Unexpected Integer UnaryOp");
570 const APFloat &CV = CFP->getValueAPF();
574 case Instruction::FNeg:
575 return ConstantFP::get(
C->getType(),
neg(CV));
577 }
else if (
auto *VTy = dyn_cast<VectorType>(
C->getType())) {
583 if (
auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
587 for (
unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
588 Constant *ExtractIdx = ConstantInt::get(Ty, i);
593 Result.push_back(Res);
611 Opcode, C1->
getType(),
false)) {
617 Opcode, C1->
getType(),
true)) {
623 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
628 bool IsScalableVector = isa<ScalableVectorType>(C1->
getType());
629 bool HasScalarUndefOrScalableVectorUndef =
631 (isa<UndefValue>(C1) || isa<UndefValue>(C2));
632 if (HasScalarUndefOrScalableVectorUndef) {
634 case Instruction::Xor:
635 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
640 case Instruction::Add:
641 case Instruction::Sub:
643 case Instruction::And:
644 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
647 case Instruction::Mul: {
649 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
660 case Instruction::SDiv:
661 case Instruction::UDiv:
668 case Instruction::URem:
669 case Instruction::SRem:
676 case Instruction::Or:
677 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
680 case Instruction::LShr:
682 if (isa<UndefValue>(C2))
686 case Instruction::AShr:
688 if (isa<UndefValue>(C2))
693 case Instruction::Shl:
695 if (isa<UndefValue>(C2))
699 case Instruction::FSub:
704 case Instruction::FAdd:
705 case Instruction::FMul:
706 case Instruction::FDiv:
707 case Instruction::FRem:
709 if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
719 case Instruction::BinaryOpsEnd:
725 assert((!HasScalarUndefOrScalableVectorUndef) &&
"Unexpected UndefValue");
728 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
734 case Instruction::UDiv:
735 case Instruction::SDiv:
739 case Instruction::URem:
740 case Instruction::SRem:
746 case Instruction::And:
747 assert(!CI2->isZero() &&
"And zero handled above");
750 if (CE1->getOpcode() == Instruction::PtrToInt &&
751 isa<GlobalValue>(CE1->getOperand(0))) {
752 GlobalValue *GV = cast<GlobalValue>(CE1->getOperand(0));
769 if (isa<Function>(GV) && !
DL.getFunctionPtrAlign())
771 }
else if (isa<GlobalVariable>(GV)) {
772 GVAlign = cast<GlobalVariable>(GV)->getAlign().valueOrOne();
776 unsigned DstWidth = CI2->getBitWidth();
777 unsigned SrcWidth = std::min(DstWidth,
Log2(GVAlign));
781 if ((CI2->getValue() & BitsNotSet) == CI2->getValue())
788 }
else if (isa<ConstantInt>(C1)) {
796 if (
ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
797 if (
ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
798 const APInt &C1V = CI1->getValue();
799 const APInt &C2V = CI2->getValue();
803 case Instruction::Add:
804 return ConstantInt::get(C1->
getType(), C1V + C2V);
805 case Instruction::Sub:
806 return ConstantInt::get(C1->
getType(), C1V - C2V);
807 case Instruction::Mul:
808 return ConstantInt::get(C1->
getType(), C1V * C2V);
809 case Instruction::UDiv:
810 assert(!CI2->isZero() &&
"Div by zero handled above");
811 return ConstantInt::get(CI1->getType(), C1V.
udiv(C2V));
812 case Instruction::SDiv:
813 assert(!CI2->isZero() &&
"Div by zero handled above");
816 return ConstantInt::get(CI1->getType(), C1V.
sdiv(C2V));
817 case Instruction::URem:
818 assert(!CI2->isZero() &&
"Div by zero handled above");
819 return ConstantInt::get(C1->
getType(), C1V.
urem(C2V));
820 case Instruction::SRem:
821 assert(!CI2->isZero() &&
"Div by zero handled above");
824 return ConstantInt::get(C1->
getType(), C1V.
srem(C2V));
825 case Instruction::And:
826 return ConstantInt::get(C1->
getType(), C1V & C2V);
827 case Instruction::Or:
828 return ConstantInt::get(C1->
getType(), C1V | C2V);
829 case Instruction::Xor:
830 return ConstantInt::get(C1->
getType(), C1V ^ C2V);
831 case Instruction::Shl:
833 return ConstantInt::get(C1->
getType(), C1V.
shl(C2V));
835 case Instruction::LShr:
837 return ConstantInt::get(C1->
getType(), C1V.
lshr(C2V));
839 case Instruction::AShr:
841 return ConstantInt::get(C1->
getType(), C1V.
ashr(C2V));
849 }
else if (
ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
850 if (
ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
851 const APFloat &C1V = CFP1->getValueAPF();
852 const APFloat &C2V = CFP2->getValueAPF();
857 case Instruction::FAdd:
858 (void)C3V.
add(C2V, APFloat::rmNearestTiesToEven);
859 return ConstantFP::get(C1->
getType(), C3V);
860 case Instruction::FSub:
861 (void)C3V.
subtract(C2V, APFloat::rmNearestTiesToEven);
862 return ConstantFP::get(C1->
getType(), C3V);
863 case Instruction::FMul:
864 (void)C3V.
multiply(C2V, APFloat::rmNearestTiesToEven);
865 return ConstantFP::get(C1->
getType(), C3V);
866 case Instruction::FDiv:
867 (void)C3V.
divide(C2V, APFloat::rmNearestTiesToEven);
868 return ConstantFP::get(C1->
getType(), C3V);
869 case Instruction::FRem:
871 return ConstantFP::get(C1->
getType(), C3V);
876 if (
auto *VTy = dyn_cast<VectorType>(C1->
getType())) {
892 if (
auto *FVTy = dyn_cast<FixedVectorType>(VTy)) {
896 for (
unsigned i = 0, e = FVTy->getNumElements(); i != e; ++i) {
897 Constant *ExtractIdx = ConstantInt::get(Ty, i);
905 Result.push_back(Res);
921 if (!isa<ConstantExpr>(
T) || cast<ConstantExpr>(
T)->
getOpcode() != Opcode)
924 }
else if (isa<ConstantExpr>(C2)) {
934 case Instruction::Add:
935 case Instruction::Sub:
937 case Instruction::Shl:
938 case Instruction::LShr:
939 case Instruction::AShr:
943 case Instruction::SDiv:
944 case Instruction::UDiv:
948 case Instruction::URem:
949 case Instruction::SRem:
964 auto isGlobalUnsafeForEquality = [](
const GlobalValue *GV) {
965 if (GV->isInterposable() || GV->hasGlobalUnnamedAddr())
967 if (
const auto *GVar = dyn_cast<GlobalVariable>(GV)) {
968 Type *Ty = GVar->getValueType();
980 if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
981 if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2))
982 return ICmpInst::ICMP_NE;
983 return ICmpInst::BAD_ICMP_PREDICATE;
994 "Cannot compare different types of values!");
995 if (V1 == V2)
return ICmpInst::ICMP_EQ;
999 return ICmpInst::BAD_ICMP_PREDICATE;
1005 auto GetComplexity = [](
Constant *V) {
1006 if (isa<ConstantExpr>(V))
1008 if (isa<GlobalValue>(V))
1010 if (isa<BlockAddress>(V))
1014 if (GetComplexity(V1) < GetComplexity(V2)) {
1016 if (SwappedRelation != ICmpInst::BAD_ICMP_PREDICATE)
1017 return ICmpInst::getSwappedPredicate(SwappedRelation);
1018 return ICmpInst::BAD_ICMP_PREDICATE;
1021 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(V1)) {
1023 if (
const BlockAddress *BA2 = dyn_cast<BlockAddress>(V2)) {
1027 if (BA2->getFunction() != BA->getFunction())
1028 return ICmpInst::ICMP_NE;
1029 }
else if (isa<ConstantPointerNull>(V2)) {
1030 return ICmpInst::ICMP_NE;
1032 }
else if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V1)) {
1035 if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1037 }
else if (isa<BlockAddress>(V2)) {
1038 return ICmpInst::ICMP_NE;
1039 }
else if (isa<ConstantPointerNull>(V2)) {
1045 if (!GV->hasExternalWeakLinkage() && !isa<GlobalAlias>(GV) &&
1047 GV->getType()->getAddressSpace()))
1048 return ICmpInst::ICMP_UGT;
1050 }
else if (
auto *CE1 = dyn_cast<ConstantExpr>(V1)) {
1055 switch (CE1->getOpcode()) {
1056 case Instruction::GetElementPtr: {
1060 if (isa<ConstantPointerNull>(V2)) {
1063 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1066 if (!GV->hasExternalWeakLinkage() && CE1GEP->
isInBounds())
1067 return ICmpInst::ICMP_UGT;
1069 }
else if (
const GlobalValue *GV2 = dyn_cast<GlobalValue>(V2)) {
1070 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CE1Op0)) {
1074 return ICmpInst::BAD_ICMP_PREDICATE;
1077 }
else if (
const auto *CE2GEP = dyn_cast<GEPOperator>(V2)) {
1080 const Constant *CE2Op0 = cast<Constant>(CE2GEP->getPointerOperand());
1081 if (isa<GlobalValue>(CE1Op0) && isa<GlobalValue>(CE2Op0)) {
1083 if (CE1Op0 != CE2Op0) {
1086 cast<GlobalValue>(CE2Op0));
1087 return ICmpInst::BAD_ICMP_PREDICATE;
1098 return ICmpInst::BAD_ICMP_PREDICATE;
1106 VT->getElementCount());
1111 if (Predicate == FCmpInst::FCMP_FALSE)
1114 if (Predicate == FCmpInst::FCMP_TRUE)
1118 if (isa<PoisonValue>(C1) || isa<PoisonValue>(C2))
1121 if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) {
1122 bool isIntegerPredicate = ICmpInst::isIntPredicate(Predicate);
1131 if (isIntegerPredicate)
1143 if (Predicate == ICmpInst::ICMP_UGE)
1146 if (Predicate == ICmpInst::ICMP_ULT)
1152 switch (Predicate) {
1153 case ICmpInst::ICMP_EQ:
1154 if (isa<ConstantInt>(C2))
1157 case ICmpInst::ICMP_NE:
1164 if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
1165 const APInt &V1 = cast<ConstantInt>(C1)->getValue();
1166 const APInt &V2 = cast<ConstantInt>(C2)->getValue();
1168 }
else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1169 const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF();
1170 const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF();
1172 }
else if (
auto *C1VTy = dyn_cast<VectorType>(C1->
getType())) {
1183 if (isa<ScalableVectorType>(C1VTy))
1191 for (
unsigned I = 0, E = C1VTy->getElementCount().getKnownMinValue();
1210 if (Predicate == FCmpInst::FCMP_ONE)
1212 else if (Predicate == FCmpInst::FCMP_UEQ)
1220 case ICmpInst::BAD_ICMP_PREDICATE:
1222 case ICmpInst::ICMP_EQ:
1225 Result = ICmpInst::isTrueWhenEqual(Predicate);
1227 case ICmpInst::ICMP_ULT:
1228 switch (Predicate) {
1229 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_ULE:
1231 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_UGE:
1237 case ICmpInst::ICMP_SLT:
1238 switch (Predicate) {
1239 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SLE:
1241 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SGE:
1247 case ICmpInst::ICMP_UGT:
1248 switch (Predicate) {
1249 case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_UGE:
1251 case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_ULE:
1257 case ICmpInst::ICMP_SGT:
1258 switch (Predicate) {
1259 case ICmpInst::ICMP_SGT:
case ICmpInst::ICMP_NE:
case ICmpInst::ICMP_SGE:
1261 case ICmpInst::ICMP_SLT:
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_SLE:
1267 case ICmpInst::ICMP_ULE:
1268 if (Predicate == ICmpInst::ICMP_UGT)
1270 if (Predicate == ICmpInst::ICMP_ULT || Predicate == ICmpInst::ICMP_ULE)
1273 case ICmpInst::ICMP_SLE:
1274 if (Predicate == ICmpInst::ICMP_SGT)
1276 if (Predicate == ICmpInst::ICMP_SLT || Predicate == ICmpInst::ICMP_SLE)
1279 case ICmpInst::ICMP_UGE:
1280 if (Predicate == ICmpInst::ICMP_ULT)
1282 if (Predicate == ICmpInst::ICMP_UGT || Predicate == ICmpInst::ICMP_UGE)
1285 case ICmpInst::ICMP_SGE:
1286 if (Predicate == ICmpInst::ICMP_SLT)
1288 if (Predicate == ICmpInst::ICMP_SGT || Predicate == ICmpInst::ICMP_SGE)
1291 case ICmpInst::ICMP_NE:
1292 if (Predicate == ICmpInst::ICMP_EQ)
1294 if (Predicate == ICmpInst::ICMP_NE)
1301 return ConstantInt::get(ResultTy, Result);
1303 if ((!isa<ConstantExpr>(C1) && isa<ConstantExpr>(C2)) ||
1308 Predicate = ICmpInst::getSwappedPredicate(Predicate);
1316 std::optional<ConstantRange>
InRange,
1318 if (Idxs.
empty())
return C;
1323 if (isa<PoisonValue>(
C))
1326 if (isa<UndefValue>(
C))
1329 auto IsNoOp = [&]() {
1336 return IdxC->
isNullValue() || isa<UndefValue>(IdxC);
1340 return GEPTy->
isVectorTy() && !
C->getType()->isVectorTy()
1342 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
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
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 * getBinOpAbsorber(unsigned Opcode, Type *Ty, bool AllowLHSConstant=false)
Return the absorbing element for the given binary operation, i.e.
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 isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
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.
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 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.
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
#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.