44#include "llvm/IR/IntrinsicsAArch64.h"
55#define DEBUG_TYPE "instsimplify"
103 Value *CLHS = Cmp->getOperand(0), *CRHS = Cmp->getOperand(1);
104 if (CPred == Pred && CLHS ==
LHS && CRHS ==
RHS)
117 unsigned MaxRecurse,
Constant *TrueOrFalse) {
119 if (SimplifiedCmp ==
Cond) {
127 return SimplifiedCmp;
133 unsigned MaxRecurse) {
141 unsigned MaxRecurse) {
151 unsigned MaxRecurse) {
202 if (!
B ||
B->getOpcode() != OpcodeToExpand)
204 Value *B0 =
B->getOperand(0), *B1 =
B->getOperand(1);
215 if ((L == B0 && R == B1) ||
236 unsigned MaxRecurse) {
253 unsigned MaxRecurse) {
356 unsigned MaxRecurse) {
393 if (TV ==
SI->getTrueValue() && FV ==
SI->getFalseValue())
399 if ((FV && !TV) || (TV && !FV)) {
403 if (Simplified && Simplified->getOpcode() ==
unsigned(Opcode) &&
404 !Simplified->hasPoisonGeneratingFlags()) {
408 Value *UnsimplifiedBranch = FV ?
SI->getTrueValue() :
SI->getFalseValue();
409 Value *UnsimplifiedLHS =
SI ==
LHS ? UnsimplifiedBranch :
LHS;
410 Value *UnsimplifiedRHS =
SI ==
LHS ?
RHS : UnsimplifiedBranch;
411 if (Simplified->getOperand(0) == UnsimplifiedLHS &&
412 Simplified->getOperand(1) == UnsimplifiedRHS)
414 if (Simplified->isCommutative() &&
415 Simplified->getOperand(1) == UnsimplifiedLHS &&
416 Simplified->getOperand(0) == UnsimplifiedRHS)
447 Value *TV =
SI->getTrueValue();
448 Value *FV =
SI->getFalseValue();
468 if (
Cond->getType()->isVectorTy() ==
RHS->getType()->isVectorTy())
480 unsigned MaxRecurse) {
500 Value *CommonValue =
nullptr;
513 if (!V || (CommonValue && V != CommonValue))
544 Value *CommonValue =
nullptr;
558 if (!V || (CommonValue && V != CommonValue))
574 case Instruction::FAdd:
575 case Instruction::FSub:
576 case Instruction::FMul:
577 case Instruction::FDiv:
578 case Instruction::FRem:
579 if (Q.
CxtI !=
nullptr)
663 return ::simplifyAddInst(Op0, Op1, IsNSW, IsNUW, Query,
RecursionLimit);
676 assert(V->getType()->isPtrOrPtrVectorTy());
679 V = V->stripAndAccumulateConstantOffsets(
DL,
Offset,
683 return Offset.sextOrTrunc(
DL.getIndexTypeSizeInBits(V->getType()));
702 Constant *Res = ConstantInt::get(
LHS->getContext(), LHSOffset - RHSOffset);
718 std::optional<bool> Imp =
723 case Instruction::Sub:
724 case Instruction::Xor:
725 case Instruction::URem:
726 case Instruction::SRem:
729 case Instruction::SDiv:
730 case Instruction::UDiv:
731 return ConstantInt::get(Ty, 1);
733 case Instruction::And:
734 case Instruction::Or:
776 if (
Known.Zero.isMaxSignedValue()) {
789 Value *
X =
nullptr, *
Y =
nullptr, *Z = Op1;
847 if (
X->getType() ==
Y->getType())
894 return ::simplifySubInst(Op0, Op1, IsNSW, IsNUW, Q,
RecursionLimit);
944 Instruction::Add, Q, MaxRecurse))
966 return ::simplifyMulInst(Op0, Op1, IsNSW, IsNUW, Q,
RecursionLimit);
976 return (
C &&
C->isAllOnesValue());
982 unsigned MaxRecurse,
bool IsSigned) {
999 Type *Ty =
X->getType();
1005 Constant *PosDividendC = ConstantInt::get(Ty,
C->abs());
1006 Constant *NegDividendC = ConstantInt::get(Ty, -
C->abs());
1015 if (
C->isMinSignedValue())
1021 Constant *PosDivisorC = ConstantInt::get(Ty,
C->abs());
1022 Constant *NegDivisorC = ConstantInt::get(Ty, -
C->abs());
1048 unsigned MaxRecurse) {
1049 bool IsDiv = (Opcode == Instruction::SDiv || Opcode == Instruction::UDiv);
1050 bool IsSigned = (Opcode == Instruction::SDiv || Opcode == Instruction::SRem);
1099 if (
Known.countMinLeadingZeros() ==
Known.getBitWidth() - 1)
1118 if (
isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1142 unsigned MaxRecurse) {
1165 (Opcode == Instruction::UDiv
1185 if ((Opcode == Instruction::SRem &&
1187 (Opcode == Instruction::URem &&
1195 if (Opcode == Instruction::SRem
1198 return C.srem(*C0).isZero();
1202 return C.urem(*C0).isZero();
1218 return simplifyDiv(Instruction::SDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1230 return simplifyDiv(Instruction::UDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1241 unsigned MaxRecurse) {
1252 return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
1262 unsigned MaxRecurse) {
1263 return simplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse);
1282 const APInt *AmountC;
1289 for (
unsigned I = 0,
1304 unsigned MaxRecurse) {
1354 assert(Opcode == Instruction::Shl &&
"Expected shl for nsw instruction");
1373 Value *Op1,
bool IsExact,
1392 if (Op0Known.
One[0])
1404 simplifyShift(Instruction::Shl, Op0, Op1, IsNSW, Q, MaxRecurse))
1428 if (IsNSW && IsNUW &&
1437 return ::simplifyShlInst(Op0, Op1, IsNSW, IsNUW, Q,
RecursionLimit);
1459 const APInt *ShRAmt, *ShLAmt;
1462 *ShRAmt == *ShLAmt) {
1465 if (ShRAmt->
uge(EffWidthY))
1513 ICmpInst *UnsignedICmp,
bool IsAnd,
1527 if (
match(UnsignedICmp,
1545 return IsAnd ? UnsignedICmp : ZeroICmp;
1551 return IsAnd ? ZeroICmp : UnsignedICmp;
1557 if (
match(UnsignedICmp,
1561 return UnsignedICmp;
1564 return UnsignedICmp;
1571 else if (
match(UnsignedICmp,
1582 return IsAnd ? ZeroICmp : UnsignedICmp;
1588 return IsAnd ? UnsignedICmp : ZeroICmp;
1598 return IsAnd ? UnsignedICmp : ZeroICmp;
1603 return IsAnd ? ZeroICmp : UnsignedICmp;
1627 const APInt *C0, *C1;
1637 if (IsAnd && Range0.intersectWith(Range1).isEmptySet())
1642 if (!IsAnd && Range0.unionWith(Range1).isFullSet())
1650 if (Range0.contains(Range1))
1651 return IsAnd ? Cmp1 : Cmp0;
1652 if (Range1.contains(Range0))
1653 return IsAnd ? Cmp0 : Cmp1;
1662 const APInt *C0, *C1;
1671 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1678 const APInt Delta = *C1 - *C0;
1752 const APInt *C0, *C1;
1761 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1768 const APInt Delta = *C1 - *C0;
1837 if (!Range0 || !Range1)
1842 if (Range0->intersectWith(*Range1).isEmptySet())
1850 if (Range0->contains(*Range1))
1852 if (Range1->contains(*Range0))
1860 Value *LHS0 =
LHS->getOperand(0), *LHS1 =
LHS->getOperand(1);
1861 Value *RHS0 =
RHS->getOperand(0), *RHS1 =
RHS->getOperand(1);
1874 if ((
match(RHS0, AbsOrSelfLHS0) ||
match(RHS1, AbsOrSelfLHS0)) &&
1889 if ((
match(LHS0, AbsOrSelfRHS0) ||
match(LHS1, AbsOrSelfRHS0)) &&
1903 Value *Op1,
bool IsAnd) {
1907 if (Cast0 && Cast1 && Cast0->getOpcode() == Cast1->getOpcode() &&
1908 Cast0->getSrcTy() == Cast1->getSrcTy()) {
1909 Op0 = Cast0->getOperand(0);
1910 Op1 = Cast1->getOperand(0);
1941 bool AllowRefinement,
1943 unsigned MaxRecurse);
1947 unsigned MaxRecurse) {
1948 assert((Opcode == Instruction::And || Opcode == Instruction::Or) &&
1964 if (Res == Absorber)
1974 if (Res == Absorber)
1984 nullptr, MaxRecurse))
1985 return Simplify(Res);
1988 nullptr, MaxRecurse))
1989 return Simplify(Res);
2021 unsigned MaxRecurse) {
2055 const APInt *Shift1, *Shift2;
2059 Shift1->
uge(*Shift2))
2072 unsigned MaxRecurse) {
2112 (~(*Mask)).lshr(*ShAmt).isZero())
2118 (~(*Mask)).shl(*ShAmt).isZero())
2123 const APInt *PowerC;
2155 Instruction::Or, Q, MaxRecurse))
2160 Instruction::Xor, Q, MaxRecurse))
2205 if (EffWidthY <= ShftCnt) {
2238 if (*Implied ==
true)
2241 if (*Implied ==
false)
2266 assert(
X->getType() ==
Y->getType() &&
"Expected same type for 'or' ops");
2267 Type *Ty =
X->getType();
2357 unsigned MaxRecurse) {
2396 C->ule(
X->getType()->getScalarSizeInBits())) {
2461 Instruction::And, Q, MaxRecurse))
2482 const APInt *C1, *C2;
2518 if (std::optional<bool> Implied =
2521 if (*Implied ==
false)
2524 if (*Implied ==
true)
2527 if (std::optional<bool> Implied =
2530 if (*Implied ==
false)
2533 if (*Implied ==
true)
2551 unsigned MaxRecurse) {
2593 if (
Value *R = foldAndOrNot(Op0, Op1))
2595 if (
Value *R = foldAndOrNot(Op1, Op0))
2648 Value *CmpLHS = Cmp->getOperand(0), *CmpRHS = Cmp->getOperand(1);
2649 if (Pred == Cmp->getPredicate() &&
LHS == CmpLHS &&
RHS == CmpRHS)
2652 LHS == CmpRHS &&
RHS == CmpLHS)
2659 return A &&
A->hasByValAttr();
2664 return A &&
A->getType()->isPointerTy() &&
A->getDereferenceableBytes() > 0;
2676 return AI->isStaticAlloca();
2678 return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
2679 GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
2680 !GV->isThreadLocal();
2772 assert(
LHS->getType() ==
RHS->getType() &&
"Must have same types");
2795 unsigned IndexSize =
DL.getIndexTypeSizeInBits(
LHS->getType());
2796 APInt LHSOffset(IndexSize, 0), RHSOffset(IndexSize, 0);
2797 LHS =
LHS->stripAndAccumulateConstantOffsets(
DL, LHSOffset, AllowNonInbounds);
2798 RHS =
RHS->stripAndAccumulateConstantOffsets(
DL, RHSOffset, AllowNonInbounds);
2818 Size = V->getPointerDereferenceableBytes(
DL, CanBeNull,
2820 return Size != 0 && !CanBeNull;
2824 if (GetKnownSize(
LHS, LHSSize) && GetKnownSize(
RHS, RHSSize)) {
2825 APInt Dist = LHSOffset - RHSOffset;
2853 if ((IsNoAliasCall(LHSUObjs) && IsAllocDisjoint(RHSUObjs)) ||
2854 (IsNoAliasCall(RHSUObjs) && IsAllocDisjoint(LHSUObjs)))
2874 bool Captured =
false;
2882 unsigned OtherIdx = 1 - U->getOperandNo();
2892 CustomCaptureTracker Tracker;
2894 if (!Tracker.Captured)
2909 if (!
OpTy->isIntOrIntVectorTy(1))
2916 auto ExtractNotLHS = [](
Value *V) ->
Value * {
3163 *MulC != 0 &&
C->urem(*MulC) != 0) ||
3165 *MulC != 0 &&
C->srem(*MulC) != 0)))
3180 unsigned Depth = 0) {
3181 if (!Res.
insert(V).second)
3208 switch (
I->getOpcode()) {
3209 case Instruction::And:
3213 case Instruction::URem:
3214 case Instruction::UDiv:
3215 case Instruction::LShr:
3218 case Instruction::Call:
3240 for (
Value *GV : GreaterValues)
3249 unsigned MaxRecurse) {
3273 if (!
Known.isNonNegative())
3284 if (!
Known.isNonNegative())
3333 const APInt *C1, *C2;
3380 const APInt *C1, *C2;
3394 unsigned MaxRecurse) {
3397 if (MaxRecurse && (LBO || RBO)) {
3399 Value *
A =
nullptr, *
B =
nullptr, *
C =
nullptr, *
D =
nullptr;
3401 bool NoLHSWrapProblem =
false, NoRHSWrapProblem =
false;
3402 if (LBO && LBO->
getOpcode() == Instruction::Add) {
3412 if (RBO && RBO->
getOpcode() == Instruction::Add) {
3424 if ((
A ==
RHS ||
B ==
RHS) && NoLHSWrapProblem)
3431 if ((
C ==
LHS ||
D ==
LHS) && NoRHSWrapProblem)
3434 C ==
LHS ?
D :
C, Q, MaxRecurse - 1))
3438 bool CanSimplify = (NoLHSWrapProblem && NoRHSWrapProblem) ||
3440 if (
A &&
C && (
A ==
C ||
A ==
D ||
B ==
C ||
B ==
D) && CanSimplify) {
3447 }
else if (
A ==
D) {
3451 }
else if (
B ==
C) {
3479 if (
C->isStrictlyPositive()) {
3485 if (
C->isNonNegative()) {
3535 case Instruction::Shl: {
3551 case Instruction::And:
3552 case Instruction::Or: {
3553 const APInt *C1, *C2;
3583 case Instruction::UDiv:
3584 case Instruction::LShr:
3592 case Instruction::SDiv:
3600 case Instruction::AShr:
3607 case Instruction::Shl: {
3628 unsigned MaxRecurse) {
3790 (
A ==
C ||
A ==
D ||
B ==
C ||
B ==
D)) {
3799 (
A ==
C ||
A ==
D ||
B ==
C ||
B ==
D)) {
3840 switch (
II->getIntrinsicID()) {
3841 case Intrinsic::uadd_sat:
3851 case Intrinsic::usub_sat:
3874 return A->getRange();
3876 return CB->getRange();
3878 return std::nullopt;
3929 if (LhsCr->icmp(Pred, *RhsCr))
3956 if (RI->getOperand(0)->getType() == SrcTy)
3968 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
3972 RI->getOperand(0), Q, MaxRecurse - 1))
3977 if (
SrcOp == RI->getOperand(0)) {
3994 assert(Trunc &&
"Constant-fold of ImmConstant should not fail");
3997 assert(RExt &&
"Constant-fold of ImmConstant should not fail");
4000 assert(AnyEq &&
"Constant-fold of ImmConstant should not fail");
4007 SrcOp, Trunc, Q, MaxRecurse - 1))
4048 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
4056 if (
SrcOp == RI->getOperand(0)) {
4072 assert(Trunc &&
"Constant-fold of ImmConstant should not fail");
4075 assert(RExt &&
"Constant-fold of ImmConstant should not fail");
4078 assert(AnyEq &&
"Constant-fold of ImmConstant should not fail");
4090 switch (Pred.getPreferredSignedPredicate()) {
4166 if (std::optional<bool> Res =
4172 if (
LHS->getType()->isPointerTy())
4193 return ::simplifyICmpInst(Predicate, LHS, RHS, Q,
RecursionLimit);
4200 unsigned MaxRecurse) {
4260 if (std::optional<bool> Res =
4266 std::optional<KnownFPClass> FullKnownClassLHS;
4270 auto computeLHSClass = [=, &FullKnownClassLHS](
FPClassTest InterestedFlags =
4272 if (FullKnownClassLHS)
4273 return *FullKnownClassLHS;
4286 FullKnownClassLHS = computeLHSClass();
4287 if ((FullKnownClassLHS->KnownFPClasses & ClassTest) ==
fcNone)
4289 if ((FullKnownClassLHS->KnownFPClasses & ~ClassTest) ==
fcNone)
4304 if (
C->isNegative() && !
C->isNegZero()) {
4338 if ((IsMax && *C2 > *
C) || (IsMin && *C2 < *
C)) {
4361 return ConstantInt::get(RetTy, IsMax);
4370 return ConstantInt::get(RetTy, !IsMax);
4386 Interested |=
fcNan;
4393 Known.cannotBeOrderedLessThanZero())
4404 if (
Known.cannotBeOrderedLessThanZero())
4430 return ::simplifyFCmpInst(Predicate, LHS, RHS, FMF, Q,
RecursionLimit);
4436 bool AllowRefinement,
4438 unsigned MaxRecurse) {
4440 "If AllowRefinement=false then CanUseUndef=false");
4441 for (
const auto &OpAndRepOp :
Ops) {
4447 if (V == OpAndRepOp.first)
4448 return OpAndRepOp.second;
4471 for (
const auto &OpAndRepOp :
Ops) {
4474 if (OpAndRepOp.first->getType()->isVectorTy() &&
4481 bool AnyReplaced =
false;
4482 for (
Value *InstOp :
I->operands()) {
4484 InstOp,
Ops, Q, AllowRefinement, DropFlags, MaxRecurse)) {
4486 AnyReplaced = InstOp != NewInstOp;
4500 if (!AllowRefinement) {
4506 unsigned Opcode = BO->getOpcode();
4509 if (!BO->getType()->isFPOrFPVectorTy()) {
4518 if ((Opcode == Instruction::And || Opcode == Instruction::Or) &&
4519 NewOps[0] == NewOps[1]) {
4522 if (PDI->isDisjoint()) {
4534 if ((Opcode == Instruction::Sub || Opcode == Instruction::Xor) &&
4535 NewOps[0] == NewOps[1] &&
4536 any_of(
Ops, [=](
const auto &Rep) {
return NewOps[0] == Rep.second; }))
4547 if ((NewOps[0] == Absorber || NewOps[1] == Absorber) &&
4549 [=](
const auto &Rep) {
return impliesPoison(BO, Rep.first); }))
4556 if ((
II->getIntrinsicID() == Intrinsic::scmp ||
4557 II->getIntrinsicID() == Intrinsic::ucmp) &&
4558 NewOps[0] == NewOps[1]) {
4559 if (
II->hasPoisonGeneratingAnnotations()) {
4566 return ConstantInt::get(
I->getType(), 0);
4570 const APInt Identity = MMI->getIdentity();
4572 Value *Result =
nullptr;
4579 if (
II->hasPoisonGeneratingAnnotations()) {
4607 auto PreventSelfSimplify = [V](
Value *Simplified) {
4608 return Simplified != V ? Simplified :
nullptr;
4611 return PreventSelfSimplify(
4618 for (
Value *NewOp : NewOps) {
4634 if (!AllowRefinement) {
4638 if (
II &&
II->getIntrinsicID() == Intrinsic::abs) {
4639 if (!ConstOps[0]->isNotMinSignedValue())
4645 if (DropFlags &&
II) {
4649 switch (
II->getIntrinsicID()) {
4650 case Intrinsic::abs:
4651 case Intrinsic::ctlz:
4652 case Intrinsic::cttz:
4662 if (DropFlags && Res &&
I->hasPoisonGeneratingAnnotations())
4673 bool AllowRefinement,
4675 unsigned MaxRecurse) {
4677 DropFlags, MaxRecurse);
4682 bool AllowRefinement,
4686 if (!AllowRefinement)
4689 return ::simplifyWithOpReplaced(V,
Op, RepOp, Q, AllowRefinement, DropFlags,
4696 const APInt *
Y,
bool TrueWhenUnset) {
4703 return TrueWhenUnset ? FalseVal : TrueVal;
4709 return TrueWhenUnset ? FalseVal : TrueVal;
4711 if (
Y->isPowerOf2()) {
4719 return TrueWhenUnset ? TrueVal : FalseVal;
4729 return TrueWhenUnset ? TrueVal : FalseVal;
4740 if (CmpRHS == TVal || CmpRHS == FVal) {
4746 if (CmpLHS == FVal) {
4753 Value *
X = CmpLHS, *
Y = CmpRHS;
4754 bool PeekedThroughSelectShuffle =
false;
4756 if (Shuf && Shuf->isSelect()) {
4757 if (Shuf->getOperand(0) ==
Y)
4758 FVal = Shuf->getOperand(1);
4759 else if (Shuf->getOperand(1) ==
Y)
4760 FVal = Shuf->getOperand(0);
4763 PeekedThroughSelectShuffle =
true;
4768 if (!MMI || TVal !=
X ||
4786 if (PeekedThroughSelectShuffle)
4822 ArrayRef<std::pair<Value *, Value *>> Replacements,
Value *TrueVal,
4824 Value *SimplifiedFalseVal =
4827 nullptr, MaxRecurse);
4828 if (!SimplifiedFalseVal)
4829 SimplifiedFalseVal = FalseVal;
4831 Value *SimplifiedTrueVal =
4834 nullptr, MaxRecurse);
4835 if (!SimplifiedTrueVal)
4836 SimplifiedTrueVal = TrueVal;
4838 if (SimplifiedFalseVal == SimplifiedTrueVal)
4849 unsigned MaxRecurse) {
4851 Value *CmpLHS, *CmpRHS;
4867 if (TrueVal->getType()->isIntOrIntVectorTy()) {
4875 X->getType()->getScalarSizeInBits());
4895 if (
match(TrueVal, isFsh) && FalseVal ==
X && CmpLHS == ShAmt)
4908 if (
match(FalseVal, isRotate) && TrueVal ==
X && CmpLHS == ShAmt &&
4930 FalseVal, Q, MaxRecurse))
4935 FalseVal, Q, MaxRecurse))
4945 {{
X, CmpRHS}, {
Y, CmpRHS}}, TrueVal, FalseVal, Q, MaxRecurse))
4954 {{
X, CmpRHS}, {
Y, CmpRHS}}, TrueVal, FalseVal, Q, MaxRecurse))
4966 unsigned MaxRecurse) {
4968 Value *CmpLHS, *CmpRHS;
4973 bool IsEquiv =
I->isEquivalence();
4974 if (
I->isEquivalence(
true)) {
4992 if (CmpLHS ==
F && CmpRHS ==
T)
4995 if (CmpLHS !=
T || CmpRHS !=
F)
5048 unsigned DiffVals = 0;
5050 for (
unsigned i = 0; i < 2; i++) {
5066 if (!
SI || !IdenticalSI)
5068 if (
SI->getCondition() != IdenticalSI->getCondition())
5072 Value *IdenticalSIOtherVal =
nullptr;
5073 if (
SI->getTrueValue() == IdenticalSI->getTrueValue()) {
5075 IdenticalSIOtherVal = IdenticalSI->getFalseValue();
5076 }
else if (
SI->getFalseValue() == IdenticalSI->getFalseValue()) {
5078 IdenticalSIOtherVal = IdenticalSI->getTrueValue();
5085 if (!SIOtherVal || IdenticalSIOtherVal != &IdenticalPN)
5099 unsigned MaxRecurse) {
5124 assert(
Cond->getType()->isIntOrIntVectorTy(1) &&
5125 "Select must have bool or bool vector condition");
5126 assert(TrueVal->getType() == FalseVal->getType() &&
5127 "Select must have same types for true/false ops");
5129 if (
Cond->getType() == TrueVal->getType()) {
5192 if (TrueVal == FalseVal)
5195 if (
Cond == TrueVal) {
5203 if (
Cond == FalseVal) {
5234 for (
unsigned i = 0; i != NumElts; ++i) {
5238 if (!TEltC || !FEltC)
5254 if (NewC.
size() == NumElts)
5271 return *Imp ? TrueVal : FalseVal;
5298 if (Indices.
empty())
5328 bool IsScalableVec =
5329 SrcTy->isScalableTy() ||
any_of(Indices, [](
const Value *V) {
5333 if (Indices.
size() == 1) {
5335 if (!IsScalableVec && Ty->isSized()) {
5340 if (TyAllocSize == 0 && Ptr->
getType() == GEPTy)
5348 auto CanSimplify = [GEPTy, &
P, Ptr]() ->
bool {
5349 return P->getType() == GEPTy &&
5353 if (TyAllocSize == 1 &&
5364 TyAllocSize == 1ULL <<
C && CanSimplify())
5383 APInt BasePtrOffset(IdxWidth, 0);
5384 Value *StrippedBasePtr =
5394 !BasePtrOffset.
isZero()) {
5395 auto *CI = ConstantInt::get(GEPTy->
getContext(), BasePtrOffset);
5401 !BasePtrOffset.
isOne()) {
5402 auto *CI = ConstantInt::get(GEPTy->
getContext(), BasePtrOffset - 1);
5423 return ::simplifyGEPInst(SrcTy, Ptr, Indices, NW, Q,
RecursionLimit);
5443 if (EV->getAggregateOperand()->getType() == Agg->
getType() &&
5444 EV->getIndices() == Idxs) {
5450 return EV->getAggregateOperand();
5453 if (Agg == EV->getAggregateOperand())
5463 return ::simplifyInsertValueInst(Agg, Val, Idxs, Q,
RecursionLimit);
5472 if (VecC && ValC && IdxC)
5493 if (VecC && ValC && VecC->getSplatValue() == ValC)
5513 unsigned NumIdxs = Idxs.
size();
5518 if (!VisitedSet.
insert(IVI).second)
5522 unsigned NumInsertValueIdxs = InsertValueIdxs.
size();
5523 unsigned NumCommonIdxs = std::min(NumInsertValueIdxs, NumIdxs);
5524 if (InsertValueIdxs.
slice(0, NumCommonIdxs) ==
5525 Idxs.
slice(0, NumCommonIdxs)) {
5526 if (NumIdxs == NumInsertValueIdxs)
5527 return IVI->getInsertedValueOperand();
5534 if (Idxs.
size() == 1 &&
5541 assert(Idxs[0] == 1 &&
"invalid index");
5575 unsigned MinNumElts = VecVTy->getElementCount().getKnownMinValue();
5579 if (IdxC->getValue().ult(MinNumElts))
5590 if (IE && IE->getOperand(2) == Idx)
5591 return IE->getOperand(1);
5602 return ::simplifyExtractElementInst(Vec, Idx, Q,
RecursionLimit);
5614 Value *CommonValue =
nullptr;
5615 bool HasPoisonInput =
false;
5616 bool HasUndefInput =
false;
5617 for (
Value *Incoming : IncomingValues) {
5622 HasPoisonInput =
true;
5627 HasUndefInput =
true;
5630 if (CommonValue && Incoming != CommonValue)
5632 CommonValue = Incoming;
5641 if (HasPoisonInput || HasUndefInput) {
5649 if (HasUndefInput &&
5664 auto *Src = CI->getOperand(0);
5665 Type *SrcTy = Src->getType();
5666 Type *MidTy = CI->getType();
5668 if (Src->getType() == Ty) {
5669 auto FirstOp = CI->getOpcode();
5672 &Q.
DL) == Instruction::BitCast)
5678 if (CastOpc == Instruction::BitCast)
5679 if (
Op->getType() == Ty)
5684 if ((CastOpc == Instruction::PtrToInt || CastOpc == Instruction::PtrToAddr) &&
5692 if (CastOpc == Instruction::ZExt || CastOpc == Instruction::SExt) {
5694 Value *Src = Trunc->getOperand(0);
5695 bool NoWrap = CastOpc == Instruction::ZExt ? Trunc->hasNoUnsignedWrap()
5696 : Trunc->hasNoSignedWrap();
5697 if (Src->getType() == Ty && NoWrap)
5712 unsigned MaxRecurse) {
5715 Op->getType()->getPointerAddressSpace()))
5718 return ::simplifyCastInst(Instruction::AddrSpaceCast,
Op, Ty, Q, MaxRecurse);
5730 int MaskVal,
Value *RootVec,
5731 unsigned MaxRecurse) {
5742 int RootElt = MaskVal;
5743 Value *SourceOp = Op0;
5744 if (MaskVal >= InVecNumElts) {
5745 RootElt = MaskVal - InVecNumElts;
5753 DestElt, SourceShuf->getOperand(0), SourceShuf->getOperand(1),
5754 SourceShuf->getMaskValue(RootElt), RootVec, MaxRecurse);
5763 if (RootVec != SourceOp)
5768 if (RootElt != DestElt)
5777 unsigned MaxRecurse) {
5782 unsigned MaskNumElts = Mask.size();
5783 ElementCount InVecEltCount = InVecTy->getElementCount();
5788 Indices.
assign(Mask.begin(), Mask.end());
5793 bool MaskSelects0 =
false, MaskSelects1 =
false;
5795 for (
unsigned i = 0; i != MaskNumElts; ++i) {
5796 if (Indices[i] == -1)
5798 if ((
unsigned)Indices[i] < InVecNumElts)
5799 MaskSelects0 =
true;
5801 MaskSelects1 =
true;
5815 if (Op0Const && Op1Const)
5821 if (!Scalable && Op0Const && !Op1Const) {
5839 if (
all_of(Indices, [InsertIndex](
int MaskElt) {
5840 return MaskElt == InsertIndex || MaskElt == -1;
5846 for (
unsigned i = 0; i != MaskNumElts; ++i)
5847 if (Indices[i] == -1)
5875 Value *RootVec =
nullptr;
5876 for (
unsigned i = 0; i != MaskNumElts; ++i) {
5883 if (!RootVec || RootVec->
getType() != RetTy)
5893 return ::simplifyShuffleVectorInst(Op0, Op1, Mask, RetTy, Q,
RecursionLimit);
5926 Type *Ty = In->getType();
5928 unsigned NumElts = VecTy->getNumElements();
5930 for (
unsigned i = 0; i != NumElts; ++i) {
5931 Constant *EltC = In->getAggregateElement(i);
5936 else if (EltC && EltC->
isNaN())
5937 NewC[i] = ConstantFP::get(
5953 auto *
Splat = In->getSplatValue();
5955 "Found a scalable-vector NaN but not a splat");
5984 if (FMF.
noNaNs() && (IsNan || IsUndef))
5986 if (FMF.
noInfs() && (IsInf || IsUndef))
6170 if (
Known.getSignBit() ==
false)
6173 if (
Known.getSignBit() ==
true)
6201 return simplifyFMAFMul(Op0, Op1, FMF, Q, MaxRecurse, ExBehavior, Rounding);
6208 return ::simplifyFAddInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6216 return ::simplifyFSubInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6224 return ::simplifyFMulInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6232 return ::simplifyFMAFMul(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6265 return ConstantFP::get(Op0->
getType(), 1.0);
6277 return ConstantFP::get(Op0->
getType(), -1.0);
6291 return ::simplifyFDivInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6329 return ::simplifyFRemInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6338 unsigned MaxRecurse) {
6340 case Instruction::FNeg:
6352 unsigned MaxRecurse) {
6354 case Instruction::FNeg:
6375 case Instruction::Add:
6378 case Instruction::Sub:
6381 case Instruction::Mul:
6384 case Instruction::SDiv:
6386 case Instruction::UDiv:
6388 case Instruction::SRem:
6390 case Instruction::URem:
6392 case Instruction::Shl:
6395 case Instruction::LShr:
6397 case Instruction::AShr:
6399 case Instruction::And:
6401 case Instruction::Or:
6403 case Instruction::Xor:
6405 case Instruction::FAdd:
6407 case Instruction::FSub:
6409 case Instruction::FMul:
6411 case Instruction::FDiv:
6413 case Instruction::FRem:
6425 unsigned MaxRecurse) {
6427 case Instruction::FAdd:
6429 case Instruction::FSub:
6431 case Instruction::FMul:
6433 case Instruction::FDiv:
6447 return ::simplifyBinOp(Opcode, LHS, RHS, FMF, Q,
RecursionLimit);
6460 return ::simplifyCmpInst(Predicate, LHS, RHS, Q,
RecursionLimit);
6469 case Intrinsic::fabs:
6470 case Intrinsic::floor:
6471 case Intrinsic::ceil:
6472 case Intrinsic::trunc:
6473 case Intrinsic::rint:
6474 case Intrinsic::nearbyint:
6475 case Intrinsic::round:
6476 case Intrinsic::roundeven:
6477 case Intrinsic::canonicalize:
6478 case Intrinsic::arithmetic_fence:
6490 case Intrinsic::floor:
6491 case Intrinsic::ceil:
6492 case Intrinsic::trunc:
6493 case Intrinsic::rint:
6494 case Intrinsic::nearbyint:
6495 case Intrinsic::round:
6496 case Intrinsic::roundeven:
6511 if (!OffsetConstInt || OffsetConstInt->getBitWidth() > 64)
6515 DL.getIndexTypeSizeInBits(Ptr->
getType()));
6516 if (OffsetInt.
srem(4) != 0)
6528 if (LoadedCE->getOpcode() == Instruction::Trunc) {
6534 if (LoadedCE->getOpcode() != Instruction::Sub)
6538 if (!LoadedLHS || LoadedLHS->getOpcode() != Instruction::PtrToInt)
6540 auto *LoadedLHSPtr = LoadedLHS->getOperand(0);
6544 APInt LoadedRHSOffset;
6547 PtrSym != LoadedRHSSym || PtrOffset != LoadedRHSOffset)
6550 return LoadedLHSPtr;
6581 if (
C && (
C->isZero() ||
C->isInfinity()))
6590 if (
C &&
C->isNaN())
6591 return ConstantFP::get(Op0->
getType(),
C->makeQuiet());
6609 if (
II->getIntrinsicID() == IID)
6626 case Intrinsic::fabs: {
6637 case Intrinsic::bswap:
6642 case Intrinsic::bitreverse:
6647 case Intrinsic::ctpop: {
6650 return ConstantInt::get(Op0->
getType(), 1);
6659 case Intrinsic::exp:
6665 case Intrinsic::exp2:
6671 case Intrinsic::exp10:
6677 case Intrinsic::log:
6683 case Intrinsic::log2:
6691 case Intrinsic::log10:
6700 case Intrinsic::vector_reverse:
6708 case Intrinsic::structured_gep:
6730 if (Op1 ==
X || Op1 ==
Y ||
6749 case Intrinsic::maxnum:
6750 case Intrinsic::minnum:
6751 case Intrinsic::maximum:
6752 case Intrinsic::minimum:
6753 case Intrinsic::maximumnum:
6754 case Intrinsic::minimumnum:
6761 assert(IsMinimumMaximumIntrinsic(IID) &&
"Unsupported intrinsic");
6767 if (!
M0 ||
M0->getIntrinsicID() != IID)
6769 Value *X0 =
M0->getOperand(0);
6770 Value *Y0 =
M0->getOperand(1);
6777 if (X0 == Op1 || Y0 == Op1)
6781 if (!
M1 || !IsMinimumMaximumIntrinsic(
M1->getIntrinsicID()))
6783 Value *X1 =
M1->getOperand(0);
6784 Value *Y1 =
M1->getOperand(1);
6792 if ((X0 == X1 && Y0 == Y1) || (X0 == Y1 && Y0 == X1))
6815 assert(OutNewConstVal !=
nullptr);
6817 bool PropagateNaN = IID == Intrinsic::minimum || IID == Intrinsic::maximum;
6818 bool PropagateSNaN = IID == Intrinsic::minnum || IID == Intrinsic::maxnum;
6819 bool IsMin = IID == Intrinsic::minimum || IID == Intrinsic::minnum ||
6820 IID == Intrinsic::minimumnum;
6824 *OutNewConstVal =
const_cast<Constant *
>(RHSConst);
6842 if (PropagateNaN || (PropagateSNaN && CAPF.
isSignaling())) {
6857 *OutNewConstVal =
const_cast<Constant *
>(RHSConst);
6877 unsigned Width = ReturnType->getPrimitiveSizeInBits();
6881 case Intrinsic::aarch64_sve_eorv:
6882 case Intrinsic::aarch64_sve_orv:
6883 case Intrinsic::aarch64_sve_saddv:
6884 case Intrinsic::aarch64_sve_uaddv:
6885 case Intrinsic::aarch64_sve_umaxv:
6887 return ConstantInt::get(ReturnType, 0);
6889 case Intrinsic::aarch64_sve_andv:
6890 case Intrinsic::aarch64_sve_uminv:
6894 case Intrinsic::aarch64_sve_smaxv:
6898 case Intrinsic::aarch64_sve_sminv:
6905 case Intrinsic::aarch64_sve_andv:
6906 case Intrinsic::aarch64_sve_orv:
6907 case Intrinsic::aarch64_sve_smaxv:
6908 case Intrinsic::aarch64_sve_sminv:
6909 case Intrinsic::aarch64_sve_umaxv:
6910 case Intrinsic::aarch64_sve_uminv:
6914 assert(SplatVal->getType() == ReturnType &&
"Unexpected result type!");
6919 case Intrinsic::aarch64_sve_eorv:
6923 return ConstantInt::get(ReturnType, 0);
6933 unsigned BitWidth = ReturnType->getScalarSizeInBits();
6935 case Intrinsic::get_active_lane_mask: {
6944 Attribute Attr =
F->getFnAttribute(Attribute::VScaleRange);
6945 if (ScalableTy && Attr.
isValid()) {
6950 (
uint64_t)ScalableTy->getMinNumElements() * (*VScaleMax);
6952 const APInt *Op1Val;
6954 Op1Val->
uge(MaxPossibleMaskElements))
6959 case Intrinsic::abs:
6967 case Intrinsic::cttz: {
6973 case Intrinsic::ctlz: {
6981 case Intrinsic::pdep: {
6990 case Intrinsic::pext: {
6999 case Intrinsic::ptrmask: {
7007 "Invalid mask width");
7024 APInt IrrelevantPtrBits =
7027 Instruction::Or,
C, ConstantInt::get(
C->getType(), IrrelevantPtrBits),
7029 if (
C !=
nullptr &&
C->isAllOnesValue())
7034 case Intrinsic::smax:
7035 case Intrinsic::smin:
7036 case Intrinsic::umax:
7037 case Intrinsic::umin: {
7048 return ConstantInt::get(
7056 return ConstantInt::get(ReturnType, *
C);
7068 if (MinMax0 && MinMax0->getIntrinsicID() == IID) {
7070 Value *M00 = MinMax0->getOperand(0), *M01 = MinMax0->getOperand(1);
7071 const APInt *InnerC;
7094 case Intrinsic::scmp:
7095 case Intrinsic::ucmp: {
7104 return ConstantInt::get(ReturnType, 1);
7113 case Intrinsic::usub_with_overflow:
7114 case Intrinsic::ssub_with_overflow:
7121 case Intrinsic::uadd_with_overflow:
7122 case Intrinsic::sadd_with_overflow:
7132 case Intrinsic::umul_with_overflow:
7133 case Intrinsic::smul_with_overflow:
7143 case Intrinsic::uadd_sat:
7149 case Intrinsic::sadd_sat:
7164 case Intrinsic::usub_sat:
7169 case Intrinsic::ssub_sat:
7177 case Intrinsic::load_relative:
7182 case Intrinsic::powi:
7185 if (Power->isZero())
7186 return ConstantFP::get(Op0->
getType(), 1.0);
7192 case Intrinsic::ldexp:
7194 case Intrinsic::copysign:
7204 case Intrinsic::is_fpclass: {
7208 return ConstantInt::get(ReturnType,
true);
7210 return ConstantInt::get(ReturnType,
false);
7215 case Intrinsic::maxnum:
7216 case Intrinsic::minnum:
7217 case Intrinsic::maximum:
7218 case Intrinsic::minimum:
7219 case Intrinsic::maximumnum:
7220 case Intrinsic::minimumnum: {
7243 if (
Constant *SplatVal =
C->getSplatValue()) {
7249 }
else if (ElemCount.
isFixed()) {
7259 auto *Elt =
C->getAggregateElement(i);
7266 (ElemResult != OptResult &&
7274 OptResult = ElemResult;
7300 case Intrinsic::vector_extract: {
7306 IdxN == 0 &&
X->getType() == ReturnType)
7312 case Intrinsic::aarch64_sve_andv:
7313 case Intrinsic::aarch64_sve_eorv:
7314 case Intrinsic::aarch64_sve_orv:
7315 case Intrinsic::aarch64_sve_saddv:
7316 case Intrinsic::aarch64_sve_smaxv:
7317 case Intrinsic::aarch64_sve_sminv:
7318 case Intrinsic::aarch64_sve_uaddv:
7319 case Intrinsic::aarch64_sve_umaxv:
7320 case Intrinsic::aarch64_sve_uminv:
7334 if (!Factor || Factor != Args.size())
7339 for (
unsigned Idx = 0; Idx != Factor; ++Idx) {
7341 if (!EV || EV->getNumIndices() != 1 || *EV->idx_begin() != Idx)
7345 if (!CurDI || CurDI->getIntrinsicID() != DeinterleaveID)
7350 else if (DI != CurDI)
7362 unsigned NumOperands = Args.size();
7371 ReturnType, Q.
DL, CxtF))
7378 case Intrinsic::vscale: {
7383 return ConstantInt::get(ReturnType,
C->getZExtValue());
7394 if (NumOperands == 1)
7397 if (NumOperands == 2)
7402 case Intrinsic::masked_load:
7403 case Intrinsic::masked_gather: {
7404 Value *MaskArg = Args[1];
7405 Value *PassthruArg = Args[2];
7412 case Intrinsic::fshl:
7413 case Intrinsic::fshr: {
7414 Value *Op0 = Args[0], *Op1 = Args[1], *ShAmtArg = Args[2];
7422 return Args[IID == Intrinsic::fshl ? 0 : 1];
7424 const APInt *ShAmtC;
7430 return Args[IID == Intrinsic::fshl ? 0 : 1];
7434 const APInt *C1, *C2;
7438 *C1 + *C2 ==
BitWidth && ShAmt == *(IID == Intrinsic::fshl ? C1 : C2))
7452 case Intrinsic::experimental_constrained_fma:
7453 return simplifyFPOp(Args, {}, Q, ExBehavior, Rounding);
7454 case Intrinsic::fma:
7455 case Intrinsic::fmuladd:
7458 case Intrinsic::smul_fix:
7459 case Intrinsic::smul_fix_sat: {
7460 Value *Op0 = Args[0];
7461 Value *Op1 = Args[1];
7462 Value *Op2 = Args[2];
7487 case Intrinsic::vector_insert: {
7488 Value *Vec = Args[0];
7489 Value *SubVec = Args[1];
7490 Value *Idx = Args[2];
7499 X->getType() == ReturnType)
7504 case Intrinsic::vector_splice_right: {
7513 case Intrinsic::vector_splice_left: {
7522 if (Ty->isScalableTy())
7524 : ConstantRange::getFull(
BitWidth));
7533 return IID == Intrinsic::vector_splice_left ? Args[0] : Args[1];
7537 case Intrinsic::experimental_constrained_fadd:
7539 case Intrinsic::experimental_constrained_fsub:
7541 case Intrinsic::experimental_constrained_fmul:
7543 case Intrinsic::experimental_constrained_fdiv:
7545 case Intrinsic::experimental_constrained_frem:
7547 case Intrinsic::experimental_constrained_ldexp:
7549 case Intrinsic::experimental_vp_reverse: {
7550 Value *Vec = Args[0];
7551 Value *EVL = Args[2];
7574 Type *ReturnType =
Call->getCalledFunction()->getReturnType();
7577 case Intrinsic::experimental_gc_relocate: {
7603 ExBehavior = Constrained->getExceptionBehavior().value_or(ExBehavior);
7604 Rounding = Constrained->getRoundingMode().value_or(Rounding);
7607 Call->getFastMathFlagsOrNone(), Q,
7608 Call->getFunction(), ExBehavior, Rounding);
7615 auto *
F =
Call->getCalledFunction();
7620 ConstantArgs.
reserve(Args.size());
7621 for (
Value *Arg : Args) {
7641 if (
Call->isMustTailCall())
7653 if (
F &&
F->isIntrinsic())
7680 return ::simplifyFreezeInst(Op0, Q);
7694 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
7725 unsigned MaxRecurse) {
7726 assert(
I->getFunction() &&
"instruction should be inserted in a function");
7728 "context instruction should be in the same function");
7732 switch (
I->getOpcode()) {
7737 [](
Value *V) { return cast<Constant>(V); });
7741 case Instruction::FNeg:
7743 case Instruction::FAdd:
7746 case Instruction::Add:
7750 case Instruction::FSub:
7753 case Instruction::Sub:
7757 case Instruction::FMul:
7760 case Instruction::Mul:
7764 case Instruction::SDiv:
7768 case Instruction::UDiv:
7772 case Instruction::FDiv:
7775 case Instruction::SRem:
7777 case Instruction::URem:
7779 case Instruction::FRem:
7782 case Instruction::Shl:
7786 case Instruction::LShr:
7790 case Instruction::AShr:
7794 case Instruction::And:
7796 case Instruction::Or:
7798 case Instruction::Xor:
7800 case Instruction::ICmp:
7802 NewOps[1], Q, MaxRecurse);
7803 case Instruction::FCmp:
7805 NewOps[1],
I->getFastMathFlags(), Q, MaxRecurse);
7806 case Instruction::Select: {
7809 FMF = FPMO->getFastMathFlags();
7813 case Instruction::GetElementPtr: {
7816 ArrayRef(NewOps).slice(1), GEPI->getNoWrapFlags(), Q,
7819 case Instruction::InsertValue: {
7824 case Instruction::InsertElement:
7826 case Instruction::ExtractValue: {
7831 case Instruction::ExtractElement:
7833 case Instruction::ShuffleVector: {
7836 SVI->getShuffleMask(), SVI->getType(), Q,
7839 case Instruction::PHI:
7841 case Instruction::Call:
7845 case Instruction::Freeze:
7847#define HANDLE_CAST_INST(num, opc, clas) case Instruction::opc:
7848#include "llvm/IR/Instruction.def"
7849#undef HANDLE_CAST_INST
7850 if (
I->getOpcode() == Instruction::AddrSpaceCast) {
7852 NewOps[0],
I->getType(),
7859 case Instruction::Alloca:
7862 case Instruction::Load:
7871 "Number of operands should match the instruction!");
7872 return ::simplifyInstructionWithOperands(
I, NewOps, SQ,
RecursionLimit);
7902 bool Simplified =
false;
7909 for (
User *U :
I->users())
7914 I->replaceAllUsesWith(SimpleV);
7916 if (!
I->isEHPad() && !
I->isTerminator() && !
I->mayHaveSideEffects())
7917 I->eraseFromParent();
7923 for (
unsigned Idx = 0; Idx != Worklist.
size(); ++Idx) {
7929 if (UnsimplifiedUsers)
7930 UnsimplifiedUsers->insert(
I);
7939 for (
User *U :
I->users())
7943 I->replaceAllUsesWith(SimpleV);
7945 if (!
I->isEHPad() && !
I->isTerminator() && !
I->mayHaveSideEffects())
7946 I->eraseFromParent();
7955 assert(
I != SimpleV &&
"replaceAndRecursivelySimplify(X,X) is not valid!");
7956 assert(SimpleV &&
"Must provide a simplified value.");
7964 auto *DT = DTWP ? &DTWP->
getDomTree() :
nullptr;
7966 auto *TLI = TLIWP ? &TLIWP->
getTLI(
F) :
nullptr;
7969 return {
F.getDataLayout(), TLI, DT, AC};
7977template <
class T,
class... TArgs>
7980 auto *DT = AM.template getCachedResult<DominatorTreeAnalysis>(
F);
7981 auto *TLI = AM.template getCachedResult<TargetLibraryAnalysis>(
F);
7982 auto *AC = AM.template getCachedResult<AssumptionAnalysis>(
F);
7983 return {
F.getDataLayout(), TLI, DT, AC};
7997void InstSimplifyFolder::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static Value * simplifyCmpSelFalseCase(CmpPredicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse)
Simplify comparison with false branch of select.
static Value * simplifyCmpSelCase(CmpPredicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse, Constant *TrueOrFalse)
Simplify comparison with true or false branch of select: sel = select i1 cond, i32 tv,...
static Value * foldMinMaxSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1)
Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/ma...
static Value * simplifySelectWithFCmp(Value *Cond, Value *T, Value *F, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is a floating-point comparison.
static Value * expandCommutativeBinOp(Instruction::BinaryOps Opcode, Value *L, Value *R, Instruction::BinaryOps OpcodeToExpand, const SimplifyQuery &Q, unsigned MaxRecurse)
Try to simplify binops of form "A op (B op' C)" or the commuted variant by distributing op over op'.
static Constant * foldOrCommuteConstant(Instruction::BinaryOps Opcode, Value *&Op0, Value *&Op1, const SimplifyQuery &Q)
static bool haveNonOverlappingStorage(const Value *V1, const Value *V2)
Return true if V1 and V2 are each the base of some distict storage region [V, object_size(V)] which d...
static Constant * foldConstant(Instruction::UnaryOps Opcode, Value *&Op, const SimplifyQuery &Q)
static Value * handleOtherCmpSelSimplifications(Value *TCmp, Value *FCmp, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse)
We know comparison with both branches of select can be simplified, but they are not equal.
static Value * threadCmpOverPHI(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
In the case of a comparison with a PHI instruction, try to simplify the comparison by seeing whether ...
static Constant * propagateNaN(Constant *In)
Try to propagate existing NaN values when possible.
static Value * simplifyICmpOfBools(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Fold an icmp when its operands have i1 scalar type.
static Value * simplifyICmpWithBinOpOnLHS(CmpPredicate Pred, BinaryOperator *LBO, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
static void getUnsignedMonotonicValues(SmallPtrSetImpl< Value * > &Res, Value *V, MonotonicType Type, const SimplifyQuery &Q, unsigned Depth=0)
Get values V_i such that V uge V_i (GreaterEq) or V ule V_i (LowerEq).
static Value * simplifyRelativeLoad(Constant *Ptr, Constant *Offset, const DataLayout &DL)
static Value * simplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
These are simplifications common to SDiv and UDiv.
static Value * simplifyPHINode(PHINode *PN, ArrayRef< Value * > IncomingValues, const SimplifyQuery &Q)
See if we can fold the given phi. If not, returns null.
static bool isSameCompare(Value *V, CmpPredicate Pred, Value *LHS, Value *RHS)
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
static Value * simplifyAndCommutative(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
static bool isIdempotent(Intrinsic::ID ID)
static std::optional< ConstantRange > getRange(Value *V, const InstrInfoQuery &IIQ)
Helper method to get range from metadata or attribute.
static Value * simplifyAndOrOfICmpsWithCtpop(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd)
Try to simplify and/or of icmp with ctpop intrinsic.
static Value * simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp, ICmpInst *UnsignedICmp, bool IsAnd, const SimplifyQuery &Q)
Commuted variants are assumed to be handled by calling this function again with the parameters swappe...
static Value * simplifyWithOpsReplaced(Value *V, ArrayRef< std::pair< Value *, Value * > > Ops, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags, unsigned MaxRecurse)
static Value * simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
static Value * simplifyAndOrOfFCmpsWithConstants(FCmpInst *Cmp0, FCmpInst *Cmp1, bool IsAnd)
Test if a pair of compares with a shared operand and 2 constants has an empty set intersection,...
static Value * simplifyICmpWithMinMax(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
simplify integer comparisons where at least one operand of the compare matches an integer min/max idi...
static Value * simplifyCmpSelTrueCase(CmpPredicate Pred, Value *LHS, Value *RHS, Value *Cond, const SimplifyQuery &Q, unsigned MaxRecurse)
Simplify comparison with true branch of select.
static Value * simplifyICmpUsingMonotonicValues(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static bool isDereferenceableArg(const Value *V)
static bool isPoisonShift(Value *Amount, const SimplifyQuery &Q)
Returns true if a shift by Amount always yields poison.
static Value * simplifyRightShift(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an LShr or AShr, see if we can fold the result.
static Value * simplifyICmpWithIntrinsicOnLHS(CmpPredicate Pred, Value *LHS, Value *RHS)
static Value * simplifyByDomEq(unsigned Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Test if there is a dominating equivalence condition for the two operands.
static Value * simplifyFPUnOp(unsigned, Value *, const FastMathFlags &, const SimplifyQuery &, unsigned)
Given the operand for a UnaryOperator, see if we can fold the result.
static Value * simplifyICmpWithBinOp(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
TODO: A large part of this logic is duplicated in InstCombine's foldICmpBinOp().
static Value * simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1, const SimplifyQuery &Q)
static Value * expandBinOp(Instruction::BinaryOps Opcode, Value *V, Value *OtherOp, Instruction::BinaryOps OpcodeToExpand, const SimplifyQuery &Q, unsigned MaxRecurse)
Try to simplify a binary operator of form "V op OtherOp" where V is "(B0 opex B1)" by distributing 'o...
static bool matchEquivZeroRHS(CmpPredicate &Pred, const Value *RHS)
Check if RHS is zero or can be transformed to an equivalent zero comparison.
static Value * simplifyICmpWithZero(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Try hard to fold icmp with zero RHS because this is a common case.
static Constant * getFalse(Type *Ty)
For a boolean type or a vector of boolean type, return false or a vector with every element false.
static MinMaxOptResult OptimizeConstMinMax(const Constant *RHSConst, const Intrinsic::ID IID, FastMathFlags FMF, Constant **OutNewConstVal)
static Value * simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Check for common or similar folds of integer division or integer remainder.
static bool removesFPFraction(Intrinsic::ID ID)
Return true if the intrinsic rounds a floating-point value to an integral floating-point value (not a...
static Value * simplifyOrOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
static Value * simplifySelectWithEquivalence(ArrayRef< std::pair< Value *, Value * > > Replacements, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is an integer equality or floating-po...
static Value * simplifyIdentityInterleave(Intrinsic::ID IID, ArrayRef< Value * > Args)
interleaveN(extractvalue(deinterleaveN(x), 0), ..., extractvalue(deinterleaveN(x),...
static bool trySimplifyICmpWithAdds(CmpPredicate Pred, Value *LHS, Value *RHS, const InstrInfoQuery &IIQ)
static Value * simplifySelectBitTest(Value *TrueVal, Value *FalseVal, Value *X, const APInt *Y, bool TrueWhenUnset)
Try to simplify a select instruction when its condition operand is an integer comparison where one op...
static Value * simplifyAssociativeBinOp(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
Generic simplifications for associative binary operations.
static Value * threadBinOpOverPHI(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
In the case of a binary operation with an operand that is a PHI instruction, try to simplify the bino...
static Value * simplifyCmpSelOfMaxMin(Value *CmpLHS, Value *CmpRHS, CmpPredicate Pred, Value *TVal, Value *FVal)
static bool isByValArg(const Value *V)
static Value * simplifyUnaryIntrinsic(Intrinsic::ID IID, Value *Op0, FastMathFlags FMF, const SimplifyQuery &Q)
static Constant * simplifyFPOp(ArrayRef< Value * > Ops, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior, RoundingMode Rounding)
Perform folds that are common to any floating-point operation.
static Value * threadCmpOverSelect(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
In the case of a comparison with a select instruction, try to simplify the comparison by seeing wheth...
static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC, SmallSetVector< Instruction *, 8 > *UnsimplifiedUsers=nullptr)
Implementation of recursive simplification through an instruction's uses.
static bool isAllocDisjoint(const Value *V)
Return true if the underlying object (storage) must be disjoint from storage returned by any noalias ...
static Constant * getTrue(Type *Ty)
For a boolean type or a vector of boolean type, return true or a vector with every element true.
static bool isDivZero(Value *X, Value *Y, const SimplifyQuery &Q, unsigned MaxRecurse, bool IsSigned)
Return true if we can simplify X / Y to 0.
static Value * simplifyLdexp(Value *Op0, Value *Op1, const SimplifyQuery &Q, bool IsStrict)
static Value * simplifyLogicOfAddSub(Value *Op0, Value *Op1, Instruction::BinaryOps Opcode)
Given a bitwise logic op, check if the operands are add/sub with a common source value and inverted c...
static Value * simplifySelectWithBitTest(Value *CondVal, Value *TrueVal, Value *FalseVal)
An alternative way to test if a bit is set or not.
static Value * simplifyOrLogic(Value *X, Value *Y)
static Type * getCompareTy(Value *Op)
static Value * simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1, const SimplifyQuery &Q)
static bool isICmpTrue(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
Given a predicate and two operands, return true if the comparison is true.
static Value * tryConstantFoldCall(CallBase *Call, ArrayRef< Value * > Args, const SimplifyQuery &Q)
static Value * simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType, Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q)
bool isSelectWithIdenticalPHI(PHINode &PN, PHINode &IdenticalPN)
Look for the following pattern and simplify to_fold to identicalPhi.
static APInt stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V)
Compute the base pointer and cumulative constant offsets for V.
static Value * foldIdentityShuffles(int DestElt, Value *Op0, Value *Op1, int MaskVal, Value *RootVec, unsigned MaxRecurse)
For the given destination element of a shuffle, peek through shuffles to match a root vector source o...
static Value * simplifyAndOrOfFCmps(const SimplifyQuery &Q, FCmpInst *LHS, FCmpInst *RHS, bool IsAnd)
static Value * simplifyICmpWithConstant(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static Value * extractEquivalentCondition(Value *V, CmpPredicate Pred, Value *LHS, Value *RHS)
Rummage around inside V looking for something equivalent to the comparison "LHS Pred RHS".
static Value * simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0, Value *Op1, bool IsAnd)
static Value * threadBinOpOverSelect(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
In the case of a binary operation with a select instruction as an operand, try to simplify the binop ...
static Constant * computePointerDifference(const DataLayout &DL, Value *LHS, Value *RHS)
Compute the constant difference between two pointer values.
static Value * simplifyAndOrOfICmpsWithConstants(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd)
Test if a pair of compares with a shared operand and 2 constants has an empty set intersection,...
static Value * simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
static Value * simplifyICmpWithDominatingAssume(CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static Value * simplifyShift(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool IsNSW, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an Shl, LShr or AShr, see if we can fold the result.
static Value * simplifySVEIntReduction(Intrinsic::ID IID, Type *ReturnType, Value *Op0, Value *Op1)
static Constant * computePointerICmp(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
static Value * simplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
These are simplifications common to SRem and URem.
static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT)
Does the given value dominate the specified phi node?
static Value * simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is an integer comparison.
static Value * foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1)
Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/ma...
static constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This header provides classes for managing per-loop analyses.
uint64_t IntrinsicInst * II
const SmallVectorImpl< MachineOperand > & Cond
This file implements a set that has insertion order iteration characteristics.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static SymbolRef::Type getType(const Symbol *Sym)
static const uint32_t IV[8]
APFloat makeQuiet() const
Assuming this is an IEEE-754 NaN value, quiet its signaling bit.
Class for arbitrary precision integers.
LLVM_ABI APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
unsigned getActiveBits() const
Compute the number of active bits in the value.
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
LLVM_ABI APInt urem(const APInt &RHS) const
Unsigned remainder operation.
void setSignBit()
Set the sign bit to 1.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
bool sle(const APInt &RHS) const
Signed less or equal comparison.
unsigned countr_zero() const
Count the number of trailing zero bits.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
bool getBoolValue() const
Convert APInt to a boolean value.
LLVM_ABI APInt srem(const APInt &RHS) const
Function for signed remainder operation.
bool isMask(unsigned numBits) const
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
bool isOne() const
Determine if this is a value of 1.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
an instruction to allocate memory on the stack
A container for analyses that lazily runs them and caches their results.
This class represents an incoming formal argument to a Function.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
Get the last element.
size_t size() const
Get the array size.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
bool empty() const
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.
An immutable pass that tracks lazily created AssumptionCache objects.
AssumptionCache & getAssumptionCache(Function &F)
Get the cached assumptions for a function.
A cache of @llvm.assume calls within a function.
MutableArrayRef< ResultElem > assumptionsFor(const Value *V)
Access the list of assumptions which affect this value.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI std::optional< unsigned > getVScaleRangeMax() const
Returns the maximum value for the vscale_range attribute or std::nullopt when unknown.
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
BinaryOps getOpcode() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Value * getArgOperand(unsigned i) const
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, const DataLayout *DL)
Determine how a pair of casts can be eliminated, if they can be at all.
This class is the base class for the comparison instructions.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Predicate getStrictPredicate() const
For example, SGE -> SGT, SLE -> SLT, ULE -> ULT, UGE -> UGT.
bool isFalseWhenEqual() const
This is just a convenience.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
bool isTrueWhenEqual() const
This is just a convenience.
static bool isFPPredicate(Predicate P)
Predicate getNonStrictPredicate() const
For example, SGT -> SGE, SLT -> SLE, ULT -> ULE, UGT -> UGE.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Predicate getPredicate() const
Return the predicate for this instruction.
static LLVM_ABI bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
static bool isIntPredicate(Predicate P)
static LLVM_ABI bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
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 * getNot(Constant *C)
static LLVM_ABI Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static LLVM_ABI std::optional< ConstantFPRange > makeExactFCmpRegion(FCmpInst::Predicate Pred, const APFloat &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
ConstantFP - Floating Point Values [float, double].
const APFloat & getValueAPF() const
static ConstantFP * getNegativeZero(Type *Ty)
static LLVM_ABI ConstantFP * getZero(Type *Ty, bool Negative=false)
static LLVM_ABI ConstantFP * 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 ConstantInt * getSigned(IntegerType *Ty, int64_t V, bool ImplicitTrunc=false)
Return a ConstantInt with the specified value for the specified type.
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...
static LLVM_ABI ConstantInt * getBool(LLVMContext &Context, bool V)
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This class represents a range of values.
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
LLVM_ABI APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
LLVM_ABI bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
LLVM_ABI bool isEmptySet() const
Return true if this set contains no members.
bool isSingleElement() const
Return true if this set contains exactly one member.
LLVM_ABI ConstantRange multiply(const ConstantRange &Other, unsigned NoWrapKind=0) const
Return a new range representing the possible values resulting from a multiplication of a value in thi...
static LLVM_ABI ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
LLVM_ABI ConstantRange inverse() const
Return a new range that is the logical not of the current set.
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
LLVM_ABI APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
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.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
LLVM_ABI bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
LLVM_ABI bool isMaxSignedValue() const
Return true if the value is the largest signed value.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
LLVM_ABI bool isMinSignedValue() const
Return true if the value is the smallest signed value.
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
A parsed version of the target data layout string in and methods for querying it.
unsigned getAddressSizeInBits(unsigned AS) const
The size in bits of an address in for the given AS.
IntegerType * getAddressType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of an address in AddressSpace.
LLVM_ABI unsigned getIndexTypeSizeInBits(Type *Ty) const
The size in bits of the index used in GEP calculation for this type.
LLVM_ABI IntegerType * getIndexType(LLVMContext &C, unsigned AddressSpace) const
Returns the type of a GEP index in AddressSpace.
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
unsigned getIndexSizeInBits(unsigned AS) const
The size in bits of indices used for address calculation in getelementptr and for addresses in the gi...