44#include "llvm/IR/IntrinsicsAArch64.h"
55#define DEBUG_TYPE "instsimplify"
104 Value *CLHS = Cmp->getOperand(0), *CRHS = Cmp->getOperand(1);
105 if (CPred ==
Pred && CLHS ==
LHS && CRHS ==
RHS)
118 unsigned MaxRecurse,
Constant *TrueOrFalse) {
120 if (SimplifiedCmp ==
Cond) {
128 return SimplifiedCmp;
134 unsigned MaxRecurse) {
142 unsigned MaxRecurse) {
152 unsigned MaxRecurse) {
203 if (!
B ||
B->getOpcode() != OpcodeToExpand)
205 Value *B0 =
B->getOperand(0), *B1 =
B->getOperand(1);
216 if ((L == B0 && R == B1) ||
237 unsigned MaxRecurse) {
254 unsigned MaxRecurse) {
357 unsigned MaxRecurse) {
394 if (TV ==
SI->getTrueValue() && FV ==
SI->getFalseValue())
400 if ((FV && !TV) || (TV && !FV)) {
404 if (Simplified && Simplified->getOpcode() ==
unsigned(Opcode) &&
405 !Simplified->hasPoisonGeneratingFlags()) {
409 Value *UnsimplifiedBranch = FV ?
SI->getTrueValue() :
SI->getFalseValue();
410 Value *UnsimplifiedLHS =
SI ==
LHS ? UnsimplifiedBranch :
LHS;
411 Value *UnsimplifiedRHS =
SI ==
LHS ?
RHS : UnsimplifiedBranch;
412 if (Simplified->getOperand(0) == UnsimplifiedLHS &&
413 Simplified->getOperand(1) == UnsimplifiedRHS)
415 if (Simplified->isCommutative() &&
416 Simplified->getOperand(1) == UnsimplifiedLHS &&
417 Simplified->getOperand(0) == UnsimplifiedRHS)
448 Value *TV =
SI->getTrueValue();
449 Value *FV =
SI->getFalseValue();
469 if (
Cond->getType()->isVectorTy() ==
RHS->getType()->isVectorTy())
481 unsigned MaxRecurse) {
501 Value *CommonValue =
nullptr;
514 if (!
V || (CommonValue &&
V != CommonValue))
545 Value *CommonValue =
nullptr;
559 if (!
V || (CommonValue &&
V != CommonValue))
575 case Instruction::FAdd:
576 case Instruction::FSub:
577 case Instruction::FMul:
578 case Instruction::FDiv:
579 case Instruction::FRem:
580 if (Q.
CtxI !=
nullptr)
664 return ::simplifyAddInst(Op0, Op1, IsNSW, IsNUW, Query,
RecursionLimit);
677 assert(
V->getType()->isPtrOrPtrVectorTy());
680 V =
V->stripAndAccumulateConstantOffsets(
DL,
Offset,
684 return Offset.sextOrTrunc(
DL.getIndexTypeSizeInBits(
V->getType()));
703 Constant *Res = ConstantInt::get(
LHS->getContext(), LHSOffset - RHSOffset);
719 std::optional<bool> Imp =
724 case Instruction::Sub:
725 case Instruction::Xor:
726 case Instruction::URem:
727 case Instruction::SRem:
730 case Instruction::SDiv:
731 case Instruction::UDiv:
732 return ConstantInt::get(Ty, 1);
734 case Instruction::And:
735 case Instruction::Or:
777 if (
Known.Zero.isMaxSignedValue()) {
790 Value *
X =
nullptr, *
Y =
nullptr, *Z = Op1;
848 if (
X->getType() ==
Y->getType())
895 return ::simplifySubInst(Op0, Op1, IsNSW, IsNUW, Q,
RecursionLimit);
945 Instruction::Add, Q, MaxRecurse))
967 return ::simplifyMulInst(Op0, Op1, IsNSW, IsNUW, Q,
RecursionLimit);
977 return (
C &&
C->isAllOnesValue());
983 unsigned MaxRecurse,
bool IsSigned) {
1000 Type *Ty =
X->getType();
1006 Constant *PosDividendC = ConstantInt::get(Ty,
C->abs());
1007 Constant *NegDividendC = ConstantInt::get(Ty, -
C->abs());
1016 if (
C->isMinSignedValue())
1022 Constant *PosDivisorC = ConstantInt::get(Ty,
C->abs());
1023 Constant *NegDivisorC = ConstantInt::get(Ty, -
C->abs());
1049 unsigned MaxRecurse) {
1050 bool IsDiv = (Opcode == Instruction::SDiv || Opcode == Instruction::UDiv);
1051 bool IsSigned = (Opcode == Instruction::SDiv || Opcode == Instruction::SRem);
1100 if (
Known.countMinLeadingZeros() ==
Known.getBitWidth() - 1)
1119 if (
isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1143 unsigned MaxRecurse) {
1166 (Opcode == Instruction::UDiv
1186 if ((Opcode == Instruction::SRem &&
1188 (Opcode == Instruction::URem &&
1196 if (Opcode == Instruction::SRem
1199 return C.srem(*C0).isZero();
1203 return C.urem(*C0).isZero();
1219 return simplifyDiv(Instruction::SDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1231 return simplifyDiv(Instruction::UDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1242 unsigned MaxRecurse) {
1253 return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
1263 unsigned MaxRecurse) {
1264 return simplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse);
1283 const APInt *AmountC;
1290 for (
unsigned I = 0,
1305 unsigned MaxRecurse) {
1355 assert(Opcode == Instruction::Shl &&
"Expected shl for nsw instruction");
1374 Value *Op1,
bool IsExact,
1393 if (Op0Known.
One[0])
1405 simplifyShift(Instruction::Shl, Op0, Op1, IsNSW, Q, MaxRecurse))
1429 if (IsNSW && IsNUW &&
1438 return ::simplifyShlInst(Op0, Op1, IsNSW, IsNUW, Q,
RecursionLimit);
1460 const APInt *ShRAmt, *ShLAmt;
1463 *ShRAmt == *ShLAmt) {
1466 if (ShRAmt->
uge(EffWidthY))
1514 ICmpInst *UnsignedICmp,
bool IsAnd,
1528 if (
match(UnsignedICmp,
1546 return IsAnd ? UnsignedICmp : ZeroICmp;
1552 return IsAnd ? ZeroICmp : UnsignedICmp;
1558 if (
match(UnsignedICmp,
1562 return UnsignedICmp;
1565 return UnsignedICmp;
1572 else if (
match(UnsignedICmp,
1583 return IsAnd ? ZeroICmp : UnsignedICmp;
1589 return IsAnd ? UnsignedICmp : ZeroICmp;
1599 return IsAnd ? UnsignedICmp : ZeroICmp;
1604 return IsAnd ? ZeroICmp : UnsignedICmp;
1638 if (IsAnd && Range0.intersectWith(Range1).isEmptySet())
1643 if (!IsAnd && Range0.unionWith(Range1).isFullSet())
1651 if (Range0.contains(Range1))
1652 return IsAnd ? Cmp1 : Cmp0;
1653 if (Range1.contains(Range0))
1654 return IsAnd ? Cmp0 : Cmp1;
1672 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1680 if (
C0->isStrictlyPositive()) {
1694 if (
C0->getBoolValue() && IsNUW) {
1737 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1745 if (
C0->isStrictlyPositive()) {
1759 if (
C0->getBoolValue() && IsNUW) {
1808 if (!Range0 || !Range1)
1813 if (Range0->intersectWith(*Range1).isEmptySet())
1821 if (Range0->contains(*Range1))
1823 if (Range1->contains(*Range0))
1831 Value *LHS0 =
LHS->getOperand(0), *LHS1 =
LHS->getOperand(1);
1832 Value *RHS0 =
RHS->getOperand(0), *RHS1 =
RHS->getOperand(1);
1845 if ((
match(RHS0, AbsOrSelfLHS0) ||
match(RHS1, AbsOrSelfLHS0)) &&
1860 if ((
match(LHS0, AbsOrSelfRHS0) ||
match(LHS1, AbsOrSelfRHS0)) &&
1874 Value *Op1,
bool IsAnd) {
1878 if (Cast0 && Cast1 && Cast0->getOpcode() == Cast1->getOpcode() &&
1879 Cast0->getSrcTy() == Cast1->getSrcTy()) {
1880 Op0 = Cast0->getOperand(0);
1881 Op1 = Cast1->getOperand(0);
1912 bool AllowRefinement,
1914 unsigned MaxRecurse);
1918 unsigned MaxRecurse) {
1919 assert((Opcode == Instruction::And || Opcode == Instruction::Or) &&
1935 if (Res == Absorber)
1945 if (Res == Absorber)
1955 nullptr, MaxRecurse))
1956 return Simplify(Res);
1959 nullptr, MaxRecurse))
1960 return Simplify(Res);
1992 unsigned MaxRecurse) {
2026 const APInt *Shift1, *Shift2;
2042 unsigned MaxRecurse) {
2082 (~(*Mask)).lshr(*ShAmt).isZero())
2088 (~(*Mask)).shl(*ShAmt).isZero())
2093 const APInt *PowerC;
2124 Instruction::Or, Q, MaxRecurse))
2129 Instruction::Xor, Q, MaxRecurse))
2174 if (EffWidthY <= ShftCnt) {
2207 if (*Implied ==
true)
2210 if (*Implied ==
false)
2235 assert(
X->getType() ==
Y->getType() &&
"Expected same type for 'or' ops");
2236 Type *Ty =
X->getType();
2326 unsigned MaxRecurse) {
2365 C->ule(
X->getType()->getScalarSizeInBits())) {
2430 Instruction::And, Q, MaxRecurse))
2487 if (std::optional<bool> Implied =
2490 if (*Implied ==
false)
2493 if (*Implied ==
true)
2496 if (std::optional<bool> Implied =
2499 if (*Implied ==
false)
2502 if (*Implied ==
true)
2520 unsigned MaxRecurse) {
2562 if (
Value *R = foldAndOrNot(Op0, Op1))
2564 if (
Value *R = foldAndOrNot(Op1, Op0))
2617 Value *CmpLHS = Cmp->getOperand(0), *CmpRHS = Cmp->getOperand(1);
2618 if (
Pred == Cmp->getPredicate() &&
LHS == CmpLHS &&
RHS == CmpRHS)
2621 LHS == CmpRHS &&
RHS == CmpLHS)
2628 return A &&
A->hasByValAttr();
2633 return A &&
A->getType()->isPointerTy() &&
A->getDereferenceableBytes() > 0;
2645 return AI->isStaticAlloca();
2647 return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
2648 GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
2649 !GV->isThreadLocal();
2741 assert(
LHS->getType() ==
RHS->getType() &&
"Must have same types");
2763 unsigned IndexSize =
DL.getIndexTypeSizeInBits(
LHS->getType());
2764 APInt LHSOffset(IndexSize, 0), RHSOffset(IndexSize, 0);
2765 LHS =
LHS->stripAndAccumulateConstantOffsets(
DL, LHSOffset, AllowNonInbounds);
2766 RHS =
RHS->stripAndAccumulateConstantOffsets(
DL, RHSOffset, AllowNonInbounds);
2786 Size =
V->getPointerDereferenceableBytes(
DL, CanBeNull,
2788 return Size != 0 && !CanBeNull;
2792 if (GetKnownSize(
LHS, LHSSize) && GetKnownSize(
RHS, RHSSize)) {
2793 APInt Dist = LHSOffset - RHSOffset;
2821 if ((IsNoAliasCall(LHSUObjs) && IsAllocDisjoint(RHSUObjs)) ||
2822 (IsNoAliasCall(RHSUObjs) && IsAllocDisjoint(LHSUObjs)))
2842 bool Captured =
false;
2850 unsigned OtherIdx = 1 - U->getOperandNo();
2860 CustomCaptureTracker Tracker;
2862 if (!Tracker.Captured)
2877 if (!
OpTy->isIntOrIntVectorTy(1))
3131 *MulC != 0 &&
C->urem(*MulC) != 0) ||
3133 *MulC != 0 &&
C->srem(*MulC) != 0)))
3148 unsigned Depth = 0) {
3176 switch (
I->getOpcode()) {
3177 case Instruction::And:
3181 case Instruction::URem:
3182 case Instruction::UDiv:
3183 case Instruction::LShr:
3186 case Instruction::Call:
3210 for (
Value *GV : GreaterValues)
3219 unsigned MaxRecurse) {
3243 if (!
Known.isNonNegative())
3254 if (!
Known.isNonNegative())
3331 (
APInt(
C1->getBitWidth(), 1) << *
C1).ule(*C2))) {
3377 return (
C1->sle(*C2) &&
C1->isNonNegative()) ||
3378 (C2->
sle(*
C1) &&
C1->isNonPositive());
3386 unsigned MaxRecurse) {
3389 if (MaxRecurse && (LBO || RBO)) {
3391 Value *
A =
nullptr, *
B =
nullptr, *
C =
nullptr, *
D =
nullptr;
3393 bool NoLHSWrapProblem =
false, NoRHSWrapProblem =
false;
3394 if (LBO && LBO->
getOpcode() == Instruction::Add) {
3404 if (RBO && RBO->
getOpcode() == Instruction::Add) {
3416 if ((
A ==
RHS ||
B ==
RHS) && NoLHSWrapProblem)
3423 if ((
C ==
LHS ||
D ==
LHS) && NoRHSWrapProblem)
3426 C ==
LHS ?
D :
C, Q, MaxRecurse - 1))
3430 bool CanSimplify = (NoLHSWrapProblem && NoRHSWrapProblem) ||
3432 if (
A &&
C && (
A ==
C ||
A ==
D ||
B ==
C ||
B ==
D) && CanSimplify) {
3439 }
else if (
A ==
D) {
3443 }
else if (
B ==
C) {
3471 if (
C->isStrictlyPositive()) {
3477 if (
C->isNonNegative()) {
3527 case Instruction::Shl: {
3543 case Instruction::And:
3544 case Instruction::Or: {
3549 if (!
C1->isSubsetOf(*C2)) {
3553 if (
C1->isSubsetOf(*C2)) {
3575 case Instruction::UDiv:
3576 case Instruction::LShr:
3584 case Instruction::SDiv:
3592 case Instruction::AShr:
3599 case Instruction::Shl: {
3620 unsigned MaxRecurse) {
3786 (
A ==
C ||
A ==
D ||
B ==
C ||
B ==
D)) {
3795 (
A ==
C ||
A ==
D ||
B ==
C ||
B ==
D)) {
3836 switch (
II->getIntrinsicID()) {
3837 case Intrinsic::uadd_sat:
3847 case Intrinsic::usub_sat:
3870 return A->getRange();
3872 return CB->getRange();
3874 return std::nullopt;
3931 if (LhsCr->icmp(
Pred, *RhsCr))
3958 if (RI->getOperand(0)->getType() == SrcTy)
3970 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
3974 RI->getOperand(0), Q, MaxRecurse - 1))
3979 if (
SrcOp == RI->getOperand(0)) {
3996 assert(
Trunc &&
"Constant-fold of ImmConstant should not fail");
3999 assert(RExt &&
"Constant-fold of ImmConstant should not fail");
4002 assert(AnyEq &&
"Constant-fold of ImmConstant should not fail");
4050 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
4058 if (
SrcOp == RI->getOperand(0)) {
4074 assert(
Trunc &&
"Constant-fold of ImmConstant should not fail");
4077 assert(RExt &&
"Constant-fold of ImmConstant should not fail");
4080 assert(AnyEq &&
"Constant-fold of ImmConstant should not fail");
4092 switch (
Pred.getPreferredSignedPredicate()) {
4168 if (std::optional<bool> Res =
4174 if (
LHS->getType()->isPointerTy())
4195 return ::simplifyICmpInst(Predicate, LHS, RHS, Q,
RecursionLimit);
4202 unsigned MaxRecurse) {
4262 if (std::optional<bool> Res =
4268 std::optional<KnownFPClass> FullKnownClassLHS;
4272 auto computeLHSClass = [=, &FullKnownClassLHS](
FPClassTest InterestedFlags =
4274 if (FullKnownClassLHS)
4275 return *FullKnownClassLHS;
4281 auto [ClassVal, ClassTest] =
4284 FullKnownClassLHS = computeLHSClass();
4285 if ((FullKnownClassLHS->getKnownFPClasses() & ClassTest) ==
fcNone)
4287 if ((FullKnownClassLHS->getKnownFPClasses() & ~ClassTest) ==
fcNone)
4302 if (
C->isNegative() && !
C->isNegZero()) {
4336 if ((IsMax && *C2 > *
C) || (IsMin && *C2 < *
C)) {
4361 return ConstantInt::get(RetTy, IsMax);
4370 return ConstantInt::get(RetTy, !IsMax);
4390 Interested |=
fcNan;
4397 Known.cannotBeOrderedLessThanZero())
4408 if (
Known.cannotBeOrderedLessThanZero())
4434 return ::simplifyFCmpInst(Predicate, LHS, RHS, FMF, Q,
RecursionLimit);
4440 bool AllowRefinement,
4442 unsigned MaxRecurse) {
4444 "If AllowRefinement=false then CanUseUndef=false");
4445 for (
const auto &OpAndRepOp :
Ops) {
4451 if (
V == OpAndRepOp.first)
4452 return OpAndRepOp.second;
4475 for (
const auto &OpAndRepOp :
Ops) {
4478 if (OpAndRepOp.first->getType()->isVectorTy() &&
4485 bool AnyReplaced =
false;
4486 for (
Use &InstOp :
I->operands()) {
4491 if (
Cond && InstOp.getOperandNo() == 1 +
Cond->isOne()) {
4498 InstOp,
Ops, Q, AllowRefinement, DropFlags, MaxRecurse)) {
4500 AnyReplaced = InstOp != NewInstOp;
4514 if (!AllowRefinement) {
4520 auto IsAssumedNonPoison = [&](
Value *
V) {
4521 return any_of(
Ops, [=](
const auto &Rep) {
return Rep.second ==
V; });
4525 unsigned Opcode = BO->getOpcode();
4528 if (!BO->getType()->isFPOrFPVectorTy()) {
4537 if ((Opcode == Instruction::And || Opcode == Instruction::Or) &&
4538 NewOps[0] == NewOps[1]) {
4541 if (PDI->isDisjoint()) {
4553 if ((Opcode == Instruction::Sub || Opcode == Instruction::Xor) &&
4554 NewOps[0] == NewOps[1] && IsAssumedNonPoison(NewOps[0]))
4565 if ((NewOps[0] == Absorber || NewOps[1] == Absorber) &&
4567 [=](
const auto &Rep) {
return impliesPoison(BO, Rep.first); }))
4572 auto WithFlagsDropped = [&](
Value *Res) ->
Value * {
4573 if (
II->hasPoisonGeneratingAnnotations()) {
4584 if ((
II->getIntrinsicID() == Intrinsic::scmp ||
4585 II->getIntrinsicID() == Intrinsic::ucmp) &&
4586 NewOps[0] == NewOps[1] && IsAssumedNonPoison(NewOps[0]))
4587 return WithFlagsDropped(ConstantInt::get(
I->getType(), 0));
4590 const APInt Identity = MMI->getIdentity();
4593 return WithFlagsDropped(NewOps[1]);
4595 return WithFlagsDropped(NewOps[0]);
4596 if (NewOps[0] == NewOps[1])
4597 return WithFlagsDropped(NewOps[0]);
4617 auto PreventSelfSimplify = [
V](
Value *Simplified) {
4618 return Simplified !=
V ? Simplified :
nullptr;
4622 I, NewOps, Q,
nullptr, MaxRecurse));
4628 for (
Value *NewOp : NewOps) {
4644 if (!AllowRefinement) {
4647 auto CanNotCreatePoisonSpecialCases = [&]() {
4650 if (
II &&
II->getIntrinsicID() == Intrinsic::abs &&
4651 ConstOps[0]->isNotMinSignedValue() &&
4652 !
II->hasPoisonGeneratingAttributes() &&
4653 !
II->hasPoisonGeneratingMetadata())
4659 return !Cmp->hasSameSign() ||
4666 if (CanNotCreatePoisonSpecialCases())
4673 if (DropFlags &&
II) {
4677 switch (
II->getIntrinsicID()) {
4678 case Intrinsic::abs:
4679 case Intrinsic::ctlz:
4680 case Intrinsic::cttz:
4690 if (DropFlags && Res &&
I->hasPoisonGeneratingAnnotations())
4701 bool AllowRefinement,
4703 unsigned MaxRecurse) {
4705 DropFlags, MaxRecurse);
4710 bool AllowRefinement,
4714 if (!AllowRefinement)
4717 return ::simplifyWithOpReplaced(V,
Op, RepOp, Q, AllowRefinement, DropFlags,
4724 const APInt *
Y,
bool TrueWhenUnset) {
4731 return TrueWhenUnset ? FalseVal : TrueVal;
4737 return TrueWhenUnset ? FalseVal : TrueVal;
4739 if (
Y->isPowerOf2()) {
4747 return TrueWhenUnset ? TrueVal : FalseVal;
4757 return TrueWhenUnset ? TrueVal : FalseVal;
4768 if (CmpRHS == TVal || CmpRHS == FVal) {
4774 if (CmpLHS == FVal) {
4781 Value *
X = CmpLHS, *
Y = CmpRHS;
4782 bool PeekedThroughSelectShuffle =
false;
4784 if (Shuf && Shuf->isSelect()) {
4785 if (Shuf->getOperand(0) ==
Y)
4786 FVal = Shuf->getOperand(1);
4787 else if (Shuf->getOperand(1) ==
Y)
4788 FVal = Shuf->getOperand(0);
4791 PeekedThroughSelectShuffle =
true;
4796 if (!MMI || TVal !=
X ||
4814 if (PeekedThroughSelectShuffle)
4842 ArrayRef<std::pair<Value *, Value *>> Replacements,
Value *TrueVal,
4845 unsigned OrigDropAnnotationsSize =
4846 DropAnnotations ? DropAnnotations->
size() : 0;
4849 false, DropAnnotations, MaxRecurse);
4850 if (!SimplifiedFalseVal)
4851 SimplifiedFalseVal = FalseVal;
4854 TrueVal, Replacements, Q,
4855 true,
nullptr, MaxRecurse);
4856 if (!SimplifiedTrueVal)
4857 SimplifiedTrueVal = TrueVal;
4859 if (SimplifiedFalseVal == SimplifiedTrueVal)
4863 if (DropAnnotations)
4864 DropAnnotations->
truncate(OrigDropAnnotationsSize);
4874 Value *CmpLHS, *CmpRHS;
4891 if (TrueVal->getType()->isIntOrIntVectorTy()) {
4899 X->getType()->getScalarSizeInBits());
4922 if (
match(FalseVal, isRotate) && TrueVal ==
X) {
4925 if (CmpLHS == ShAmt)
4928 unsigned BW =
X->getType()->getScalarSizeInBits();
4952 FalseVal, Q, DropAnnotations,
4958 FalseVal, Q, DropAnnotations,
4969 TrueVal, FalseVal, Q,
4970 DropAnnotations, MaxRecurse))
4979 TrueVal, FalseVal, Q,
4980 DropAnnotations, MaxRecurse))
4994 Value *CmpLHS, *CmpRHS;
4999 bool IsEquiv =
I->isEquivalence();
5000 if (
I->isEquivalence(
true)) {
5010 DropAnnotations, MaxRecurse))
5013 DropAnnotations, MaxRecurse))
5018 if (CmpLHS ==
F && CmpRHS ==
T)
5021 if (CmpLHS !=
T || CmpRHS !=
F)
5074 unsigned DiffVals = 0;
5076 for (
unsigned i = 0; i < 2; i++) {
5092 if (!
SI || !IdenticalSI)
5094 if (
SI->getCondition() != IdenticalSI->getCondition())
5098 Value *IdenticalSIOtherVal =
nullptr;
5099 if (
SI->getTrueValue() == IdenticalSI->getTrueValue()) {
5101 IdenticalSIOtherVal = IdenticalSI->getFalseValue();
5102 }
else if (
SI->getFalseValue() == IdenticalSI->getFalseValue()) {
5104 IdenticalSIOtherVal = IdenticalSI->getTrueValue();
5111 if (!SIOtherVal || IdenticalSIOtherVal != &IdenticalPN)
5127 unsigned MaxRecurse) {
5152 assert(
Cond->getType()->isIntOrIntVectorTy(1) &&
5153 "Select must have bool or bool vector condition");
5154 assert(TrueVal->getType() == FalseVal->getType() &&
5155 "Select must have same types for true/false ops");
5157 if (
Cond->getType() == TrueVal->getType()) {
5220 if (TrueVal == FalseVal)
5223 if (
Cond == TrueVal) {
5231 if (
Cond == FalseVal) {
5262 for (
unsigned i = 0; i != NumElts; ++i) {
5266 if (!TEltC || !FEltC)
5282 if (NewC.
size() == NumElts)
5287 DropAnnotations, MaxRecurse))
5294 DropAnnotations, MaxRecurse))
5299 return *Imp ? TrueVal : FalseVal;
5315 return ::simplifySelectInst(
Cond, TrueVal, FalseVal, FMF, Q, DropAnnotations,
5329 if (Indices.
empty())
5359 bool IsScalableVec =
5360 SrcTy->isScalableTy() ||
any_of(Indices, [](
const Value *
V) {
5364 if (Indices.
size() == 1) {
5366 if (!IsScalableVec && Ty->isSized()) {
5371 if (TyAllocSize == 0 && Ptr->
getType() == GEPTy)
5379 auto CanSimplify = [GEPTy, &
P, Ptr]() ->
bool {
5380 return P->getType() == GEPTy &&
5384 if (TyAllocSize == 1 &&
5392 if (
match(Indices[0],
5396 TyAllocSize == 1ULL <<
C && CanSimplify())
5401 if (
match(Indices[0],
5420 APInt BasePtrOffset(IdxWidth, 0);
5421 Value *StrippedBasePtr =
5430 APInt Offset = IsNeg ? BasePtrOffset : BasePtrOffset - 1;
5431 if (PtrOp == StrippedBasePtr && !
Offset.isZero()) {
5455 return ::simplifyGEPInst(SrcTy, Ptr, Indices, NW, Q,
RecursionLimit);
5475 if (EV->getAggregateOperand()->getType() == Agg->
getType() &&
5476 EV->getIndices() == Idxs) {
5482 return EV->getAggregateOperand();
5485 if (Agg == EV->getAggregateOperand())
5495 return ::simplifyInsertValueInst(Agg, Val, Idxs, Q,
RecursionLimit);
5504 if (VecC && ValC && IdxC)
5525 if (VecC && ValC && VecC->getSplatValue() == ValC)
5545 unsigned NumIdxs = Idxs.
size();
5550 if (!VisitedSet.
insert(IVI).second)
5554 unsigned NumInsertValueIdxs = InsertValueIdxs.
size();
5555 unsigned NumCommonIdxs = std::min(NumInsertValueIdxs, NumIdxs);
5556 if (InsertValueIdxs.
slice(0, NumCommonIdxs) ==
5557 Idxs.
slice(0, NumCommonIdxs)) {
5558 if (NumIdxs == NumInsertValueIdxs)
5559 return IVI->getInsertedValueOperand();
5566 if (Idxs.
size() == 1 &&
5573 assert(Idxs[0] == 1 &&
"invalid index");
5607 unsigned MinNumElts = VecVTy->getElementCount().getKnownMinValue();
5611 if (IdxC->getValue().ult(MinNumElts))
5622 if (IE && IE->getOperand(2) == Idx)
5623 return IE->getOperand(1);
5634 return ::simplifyExtractElementInst(Vec, Idx, Q,
RecursionLimit);
5661 for (
unsigned I = 0,
5679 if (CBase && CVal && COffset)
5709 if (CSrc && COffset)
5718 if (Src->getType() == Ty)
5744 Value *CommonValue =
nullptr;
5745 bool HasPoisonInput =
false;
5746 bool HasUndefInput =
false;
5747 for (
Value *Incoming : IncomingValues) {
5752 HasPoisonInput =
true;
5757 HasUndefInput =
true;
5760 if (CommonValue && Incoming != CommonValue)
5762 CommonValue = Incoming;
5771 if (HasPoisonInput || HasUndefInput) {
5779 if (HasUndefInput &&
5794 auto *Src = CI->getOperand(0);
5795 Type *SrcTy = Src->getType();
5796 Type *MidTy = CI->getType();
5798 if (Src->getType() == Ty) {
5799 auto FirstOp = CI->getOpcode();
5802 &Q.
DL) == Instruction::BitCast)
5808 if (CastOpc == Instruction::BitCast)
5809 if (
Op->getType() == Ty)
5818 if (CastOpc == Instruction::PtrToAddr &&
5824 if (CastOpc == Instruction::ZExt || CastOpc == Instruction::SExt) {
5827 bool NoWrap = CastOpc == Instruction::ZExt ?
Trunc->hasNoUnsignedWrap()
5828 :
Trunc->hasNoSignedWrap();
5829 if (Src->getType() == Ty && NoWrap)
5844 unsigned MaxRecurse) {
5847 Op->getType()->getPointerAddressSpace()))
5850 return ::simplifyCastInst(Instruction::AddrSpaceCast,
Op, Ty, Q, MaxRecurse);
5862 int MaskVal,
Value *RootVec,
5863 unsigned MaxRecurse) {
5874 int RootElt = MaskVal;
5875 Value *SourceOp = Op0;
5876 if (MaskVal >= InVecNumElts) {
5877 RootElt = MaskVal - InVecNumElts;
5885 DestElt, SourceShuf->getOperand(0), SourceShuf->getOperand(1),
5886 SourceShuf->getMaskValue(RootElt), RootVec, MaxRecurse);
5895 if (RootVec != SourceOp)
5900 if (RootElt != DestElt)
5909 unsigned MaxRecurse) {
5914 unsigned MaskNumElts = Mask.size();
5915 ElementCount InVecEltCount = InVecTy->getElementCount();
5920 Indices.
assign(Mask.begin(), Mask.end());
5925 bool MaskSelects0 =
false, MaskSelects1 =
false;
5927 for (
unsigned i = 0; i != MaskNumElts; ++i) {
5928 if (Indices[i] == -1)
5930 if ((
unsigned)Indices[i] < InVecNumElts)
5931 MaskSelects0 =
true;
5933 MaskSelects1 =
true;
5947 if (Op0Const && Op1Const)
5953 if (!Scalable && Op0Const && !Op1Const) {
5971 if (
all_of(Indices, [InsertIndex](
int MaskElt) {
5972 return MaskElt == InsertIndex || MaskElt == -1;
5978 for (
unsigned i = 0; i != MaskNumElts; ++i)
5979 if (Indices[i] == -1)
6007 Value *RootVec =
nullptr;
6008 for (
unsigned i = 0; i != MaskNumElts; ++i) {
6015 if (!RootVec || RootVec->
getType() != RetTy)
6025 return ::simplifyShuffleVectorInst(Op0, Op1, Mask, RetTy, Q,
RecursionLimit);
6059 Type *Ty = In->getType();
6061 unsigned NumElts = VecTy->getNumElements();
6063 for (
unsigned i = 0; i != NumElts; ++i) {
6064 Constant *EltC = In->getAggregateElement(i);
6069 else if (EltC && EltC->
isNaN())
6070 NewC[i] = ConstantFP::get(
6086 auto *
Splat = In->getSplatValue();
6088 "Found a scalable-vector NaN but not a splat");
6117 if (FMF.
noNaNs() && (IsNan || IsUndef))
6119 if (FMF.
noInfs() && (IsInf || IsUndef))
6310 if (
Known.getSignBit() ==
false)
6313 if (
Known.getSignBit() ==
true)
6341 return simplifyFMAFMul(Op0, Op1, FMF, Q, MaxRecurse, ExBehavior, Rounding);
6348 return ::simplifyFAddInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6356 return ::simplifyFSubInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6364 return ::simplifyFMulInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6372 return ::simplifyFMAFMul(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6405 return ConstantFP::get(Op0->
getType(), 1.0);
6420 return ConstantFP::get(Op0->
getType(), -1.0);
6434 return ::simplifyFDivInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6472 return ::simplifyFRemInst(Op0, Op1, FMF, Q,
RecursionLimit, ExBehavior,
6481 unsigned MaxRecurse) {
6483 case Instruction::FNeg:
6495 unsigned MaxRecurse) {
6497 case Instruction::FNeg:
6518 case Instruction::Add:
6521 case Instruction::Sub:
6524 case Instruction::Mul:
6527 case Instruction::SDiv:
6529 case Instruction::UDiv:
6531 case Instruction::SRem:
6533 case Instruction::URem:
6535 case Instruction::Shl:
6538 case Instruction::LShr:
6540 case Instruction::AShr:
6542 case Instruction::And:
6544 case Instruction::Or:
6546 case Instruction::Xor:
6548 case Instruction::FAdd:
6550 case Instruction::FSub:
6552 case Instruction::FMul:
6554 case Instruction::FDiv:
6556 case Instruction::FRem:
6568 unsigned MaxRecurse) {
6570 case Instruction::FAdd:
6572 case Instruction::FSub:
6574 case Instruction::FMul:
6576 case Instruction::FDiv:
6578 case Instruction::FRem:
6592 return ::simplifyBinOp(Opcode, LHS, RHS, FMF, Q,
RecursionLimit);
6605 return ::simplifyCmpInst(Predicate, LHS, RHS, Q,
RecursionLimit);
6614 case Intrinsic::fabs:
6615 case Intrinsic::floor:
6616 case Intrinsic::ceil:
6617 case Intrinsic::trunc:
6618 case Intrinsic::rint:
6619 case Intrinsic::nearbyint:
6620 case Intrinsic::round:
6621 case Intrinsic::roundeven:
6622 case Intrinsic::canonicalize:
6623 case Intrinsic::arithmetic_fence:
6635 case Intrinsic::floor:
6636 case Intrinsic::ceil:
6637 case Intrinsic::trunc:
6638 case Intrinsic::rint:
6639 case Intrinsic::nearbyint:
6640 case Intrinsic::round:
6641 case Intrinsic::roundeven:
6656 if (!OffsetConstInt || OffsetConstInt->getBitWidth() > 64)
6660 DL.getIndexTypeSizeInBits(Ptr->
getType()));
6661 if (OffsetInt.
srem(4) != 0)
6673 if (LoadedCE->getOpcode() == Instruction::Trunc) {
6679 if (LoadedCE->getOpcode() != Instruction::Sub)
6683 if (!LoadedLHS || LoadedLHS->getOpcode() != Instruction::PtrToInt)
6685 auto *LoadedLHSPtr = LoadedLHS->getOperand(0);
6689 APInt LoadedRHSOffset;
6692 PtrSym != LoadedRHSSym || PtrOffset != LoadedRHSOffset)
6695 return LoadedLHSPtr;
6721 if (
C && (
C->isZero() ||
C->isInfinity()))
6730 if (
C &&
C->isNaN())
6731 return ConstantFP::get(Op0->
getType(),
C->makeQuiet());
6749 if (
II->getIntrinsicID() == IID)
6766 case Intrinsic::fabs: {
6777 case Intrinsic::bswap:
6782 case Intrinsic::bitreverse:
6787 case Intrinsic::ctpop: {
6790 return ConstantInt::get(Op0->
getType(), 1);
6799 case Intrinsic::exp:
6805 case Intrinsic::exp2:
6811 case Intrinsic::exp10:
6817 case Intrinsic::log:
6823 case Intrinsic::log2:
6831 case Intrinsic::log10:
6840 case Intrinsic::vector_reverse:
6848 case Intrinsic::structured_gep:
6870 if (Op1 ==
X || Op1 ==
Y ||
6886 Value *Op1,
unsigned MaxRecurse) {
6889 case Intrinsic::maxnum:
6890 case Intrinsic::minnum:
6891 case Intrinsic::maximum:
6892 case Intrinsic::minimum:
6893 case Intrinsic::maximumnum:
6894 case Intrinsic::minimumnum:
6901 assert(IsMinimumMaximumIntrinsic(IID) &&
"Unsupported intrinsic");
6907 if (!
M0 ||
M0->getIntrinsicID() != IID)
6909 Value *X0 =
M0->getOperand(0);
6910 Value *Y0 =
M0->getOperand(1);
6917 if (X0 == Op1 || Y0 == Op1)
6928 if (!
M1 || !IsMinimumMaximumIntrinsic(
M1->getIntrinsicID()))
6930 Value *X1 =
M1->getOperand(0);
6931 Value *Y1 =
M1->getOperand(1);
6939 if ((X0 == X1 && Y0 == Y1) || (X0 == Y1 && Y0 == X1))
6962 assert(OutNewConstVal !=
nullptr);
6964 bool PropagateNaN = IID == Intrinsic::minimum || IID == Intrinsic::maximum;
6965 bool PropagateSNaN = IID == Intrinsic::minnum || IID == Intrinsic::maxnum;
6966 bool IsMin = IID == Intrinsic::minimum || IID == Intrinsic::minnum ||
6967 IID == Intrinsic::minimumnum;
6971 *OutNewConstVal =
const_cast<Constant *
>(RHSConst);
6989 if (PropagateNaN || (PropagateSNaN && CAPF.
isSignaling())) {
7004 *OutNewConstVal =
const_cast<Constant *
>(RHSConst);
7024 unsigned Width = ReturnType->getPrimitiveSizeInBits();
7028 case Intrinsic::aarch64_sve_eorv:
7029 case Intrinsic::aarch64_sve_orv:
7030 case Intrinsic::aarch64_sve_saddv:
7031 case Intrinsic::aarch64_sve_uaddv:
7032 case Intrinsic::aarch64_sve_umaxv:
7033 if ((
C0 &&
C0->isNullValue()) || (
C1 &&
C1->isNullValue()))
7034 return ConstantInt::get(ReturnType, 0);
7036 case Intrinsic::aarch64_sve_andv:
7037 case Intrinsic::aarch64_sve_uminv:
7038 if ((
C0 &&
C0->isNullValue()) || (
C1 &&
C1->isAllOnesValue()))
7041 case Intrinsic::aarch64_sve_smaxv:
7042 if ((
C0 &&
C0->isNullValue()) || (
C1 &&
C1->isMinSignedValue()))
7045 case Intrinsic::aarch64_sve_sminv:
7046 if ((
C0 &&
C0->isNullValue()) || (
C1 &&
C1->isMaxSignedValue()))
7052 case Intrinsic::aarch64_sve_andv:
7053 case Intrinsic::aarch64_sve_orv:
7054 case Intrinsic::aarch64_sve_smaxv:
7055 case Intrinsic::aarch64_sve_sminv:
7056 case Intrinsic::aarch64_sve_umaxv:
7057 case Intrinsic::aarch64_sve_uminv:
7059 if (
C0 &&
C0->isAllOnesValue()) {
7061 assert(SplatVal->getType() == ReturnType &&
"Unexpected result type!");
7066 case Intrinsic::aarch64_sve_eorv:
7068 if (
C0 &&
C0->isAllOnesValue())
7070 return ConstantInt::get(ReturnType, 0);
7080 unsigned BitWidth = ReturnType->getScalarSizeInBits();
7082 case Intrinsic::vector_shuffle:
7091 case Intrinsic::get_active_lane_mask: {
7100 Attribute Attr =
F->getFnAttribute(Attribute::VScaleRange);
7101 if (ScalableTy && Attr.
isValid()) {
7106 (
uint64_t)ScalableTy->getMinNumElements() * (*VScaleMax);
7108 const APInt *Op1Val;
7110 Op1Val->
uge(MaxPossibleMaskElements))
7115 case Intrinsic::abs:
7123 case Intrinsic::cttz: {
7129 case Intrinsic::ctlz: {
7137 case Intrinsic::pdep: {
7146 case Intrinsic::pext: {
7155 case Intrinsic::ptrmask: {
7163 "Invalid mask width");
7180 APInt IrrelevantPtrBits =
7183 Instruction::Or,
C, ConstantInt::get(
C->getType(), IrrelevantPtrBits),
7185 if (
C !=
nullptr &&
C->isAllOnesValue())
7190 case Intrinsic::smax:
7191 case Intrinsic::smin:
7192 case Intrinsic::umax:
7193 case Intrinsic::umin: {
7204 return ConstantInt::get(
7212 return ConstantInt::get(ReturnType, *
C);
7224 if (MinMax0 && MinMax0->getIntrinsicID() == IID) {
7226 Value *M00 = MinMax0->getOperand(0), *M01 = MinMax0->getOperand(1);
7227 const APInt *InnerC;
7250 case Intrinsic::scmp:
7251 case Intrinsic::ucmp: {
7260 return ConstantInt::get(ReturnType, 1);
7269 case Intrinsic::umulh:
7270 case Intrinsic::smulh:
7272 if (IID == Intrinsic::umulh ||
BitWidth == 1)
7284 case Intrinsic::usub_with_overflow:
7285 case Intrinsic::ssub_with_overflow:
7292 case Intrinsic::uadd_with_overflow:
7293 case Intrinsic::sadd_with_overflow:
7303 case Intrinsic::umul_with_overflow:
7304 case Intrinsic::smul_with_overflow:
7314 case Intrinsic::uadd_sat:
7320 case Intrinsic::sadd_sat:
7335 case Intrinsic::usub_sat:
7340 case Intrinsic::ssub_sat:
7348 case Intrinsic::ushl_sat:
7349 case Intrinsic::sshl_sat:
7358 if (IID == Intrinsic::ushl_sat) {
7368 case Intrinsic::load_relative:
7373 case Intrinsic::powi:
7376 if (Power->isZero())
7377 return ConstantFP::get(Op0->
getType(), 1.0);
7383 case Intrinsic::ldexp:
7385 case Intrinsic::fptrunc_round:
7392 case Intrinsic::copysign:
7402 case Intrinsic::is_fpclass: {
7406 return ConstantInt::get(ReturnType,
true);
7408 return ConstantInt::get(ReturnType,
false);
7413 case Intrinsic::maxnum:
7414 case Intrinsic::minnum:
7415 case Intrinsic::maximum:
7416 case Intrinsic::minimum:
7417 case Intrinsic::maximumnum:
7418 case Intrinsic::minimumnum: {
7441 if (
Constant *SplatVal =
C->getSplatValue()) {
7447 }
else if (ElemCount.
isFixed()) {
7457 auto *Elt =
C->getAggregateElement(i);
7464 (ElemResult != OptResult &&
7472 OptResult = ElemResult;
7499 case Intrinsic::vector_extract: {
7505 IdxN == 0 &&
X->getType() == ReturnType)
7511 case Intrinsic::aarch64_sve_andv:
7512 case Intrinsic::aarch64_sve_eorv:
7513 case Intrinsic::aarch64_sve_orv:
7514 case Intrinsic::aarch64_sve_saddv:
7515 case Intrinsic::aarch64_sve_smaxv:
7516 case Intrinsic::aarch64_sve_sminv:
7517 case Intrinsic::aarch64_sve_uaddv:
7518 case Intrinsic::aarch64_sve_umaxv:
7519 case Intrinsic::aarch64_sve_uminv:
7533 if (!Factor || Factor != Args.size())
7538 for (
unsigned Idx = 0; Idx != Factor; ++Idx) {
7540 if (!EV || EV->getNumIndices() != 1 || *EV->idx_begin() != Idx)
7544 if (!CurDI || CurDI->getIntrinsicID() != DeinterleaveID)
7549 else if (DI != CurDI)
7561 unsigned NumOperands = Args.size();
7577 case Intrinsic::vscale: {
7582 return ConstantInt::get(ReturnType,
C->getZExtValue());
7593 if (NumOperands == 1)
7596 if (NumOperands == 2)
7601 case Intrinsic::masked_load:
7602 case Intrinsic::masked_gather: {
7603 Value *MaskArg = Args[1];
7604 Value *PassthruArg = Args[2];
7611 case Intrinsic::fshl:
7612 case Intrinsic::fshr: {
7613 Value *Op0 = Args[0], *Op1 = Args[1], *ShAmtArg = Args[2];
7621 return Args[IID == Intrinsic::fshl ? 0 : 1];
7623 const APInt *ShAmtC;
7629 return Args[IID == Intrinsic::fshl ? 0 : 1];
7637 *
C1 + *C2 ==
BitWidth && ShAmt == *(IID == Intrinsic::fshl ?
C1 : C2))
7651 case Intrinsic::experimental_constrained_fma:
7652 return simplifyFPOp(Args, {}, Q, ExBehavior, Rounding);
7653 case Intrinsic::fma:
7654 case Intrinsic::fmuladd:
7657 case Intrinsic::smul_fix:
7658 case Intrinsic::smul_fix_sat: {
7659 Value *Op0 = Args[0];
7660 Value *Op1 = Args[1];
7661 Value *Op2 = Args[2];
7686 case Intrinsic::vector_insert: {
7687 Value *Vec = Args[0];
7688 Value *SubVec = Args[1];
7689 Value *Idx = Args[2];
7698 X->getType() == ReturnType)
7703 case Intrinsic::vector_splice_right: {
7712 case Intrinsic::vector_splice_left: {
7721 if (Ty->isScalableTy())
7724 : ConstantRange::getFull(
BitWidth));
7733 return IID == Intrinsic::vector_splice_left ? Args[0] : Args[1];
7737 case Intrinsic::experimental_constrained_fadd:
7739 case Intrinsic::experimental_constrained_fsub:
7741 case Intrinsic::experimental_constrained_fmul:
7743 case Intrinsic::experimental_constrained_fdiv:
7745 case Intrinsic::experimental_constrained_frem:
7747 case Intrinsic::experimental_constrained_ldexp:
7749 case Intrinsic::experimental_vp_reverse: {
7750 Value *Vec = Args[0];
7751 Value *EVL = Args[2];
7774 Type *ReturnType =
Call->getCalledFunction()->getReturnType();
7777 case Intrinsic::experimental_gc_relocate: {
7803 ExBehavior = Constrained->getExceptionBehavior().value_or(ExBehavior);
7804 Rounding = Constrained->getRoundingMode().value_or(Rounding);
7807 IID, ReturnType, Args,
Call->getFastMathFlagsOrNone(),
7815 auto *
F =
Call->getCalledFunction();
7822 ConstantArgs.
reserve(Args.size());
7823 for (
Value *Arg : Args) {
7847 if (
Call->isMustTailCall())
7859 if (
F &&
F->isIntrinsic())
7886 return ::simplifyFreezeInst(Op0, Q);
7900 if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())
7931 assert(
I->getFunction() &&
"instruction should be inserted in a function");
7933 "context instruction should be in the same function");
7937 switch (
I->getOpcode()) {
7942 [](
Value *
V) { return cast<Constant>(V); });
7946 case Instruction::FNeg:
7948 case Instruction::FAdd:
7951 case Instruction::Add:
7955 case Instruction::FSub:
7958 case Instruction::Sub:
7962 case Instruction::FMul:
7965 case Instruction::Mul:
7969 case Instruction::SDiv:
7973 case Instruction::UDiv:
7977 case Instruction::FDiv:
7980 case Instruction::SRem:
7982 case Instruction::URem:
7984 case Instruction::FRem:
7987 case Instruction::Shl:
7991 case Instruction::LShr:
7995 case Instruction::AShr:
7999 case Instruction::And:
8001 case Instruction::Or:
8003 case Instruction::Xor:
8005 case Instruction::ICmp:
8007 NewOps[1], Q, MaxRecurse);
8008 case Instruction::FCmp:
8010 NewOps[1],
I->getFastMathFlags(), Q, MaxRecurse);
8011 case Instruction::Select: {
8014 FMF = FPMO->getFastMathFlags();
8016 DropAnnotations, MaxRecurse);
8018 case Instruction::GetElementPtr: {
8021 ArrayRef(NewOps).slice(1), GEPI->getNoWrapFlags(), Q,
8024 case Instruction::InsertValue: {
8029 case Instruction::InsertElement:
8031 case Instruction::ExtractValue: {
8036 case Instruction::ExtractElement:
8038 case Instruction::BitInsert:
8041 case Instruction::BitExtract:
8044 case Instruction::ShuffleVector: {
8047 SVI->getShuffleMask(), SVI->getType(), Q,
8050 case Instruction::PHI:
8052 case Instruction::Call:
8057 case Instruction::Freeze:
8059#define HANDLE_CAST_INST(num, opc, clas) case Instruction::opc:
8060#include "llvm/IR/Instruction.def"
8061#undef HANDLE_CAST_INST
8062 if (
I->getOpcode() == Instruction::AddrSpaceCast) {
8064 NewOps[0],
I->getType(),
8071 case Instruction::Alloca:
8074 case Instruction::Load:
8083 "Number of operands should match the instruction!");
8084 return ::simplifyInstructionWithOperands(
8118 bool Simplified =
false;
8130 I->replaceAllUsesWith(SimpleV);
8132 if (!
I->isEHPad() && !
I->isTerminator() && !
I->mayHaveSideEffects())
8133 I->eraseFromParent();
8139 for (
unsigned Idx = 0; Idx != Worklist.
size(); ++Idx) {
8145 if (UnsimplifiedUsers)
8146 UnsimplifiedUsers->insert(
I);
8159 I->replaceAllUsesWith(SimpleV);
8161 if (!
I->isEHPad() && !
I->isTerminator() && !
I->mayHaveSideEffects())
8162 I->eraseFromParent();
8171 assert(
I != SimpleV &&
"replaceAndRecursivelySimplify(X,X) is not valid!");
8172 assert(SimpleV &&
"Must provide a simplified value.");
8180 auto *DT = DTWP ? &DTWP->
getDomTree() :
nullptr;
8182 auto *
TLI = TLIWP ? &TLIWP->getTLI(
F) :
nullptr;
8185 return {
F.getDataLayout(),
TLI, DT, AC};
8193template <
class T,
class... TArgs>
8196 auto *DT = AM.template getCachedResult<DominatorTreeAnalysis>(
F);
8197 auto *
TLI = AM.template getCachedResult<TargetLibraryAnalysis>(
F);
8198 auto *AC = AM.template getCachedResult<AssumptionAnalysis>(
F);
8199 return {
F.getDataLayout(),
TLI, DT, AC};
8213void InstSimplifyFolder::anchor() {}
const TargetLowering & TLI
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 * 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 * simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, SmallVectorImpl< Instruction * > *DropAnnotations, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is an integer comparison.
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 bool isPoisonBitRange(Value *Offset, Type *Ty, Type *SrcTy, const SimplifyQuery &Q)
Return true if accessing the bit range of type Ty at Offset in a value of type SrcTy is poison.
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 * foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1, unsigned MaxRecurse)
Given a min/max intrinsic, see if it can be removed based on having an operand that is another min/ma...
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 * 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 Value * simplifySelectWithEquivalence(ArrayRef< std::pair< Value *, Value * > > Replacements, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, SmallVectorImpl< Instruction * > *DropAnnotations, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is an integer equality or floating-po...
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 * simplifySelectWithFCmp(Value *Cond, Value *T, Value *F, FastMathFlags FMF, const SimplifyQuery &Q, SmallVectorImpl< Instruction * > *DropAnnotations, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is a floating-point comparison.
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 constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
SmallVector< MachineOperand, 4 > Cond
This header provides classes for managing per-loop analyses.
uint64_t IntrinsicInst * II
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.
LLVM_ABI APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
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.
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 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.
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_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH 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 * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
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.
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 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 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...
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Legacy analysis pass which computes a DominatorTree.
DominatorTree & getDomTree()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
This instruction compares its operands according to the predicate given to the constructor.
Convenience struct for specifying and reasoning about fast-math flags.
bool noSignedZeros() const
bool allowReassoc() const
Flag queries.
Represents calls to the gc.relocate intrinsic.
LLVM_ABI Value * getBasePtr() const
LLVM_ABI Value * getDerivedPtr() const
Represents flags for the getelementptr instruction/expression.
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
This instruction compares its operands according to the predicate given to the constructor.
static LLVM_ABI bool compare(const APInt &LHS, const APInt &RHS, ICmpInst::Predicate Pred)
Return result of LHS Pred RHS comparison.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
bool isEquality() const
Return true if this predicate is either EQ or NE.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
This instruction inserts a struct field of array element value into an aggregate value.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
LLVM_ABI bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
A wrapper class for inspecting calls to intrinsic functions.
bool isKnownAlwaysNaN() const
Return true if it's known this must always be a nan.
static constexpr FPClassTest OrderedLessThanZeroMask
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
std::optional< bool > getSignBit() const
std::nullopt if the sign bit is unknown, true if the sign bit is definitely set or false if the sign ...
bool cannotBeOrderedLessThanZero() const
Return true if we can prove that the analyzed floating-point value is either NaN or never less than -...
An instruction for reading from memory.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
static APInt getSaturationPoint(Intrinsic::ID ID, unsigned numBits)
Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values, so there is a certain thre...
static ICmpInst::Predicate getPredicate(Intrinsic::ID ID)
Returns the comparison predicate underlying the intrinsic.
op_range incoming_values()
Value * getIncomingValueForBlock(const BasicBlock *BB) const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Pass interface - Implemented by all 'passes'.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class represents a sign extension of integer types.
This class represents the LLVM 'select' instruction.
const Value * getFalseValue() const
const Value * getTrueValue() const
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
void reserve(size_type N)
void truncate(size_type N)
Like resize, but requires that N is less than size().
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
This is a wrapper around stripAndAccumulateConstantOffsets with the in-bounds requirement set to fals...
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr, bool LookThroughIntToPtr=false) const
Accumulate the constant offset this value has compared to a base pointer.
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
This class represents zero extension of integer types.
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr bool isFixed() const
Returns true if the quantity is not scaled by vscale.
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
const ParentTy * getParent() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI Intrinsic::ID getDeinterleaveIntrinsicID(unsigned Factor)
Returns the corresponding llvm.vector.deinterleaveN intrinsic for factor N.
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
auto m_PosZeroFP()
Matches a floating-point positive zero.
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
AllOnesConstantMatch m_AllOnes()
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
match_combine_and< Ty... > m_CombineAnd(const Ty &...Ps)
Combine pattern matchers matching all of Ps patterns.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
auto m_BSwap(const Opnd0 &Op0)
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
auto m_BitReverse(const Opnd0 &Op0)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
auto m_PtrToIntOrAddr(const OpTy &Op)
Matches PtrToInt or PtrToAddr.
FNeg_match< OpTy, false > m_FNeg(const OpTy &X)
Match fneg X only.
cstfp_pred_ty< is_inf > m_Inf()
Match a positive or negative infinity FP constant.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
auto m_Poison()
Match an arbitrary poison constant.
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
auto m_Sqrt(const Opnd0 &Op0)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
auto m_UMin(const Opnd0 &Op0, const Opnd1 &Op1)
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
ap_match< APFloat > m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
ap_match< APFloat > m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
auto match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
auto m_SMax(const Opnd0 &Op0, const Opnd1 &Op1)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
auto m_BinOp()
Match an arbitrary binary operation and ignore it.
auto m_UMax(const Opnd0 &Op0, const Opnd1 &Op1)
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
match_combine_or< CastInst_match< OpTy, UIToFPInst >, CastInst_match< OpTy, SIToFPInst > > m_IToFP(const OpTy &Op)
ICmpLike_match< LHS, RHS > m_ICmpLike(CmpPredicate &Pred, const LHS &L, const RHS &R)
auto m_Value()
Match an arbitrary value and ignore it.
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
auto m_Ctpop(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
auto m_Constant()
Match an arbitrary Constant and ignore it.
CastInst_match< OpTy, FPExtInst > m_FPExt(const OpTy &Op)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
is_zero< true > m_Zero()
Match any null constant or a vector with all elements equal to 0.
auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
PtrAdd_match< PointerOpTy, OffsetOpTy > m_PtrAdd(const DataLayout &DL, const PointerOpTy &PointerOp, const OffsetOpTy &OffsetOp)
Matches GEP with i8 source element type and canonical index type.
auto m_FMinNum_or_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1)
match_immconstant_ty m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
cst_pred_ty< custom_checkfn< APInt > > m_CheckedInt(function_ref< bool(const APInt &)> CheckFn)
Match an integer or vector where CheckFn(ele) for each element is true.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
CastInst_match< OpTy, UIToFPInst > m_UIToFP(const OpTy &Op)
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
auto m_c_MaxOrMin(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
auto m_SMin(const Opnd0 &Op0, const Opnd1 &Op1)
FNeg_match< OpTy, true > m_FNegOrFSubNegZero(const OpTy &X)
Match fneg X or fsub -0.0, X.
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
auto m_FAbs(const Opnd0 &Op0)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Exact_match< T > m_Exact(const T &SubPattern)
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
auto m_VecReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElt(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
CastOperator_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
TwoOps_match< Src_t, Off_t, Instruction::BitExtract > m_BitExtract(const Src_t &Src, const Off_t &Off)
Matches BitExtractInst.
ThreeOps_match< Base_t, Val_t, Off_t, Instruction::BitInsert > m_BitInsert(const Base_t &Base, const Val_t &Val, const Off_t &Off)
Matches BitInsertInst.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
auto m_FMaxNum_or_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
ExceptionBehavior
Exception behavior used for floating point operations.
@ ebStrict
This corresponds to "fpexcept.strict".
@ ebIgnore
This corresponds to "fpexcept.ignore".
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Intrinsic::ID getInverseMinMaxIntrinsic(Intrinsic::ID MinMaxID)
LLVM_ABI Value * simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q)
Given operands for a AShr, fold the result or return nulll.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth=0)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Value * simplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FMul, fold the result or return null.
LLVM_ABI Value * simplifyBitInsertInst(Value *Base, Value *Val, Value *Offset, const SimplifyQuery &Q)
Given operands for a BitInsertInst, fold the result or return null.
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to have exactly one bit set when defined.
LLVM_ABI Value * simplifyGEPInst(Type *SrcTy, Value *Ptr, ArrayRef< Value * > Indices, GEPNoWrapFlags NW, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
LLVM_ABI bool canCreatePoison(const Operator *Op, bool ConsiderFlagsAndMetadata=true)
LLVM_ABI Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q, SmallVectorImpl< Instruction * > *DropAnnotations=nullptr)
See if we can compute a simplified version of this instruction.
LLVM_ABI Value * simplifyFreezeInst(Value *Op, const SimplifyQuery &Q)
Given an operand for a Freeze, see if we can fold the result.
LLVM_ABI Constant * ConstantFoldFPInstOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL, const Instruction *I, bool AllowNonDeterministic=true)
Attempt to constant fold a floating point binary operation with the specified operands,...
LLVM_ABI bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS, bool &TrueIfSigned)
Given an exploded icmp instruction, return true if the comparison only checks the sign bit.
@ Known
Known to have no common set bits.
LLVM_ABI APInt getMinMaxLimit(SelectPatternFlavor SPF, unsigned BitWidth)
Return the minimum or maximum constant value for the specified integer min/max flavor and type.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Value * simplifySDivInst(Value *LHS, Value *RHS, bool IsExact, const SimplifyQuery &Q)
Given operands for an SDiv, fold the result or return null.
LLVM_ABI Value * simplifyAddrSpaceCastInst(Value *Op, Type *Ty, bool IsNonNull, const SimplifyQuery &Q)
Given operands for an AddrSpaceCastInst, fold the result or return null.
LLVM_ABI Value * simplifyUnOp(unsigned Opcode, Value *Op, const SimplifyQuery &Q)
Given operand for a UnaryOperator, fold the result or return null.
bool isDefaultFPEnvironment(fp::ExceptionBehavior EB, RoundingMode RM)
Returns true if the exception handling behavior and rounding mode match what is used in the default f...
LLVM_ABI Value * simplifyMulInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for a Mul, fold the result or return null.
LLVM_ABI bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &DL, DSOLocalEquivalent **DSOEquiv=nullptr)
If this constant is a constant offset from a global, return the global and the constant.
LLVM_ABI Value * simplifyInstructionWithOperands(Instruction *I, ArrayRef< Value * > NewOps, const SimplifyQuery &Q)
Like simplifyInstruction but the operands of I are replaced with NewOps.
LLVM_ABI Value * simplifyCall(CallBase *Call, Value *Callee, ArrayRef< Value * > Args, const SimplifyQuery &Q)
Given a callsite, callee, and arguments, fold the result or return null.
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI Constant * ConstantFoldBitInsertOperands(Constant *Base, Constant *Val, Constant *Offset, const DataLayout &DL)
Attempt to constant fold a bitinsert instruction with the specified operands.
bool canRoundingModeBe(RoundingMode RM, RoundingMode QRM)
Returns true if the rounding mode RM may be QRM at compile time or at run time.
LLVM_ABI Value * simplifyIntrinsic(Intrinsic::ID IID, Type *ReturnType, ArrayRef< Value * > Args, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an intrinsic, fold the result or return null.
LLVM_ABI bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
LLVM_ABI Value * simplifyFCmpInst(CmpPredicate Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FCmpInst, fold the result or return null.
LLVM_ABI Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
LLVM_ABI Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, std::optional< ConstantRange > InRange, ArrayRef< Value * > Idxs)
LLVM_ABI CmpInst::Predicate getMinMaxPred(SelectPatternFlavor SPF, bool Ordered=false)
Return the canonical comparison predicate for the specified minimum/maximum flavor.
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
LLVM_ABI Value * simplifyShuffleVectorInst(Value *Op0, Value *Op1, ArrayRef< int > Mask, Type *RetTy, const SimplifyQuery &Q)
Given operands for a ShuffleVectorInst, fold the result or return null.
LLVM_ABI Constant * ConstantFoldCall(const CallBase *Call, Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
LLVM_ABI Value * simplifyOrInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Or, fold the result or return null.
LLVM_ABI Value * simplifyXorInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Xor, fold the result or return null.
LLVM_ABI unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return the number of times the sign bit of the register is replicated into the other bits.
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
LLVM_ABI bool canConstantFoldCallTo(const CallBase *Call, const Function *F, const TargetLibraryInfo *TLI=nullptr)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function.
LLVM_ABI Constant * ConstantFoldIntrinsic(Intrinsic::ID ID, ArrayRef< Constant * > Ops, Type *Ty, const DataLayout &DL, const Function *CtxF=nullptr)
LLVM_ABI Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices.
LLVM_ABI bool MaskedValueIsZero(const Value *V, const APInt &Mask, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if 'V & Mask' is known to be zero.
LLVM_ABI Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
unsigned M1(unsigned Val)
LLVM_ABI Value * simplifySubInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for a Sub, fold the result or return null.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Function *CtxF=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CtxI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
LLVM_ABI Value * simplifyAddInst(Value *LHS, Value *RHS, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
LLVM_ABI Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Fold the constant using the specified DataLayout.
auto dyn_cast_or_null(const Y &Val)
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool isSplatValue(const Value *V, int Index=-1, unsigned Depth=0)
Return true if each element of the vector value V is poisoned or equal to every other non-poisoned el...
LLVM_ABI Constant * ConstantFoldLoadFromUniformValue(Constant *C, Type *Ty, const DataLayout &DL)
If C is a uniform value where all bits are the same (either all zero, all ones, all undef or all pois...
LLVM_ABI SelectPatternFlavor getInverseMinMaxFlavor(SelectPatternFlavor SPF)
Return the inverse minimum/maximum flavor of the specified flavor.
LLVM_ABI bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, SmallSetVector< Instruction *, 8 > *UnsimplifiedUsers=nullptr)
Replace all uses of 'I' with 'SimpleV' and simplify the uses recursively.
LLVM_ABI Constant * ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op, const DataLayout &DL)
Attempt to constant fold a unary operation with the specified operand.
LLVM_ABI bool isAllocLikeFn(const Value *V)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc,...
SelectPatternFlavor
Specific patterns of select instructions we can match.
LLVM_ABI Value * simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q)
Given operands for a Shl, fold the result or return null.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI Value * simplifyFNegInst(Value *Op, FastMathFlags FMF, const SimplifyQuery &Q)
Given operand for an FNeg, fold the result or return null.
LLVM_ABI Value * simplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FSub, fold the result or return null.
LLVM_ABI bool canReplacePointersIfEqual(const Value *From, const Value *To, const DataLayout &DL)
Returns true if a pointer value From can be replaced with another pointer value \To if they are deeme...
LLVM_ABI Value * simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, FastMathFlags FMF, const SimplifyQuery &Q, SmallVectorImpl< Instruction * > *DropAnnotations=nullptr)
Given operands for a SelectInst, fold the result or return null.
LLVM_ABI bool impliesPoison(const Value *ValAssumedPoison, const Value *V)
Return true if V is poison given that ValAssumedPoison is already poison.
@ Off
Use window algorithm after SMS algorithm fails.
LLVM_ABI Value * simplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FRem, fold the result or return null.
LLVM_ABI Value * simplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FAdd, fold the result or return null.
FPClassTest
Floating-point class tests, supported by 'is_fpclass' intrinsic.
LLVM_ABI Value * simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact, const SimplifyQuery &Q)
Given operands for a LShr, fold the result or return null.
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI bool cannotBeNegativeZero(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if we can prove that the specified FP value is never equal to -0.0.
LLVM_ABI unsigned getInterleaveIntrinsicFactor(Intrinsic::ID ID)
Returns the corresponding factor of llvm.vector.interleaveN intrinsics.
LLVM_ABI Value * simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an ICmpInst, fold the result or return null.
LLVM_ABI ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)
Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...
LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
LLVM_ABI Value * simplifyAndInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an And, fold the result or return null.
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth, bool MustPreserveProvenance=false)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool intrinsicPropagatesPoison(Intrinsic::ID IID)
Return whether this intrinsic propagates poison for all operands.
LLVM_ABI Value * simplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an ExtractValueInst, fold the result or return null.
LLVM_ABI bool isNotCrossLaneOperation(const Instruction *I)
Return true if the instruction doesn't potentially cross vector lanes.
LLVM_ABI Value * simplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an InsertValueInst, fold the result or return null.
LLVM_ABI Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.
LLVM_ABI Value * simplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for an FDiv, fold the result or return null.
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
constexpr int PoisonMaskElem
LLVM_ABI Value * simplifyLoadInst(LoadInst *LI, Value *PtrOp, const SimplifyQuery &Q)
Given a load instruction and its pointer operand, fold the result or return null.
LLVM_ABI Value * simplifyFMAFMul(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, fp::ExceptionBehavior ExBehavior=fp::ebIgnore, RoundingMode Rounding=RoundingMode::NearestTiesToEven)
Given operands for the multiplication of a FMA, fold the result or return null.
LLVM_ABI Constant * ConstantFoldBitExtractOperands(Type *Ty, Constant *Src, Constant *Offset, const DataLayout &DL)
Attempt to constant fold a bitextract instruction with the specified result type and operands.
LLVM_ABI Value * simplifyConstrainedFPCall(CallBase *Call, const SimplifyQuery &Q)
Given a constrained FP intrinsic call, tries to compute its simplified version.
LLVM_ABI Value * simplifyBitExtractInst(Type *Ty, Value *Src, Value *Offset, const SimplifyQuery &Q)
Given operands for a BitExtractInst, fold the result or return null.
LLVM_ABI SelectPatternResult matchDecomposedSelectPattern(CmpInst *CmpI, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, FastMathFlags FMF=FastMathFlags(), Instruction::CastOps *CastOp=nullptr)
Determine the pattern that a select with the given compare as its predicate and given values as its t...
LLVM_ABI Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
LLVM_ABI std::optional< DecomposedBitTest > decomposeBitTest(Value *Cond, bool LookThroughTrunc=true, bool AllowNonZeroC=false, bool DecomposeAnd=false)
Decompose an icmp into the form ((X & Mask) pred C) if possible.
LLVM_ABI Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register,...
LLVM_ABI ConstantRange computeConstantRangeIncludingKnownBits(const WithCache< const Value * > &V, bool ForSigned, const SimplifyQuery &SQ)
Combine constant ranges from computeConstantRange() and computeKnownBits().
LLVM_ABI bool isKnownNonEqual(const Value *V1, const Value *V2, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the given values are known to be non-equal when defined.
LLVM_ABI Value * simplifyUDivInst(Value *LHS, Value *RHS, bool IsExact, const SimplifyQuery &Q)
Given operands for a UDiv, fold the result or return null.
DWARFExpression::Operation Op
LLVM_ABI bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, unsigned MaxUsesToExplore=0)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
RoundingMode
Rounding mode.
@ NearestTiesToEven
roundTiesToEven.
@ TowardNegative
roundTowardNegative.
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
unsigned M0(unsigned Val)
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI Value * simplifyInsertElementInst(Value *Vec, Value *Elt, Value *Idx, const SimplifyQuery &Q)
Given operands for an InsertElement, fold the result or return null.
constexpr unsigned BitWidth
LLVM_ABI Value * simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags=nullptr)
See if V simplifies when its operand Op is replaced with RepOp.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI Value * simplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SRem, fold the result or return null.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
LLVM_ABI Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
Attempt to constant fold an insertvalue instruction with the specified operands and indices.
LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
LLVM_ABI std::optional< bool > isImpliedByDomCondition(const Value *Cond, const Instruction *ContextI, const DataLayout &DL)
Return the boolean condition value in the context of the given instruction if it is known based on do...
LLVM_ABI Value * simplifyCmpInst(CmpPredicate Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
LLVM_ABI Constant * ConstantFoldInstOperands(const Instruction *I, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands.
LLVM_ABI bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW=false, bool AllowPoison=true)
Return true if the two given values are negation.
LLVM_ABI Constant * ConstantFoldIntegerCast(Constant *C, Type *DestTy, bool IsSigned, const DataLayout &DL)
Constant fold a zext, sext or trunc, depending on IsSigned and whether the DestTy is wider or narrowe...
LLVM_ABI const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)
std::pair< Value *, FPClassTest > fcmpToClassTest(FCmpInst::Predicate Pred, const Function &F, Value *LHS, Value *RHS, bool LookThroughSrc=true)
Returns a pair of values, which if passed to llvm.is.fpclass, returns the same result as an fcmp with...
LLVM_ABI void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, const LoopInfo *LI=nullptr, unsigned MaxLookup=MaxLookupSearchDepth)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
LLVM_ABI bool isCheckForZeroAndMulWithOverflow(Value *Op0, Value *Op1, bool IsAnd, Use *&Y)
Match one of the patterns up to the select/logic op: Op0 = icmp ne i4 X, 0 Agg = call { i4,...
bool canIgnoreSNaN(fp::ExceptionBehavior EB, FastMathFlags FMF)
Returns true if the possibility of a signaling NaN can be safely ignored.
LLVM_ABI Value * simplifyURemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a URem, fold the result or return null.
LLVM_ABI Value * simplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &Q)
Given operands for an ExtractElementInst, fold the result or return null.
constexpr detail::IsaCheckPredicate< Types... > IsaPred
Function object wrapper for the llvm::isa type check.
LLVM_ABI std::optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsTrue=true, unsigned Depth=0)
Return true if RHS is known to be implied true by LHS.
LLVM_ABI ConstantRange computeConstantRange(const Value *V, bool ForSigned, const SimplifyQuery &SQ, unsigned Depth=0)
Determine the possible constant range of an integer or vector of integer value.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This callback is used in conjunction with PointerMayBeCaptured.
virtual Action captured(const Use *U, UseCaptureInfo CI)=0
Use U directly captures CI.UseCC and additionally CI.ResultCC through the return value of the user of...
virtual void tooManyUses()=0
tooManyUses - The depth of traversal has breached a limit.
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
bool isExact(const BinaryOperator *Op) const
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
bool hasNoSignedWrap(const InstT *Op) const
bool hasNoUnsignedWrap(const InstT *Op) const
bool isNonNegative() const
Returns true if this value is known to be non-negative.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned countMaxTrailingZeros() const
Returns the maximum number of trailing zero bits possible.
bool hasConflict() const
Returns true if there is conflicting information.
unsigned getBitWidth() const
Get the bit width of this value.
unsigned countMaxActiveBits() const
Returns the maximum number of bits needed to represent all possible unsigned values with these known ...
APInt getMinValue() const
Return the minimal unsigned value possible given these KnownBits.
bool isNegative() const
Returns true if this value is known to be negative.
static LLVM_ABI KnownBits shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW=false, bool NSW=false, bool ShAmtNonZero=false)
Compute known bits for shl(LHS, RHS).
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
SelectPatternFlavor Flavor
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
bool CanUseUndef
Controls whether simplifications are allowed to constrain the range of possible values for uses of un...
SimplifyQuery getWithFunction(const Function *F) const
SimplifyQuery getWithInstruction(const Instruction *I) const
LLVM_ABI bool isUndefValue(Value *V) const
If CanUseUndef is true, returns whether V is undef.
const Function * getFunction() const
const TargetLibraryInfo * TLI
SimplifyQuery getWithoutUndef() const
Capture information for a specific Use.