45 #define DEBUG_TYPE "instsimplify" 49 STATISTIC(NumExpand,
"Number of expansions");
50 STATISTIC(NumReassoc,
"Number of reassociations");
71 if (
auto *BO = dyn_cast<BinaryOperator>(Cond))
72 BinOpCode = BO->getOpcode();
77 if (BinOpCode == BinaryOperator::Or) {
79 }
else if (BinOpCode == BinaryOperator::And) {
101 Pred1 != Pred2 || Pred1 != ExpectedPred)
104 if (X == TrueVal || X == FalseVal || Y == TrueVal || Y == FalseVal)
105 return BinOpCode == BinaryOperator::Or ? TrueVal : FalseVal;
130 if (CPred == Pred && CLHS == LHS && CRHS == RHS)
176 if (Op0->getOpcode() == OpcodeToExpand) {
178 Value *
A = Op0->getOperand(0), *
B = Op0->getOperand(1), *
C = RHS;
185 && L ==
B &&
R == A)) {
199 if (Op1->getOpcode() == OpcodeToExpand) {
208 && L ==
C &&
R == B)) {
228 unsigned MaxRecurse) {
248 if (V == B)
return LHS;
258 if (Op1 && Op1->getOpcode() == Opcode) {
260 Value *
B = Op1->getOperand(0);
267 if (V == B)
return RHS;
290 if (V == A)
return LHS;
300 if (Op1 && Op1->getOpcode() == Opcode) {
302 Value *
B = Op1->getOperand(0);
309 if (V == C)
return RHS;
327 unsigned MaxRecurse) {
333 if (isa<SelectInst>(LHS)) {
334 SI = cast<SelectInst>(LHS);
336 assert(isa<SelectInst>(RHS) &&
"No select instruction operand!");
337 SI = cast<SelectInst>(RHS);
357 if (TV && isa<UndefValue>(TV))
359 if (FV && isa<UndefValue>(FV))
370 if ((FV && !TV) || (TV && !FV)) {
379 Value *UnsimplifiedLHS = SI == LHS ? UnsimplifiedBranch : LHS;
380 Value *UnsimplifiedRHS = SI == LHS ? RHS : UnsimplifiedBranch;
381 if (Simplified->
getOperand(0) == UnsimplifiedLHS &&
385 Simplified->
getOperand(1) == UnsimplifiedLHS &&
399 unsigned MaxRecurse) {
405 if (!isa<SelectInst>(LHS)) {
409 assert(isa<SelectInst>(LHS) &&
"Not comparing with a select instruction!");
421 TCmp =
getTrue(Cond->getType());
427 TCmp =
getTrue(Cond->getType());
481 unsigned MaxRecurse) {
487 if (isa<PHINode>(LHS)) {
488 PI = cast<PHINode>(LHS);
493 assert(isa<PHINode>(RHS) &&
"No PHI instruction operand!");
494 PI = cast<PHINode>(RHS);
501 Value *CommonValue =
nullptr;
504 if (Incoming == PI)
continue;
505 Value *V = PI == LHS ?
510 if (!V || (CommonValue && V != CommonValue))
529 if (!isa<PHINode>(LHS)) {
533 assert(isa<PHINode>(LHS) &&
"Not comparing with a phi instruction!");
534 PHINode *PI = cast<PHINode>(LHS);
541 Value *CommonValue =
nullptr;
544 if (Incoming == PI)
continue;
548 if (!V || (CommonValue && V != CommonValue))
559 if (
auto *CLHS = dyn_cast<Constant>(Op0)) {
560 if (
auto *CRHS = dyn_cast<Constant>(Op1))
652 bool AllowNonInbounds =
false) {
664 if ((!AllowNonInbounds && !
GEP->isInBounds()) ||
665 !
GEP->accumulateConstantOffset(DL, Offset))
667 V =
GEP->getPointerOperand();
669 V = cast<Operator>(V)->getOperand(0);
670 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
671 if (GA->isInterposable())
673 V = GA->getAliasee();
676 if (
Value *RV = CS.getReturnedArgOperand()) {
683 }
while (Visited.insert(V).second);
738 if (Known.Zero.isMaxSignedValue()) {
751 Value *
X =
nullptr, *
Y =
nullptr, *
Z = Op1;
849 unsigned MaxRecurse) {
887 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
894 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
927 for (
unsigned i = 0; i != NumElts; ++i) {
929 if (Elt && (Elt->
isNullValue() || isa<UndefValue>(Elt)))
968 Constant *
C = dyn_cast_or_null<Constant>(V);
975 unsigned MaxRecurse,
bool IsSigned) {
1033 bool IsSigned = Opcode == Instruction::SDiv;
1038 auto *Mul = cast<OverflowingBinaryOperator>(Op0);
1066 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1072 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1076 if (
isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1092 if ((Opcode == Instruction::SRem &&
1094 (Opcode == Instruction::URem &&
1100 ((Opcode == Instruction::SRem &&
1102 (Opcode == Instruction::URem &&
1108 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1114 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1119 if (
isDivZero(Op0, Op1, Q, MaxRecurse, Opcode == Instruction::SRem))
1128 unsigned MaxRecurse) {
1133 return simplifyDiv(Instruction::SDiv, Op0, Op1, Q, MaxRecurse);
1143 unsigned MaxRecurse) {
1144 return simplifyDiv(Instruction::UDiv, Op0, Op1, Q, MaxRecurse);
1154 unsigned MaxRecurse) {
1165 return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
1175 unsigned MaxRecurse) {
1176 return simplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse);
1190 if (isa<UndefValue>(C))
1195 if (CI->getValue().getLimitedValue() >=
1196 CI->getType()->getScalarSizeInBits())
1200 if (isa<ConstantVector>(C) || isa<ConstantDataVector>(
C)) {
1235 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1241 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1264 unsigned MaxRecurse) {
1280 if (Op0Known.
One[0])
1338 const APInt *ShRAmt, *ShLAmt;
1341 *ShRAmt == *ShLAmt) {
1345 if (ShRAmt->
uge(EffWidthY))
1391 ICmpInst *UnsignedICmp,
bool IsAnd) {
1403 else if (
match(UnsignedICmp,
1413 return IsAnd ? UnsignedICmp : ZeroICmp;
1420 return UnsignedICmp;
1491 const APInt *C0, *C1;
1501 if (IsAnd && Range0.intersectWith(Range1).isEmptySet())
1506 if (!IsAnd && Range0.unionWith(Range1).isFullSet())
1514 if (Range0.contains(Range1))
1515 return IsAnd ? Cmp1 : Cmp0;
1516 if (Range1.contains(Range0))
1517 return IsAnd ? Cmp0 : Cmp1;
1563 const APInt *C0, *C1;
1571 auto *AddInst = cast<OverflowingBinaryOperator>(Op0->
getOperand(0));
1572 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1579 const APInt Delta = *C1 - *C0;
1580 if (C0->isStrictlyPositive()) {
1594 if (C0->getBoolValue() && isNUW) {
1636 const APInt *C0, *C1;
1644 auto *AddInst = cast<BinaryOperator>(Op0->
getOperand(0));
1645 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1652 const APInt Delta = *C1 - *C0;
1653 if (C0->isStrictlyPositive()) {
1667 if (C0->getBoolValue() && isNUW) {
1748 if (Cast0 && Cast1 && Cast0->getOpcode() == Cast1->getOpcode() &&
1749 Cast0->getSrcTy() == Cast1->getSrcTy()) {
1750 Op0 = Cast0->getOperand(0);
1751 Op1 = Cast1->getOperand(0);
1773 if (
auto *
C = dyn_cast<Constant>(V))
1782 unsigned MaxRecurse) {
1823 (~(*Mask)).lshr(*ShAmt).isNullValue())
1829 (~(*Mask)).shl(*ShAmt).isNullValue())
1864 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1871 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1895 if (EffWidthY <= ShftCnt) {
1920 unsigned MaxRecurse) {
2009 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
2015 const APInt *C1, *C2;
2042 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2056 unsigned MaxRecurse) {
2115 if (Pred == Cmp->
getPredicate() && LHS == CmpLHS && RHS == CmpRHS)
2118 LHS == CmpRHS && RHS == CmpLHS)
2163 isa<ConstantPointerNull>(RHS) &&
2235 if (isa<AllocaInst>(LHS) &&
2236 (isa<AllocaInst>(RHS) || isa<GlobalVariable>(RHS))) {
2239 uint64_t LHSSize, RHSSize;
2243 if (LHSOffsetCI && RHSOffsetCI &&
2247 const APInt &RHSOffsetValue = RHSOffsetCI->getValue();
2250 LHSOffsetValue.
ult(LHSSize) &&
2251 RHSOffsetValue.
ult(RHSSize)) {
2259 if (!cast<PointerType>(LHS->
getType())->isEmptyTy() &&
2260 !cast<PointerType>(RHS->
getType())->isEmptyTy() &&
2300 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2301 return AI->getParent() && AI->getFunction() && AI->isStaticAlloca();
2302 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
2303 return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
2304 GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
2305 !GV->isThreadLocal();
2306 if (
const Argument *
A = dyn_cast<Argument>(V))
2307 return A->hasByValAttr();
2312 if ((IsNAC(LHSUObjs) && IsAllocDisjoint(RHSUObjs)) ||
2313 (IsNAC(RHSUObjs) && IsAllocDisjoint(LHSUObjs)))
2489 }
else if (IIQ.
hasNoSignedWrap(cast<OverflowingBinaryOperator>(&BO))) {
2503 case Instruction::And:
2509 case Instruction::Or:
2515 case Instruction::AShr:
2521 unsigned ShiftAmount = Width - 1;
2527 Upper = C->
ashr(ShiftAmount) + 1;
2530 Lower = C->
ashr(ShiftAmount);
2536 case Instruction::LShr:
2542 unsigned ShiftAmount = Width - 1;
2545 Lower = C->
lshr(ShiftAmount);
2550 case Instruction::Shl:
2560 Lower = C->
shl(ShiftAmount);
2566 Upper = C->
shl(ShiftAmount) + 1;
2572 case Instruction::SDiv:
2584 Lower = IntMin.
sdiv(*C);
2585 Upper = IntMax.
sdiv(*C);
2586 if (Lower.
sgt(Upper))
2589 assert(Upper != Lower &&
"Upper part of range has wrapped!");
2595 Upper = Lower.
lshr(1) + 1;
2598 Upper = C->
abs() + 1;
2599 Lower = (-Upper) + 1;
2604 case Instruction::UDiv:
2614 case Instruction::SRem:
2618 Lower = (-Upper) + 1;
2622 case Instruction::URem:
2728 if (
auto *BO = dyn_cast<BinaryOperator>(LHS))
2730 else if (
auto *II = dyn_cast<IntrinsicInst>(LHS))
2734 Lower != Upper ?
ConstantRange(Lower, Upper) : ConstantRange(Width,
true);
2736 if (
auto *
I = dyn_cast<Instruction>(LHS))
2755 unsigned MaxRecurse) {
2760 if (MaxRecurse && (LBO || RBO)) {
2762 Value *
A =
nullptr, *
B =
nullptr, *
C =
nullptr, *
D =
nullptr;
2764 bool NoLHSWrapProblem =
false, NoRHSWrapProblem =
false;
2777 D = RBO->getOperand(1);
2787 if ((A == RHS ||
B == RHS) && NoLHSWrapProblem)
2794 if ((
C == LHS ||
D == LHS) && NoRHSWrapProblem)
2797 C == LHS ?
D :
C, Q, MaxRecurse - 1))
2801 if (A && C && (A == C || A ==
D ||
B == C ||
B ==
D) && NoLHSWrapProblem &&
2809 }
else if (A ==
D) {
2813 }
else if (
B == C) {
2881 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
2882 if (RHSC->getValue().isStrictlyPositive()) {
2892 if (RHSC->getValue().isNonNegative()) {
2988 if (
auto *CI = dyn_cast<ConstantInt>(RHS)) {
2989 const APInt *CI2Val, *CIVal = &CI->getValue();
3019 if (MaxRecurse && LBO && RBO && LBO->
getOpcode() == RBO->getOpcode() &&
3024 case Instruction::UDiv:
3025 case Instruction::LShr:
3030 RBO->getOperand(0), Q, MaxRecurse - 1))
3033 case Instruction::SDiv:
3038 RBO->getOperand(0), Q, MaxRecurse - 1))
3041 case Instruction::AShr:
3045 RBO->getOperand(0), Q, MaxRecurse - 1))
3048 case Instruction::Shl: {
3056 RBO->getOperand(0), Q, MaxRecurse - 1))
3079 cast<Instruction>(SP1)->hasNoSignedWrap())
3095 if (AbsRange.intersectWith(CmpRange).isEmptySet())
3107 unsigned MaxRecurse) {
3121 (A == LHS || B == LHS)) {
3128 (A == RHS || B == RHS)) {
3136 (A == LHS || B == LHS)) {
3195 (A == LHS || B == LHS)) {
3202 (A == RHS || B == RHS)) {
3210 (A == LHS || B == LHS)) {
3264 (A == C || A == D || B == C || B == D)) {
3274 (A == C || A == D || B == C || B == D)) {
3284 (A == C || A == D || B == C || B == D)) {
3294 (A == C || A == D || B == C || B == D)) {
3314 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
3315 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
3327 if (LHS == RHS || isa<UndefValue>(RHS))
3341 if (isa<Instruction>(RHS) && isa<Instruction>(LHS)) {
3342 auto RHS_Instr = cast<Instruction>(RHS);
3343 auto LHS_Instr = cast<Instruction>(LHS);
3353 if (Satisfied_CR.contains(LHS_CR))
3358 if (InversedSatisfied_CR.contains(LHS_CR))
3364 if (isa<CastInst>(LHS) && (isa<Constant>(RHS) || isa<CastInst>(RHS))) {
3367 Type *SrcTy = SrcOp->getType();
3372 if (MaxRecurse && isa<PtrToIntInst>(LI) &&
3374 if (
Constant *RHSC = dyn_cast<Constant>(RHS)) {
3380 }
else if (
PtrToIntInst *RI = dyn_cast<PtrToIntInst>(RHS)) {
3381 if (RI->getOperand(0)->getType() == SrcTy)
3389 if (isa<ZExtInst>(LHS)) {
3392 if (
ZExtInst *RI = dyn_cast<ZExtInst>(RHS)) {
3393 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
3396 SrcOp, RI->getOperand(0), Q,
3402 else if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
3410 if (RExt == CI && MaxRecurse)
3412 SrcOp, Trunc, Q, MaxRecurse-1))
3435 return CI->getValue().isNegative() ?
3441 return CI->getValue().isNegative() ?
3449 if (isa<SExtInst>(LHS)) {
3452 if (
SExtInst *RI = dyn_cast<SExtInst>(RHS)) {
3453 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
3461 else if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
3469 if (RExt == CI && MaxRecurse)
3487 return CI->getValue().isNegative() ?
3492 return CI->getValue().isNegative() ?
3543 if (
auto *CLHS = dyn_cast<PtrToIntOperator>(LHS))
3544 if (
auto *CRHS = dyn_cast<PtrToIntOperator>(RHS))
3550 Q.
IIQ, CLHS->getPointerOperand(),
3551 CRHS->getPointerOperand()))
3555 if (
GEPOperator *GRHS = dyn_cast<GEPOperator>(RHS)) {
3556 if (GLHS->getPointerOperand() == GRHS->getPointerOperand() &&
3557 GLHS->hasAllConstantIndices() && GRHS->hasAllConstantIndices() &&
3559 (GLHS->isInBounds() && GRHS->isInBounds() &&
3567 GLHS->getSourceElementType(), Null, IndicesLHS);
3571 GLHS->getSourceElementType(), Null, IndicesRHS);
3579 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3585 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3601 unsigned MaxRecurse) {
3605 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
3606 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
3629 "Comparison must be either ordered or unordered");
3635 if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS)) {
3700 assert(!C->
isNaN() &&
"Unexpected NaN constant!");
3726 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3732 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3747 unsigned MaxRecurse) {
3753 if (isa<Constant>(Op))
3761 if (
auto *
B = dyn_cast<BinaryOperator>(
I)) {
3768 if (isa<OverflowingBinaryOperator>(
B))
3775 if (
B->getOperand(0) ==
Op)
3778 if (
B->getOperand(1) ==
Op)
3785 if (
CmpInst *
C = dyn_cast<CmpInst>(
I)) {
3797 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(
I)) {
3801 [&](
Value *V) {
return V == Op ? RepOp : V; });
3811 if (
Constant *CRepOp = dyn_cast<Constant>(RepOp)) {
3814 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i) {
3815 if (
I->getOperand(i) ==
Op)
3817 else if (
Constant *COp = dyn_cast<Constant>(
I->getOperand(i)))
3824 if (ConstOps.
size() ==
I->getNumOperands()) {
3827 ConstOps[1], Q.
DL, Q.
TLI);
3829 if (
LoadInst *LI = dyn_cast<LoadInst>(
I))
3830 if (!LI->isVolatile())
3843 const APInt *
Y,
bool TrueWhenUnset) {
3850 return TrueWhenUnset ? FalseVal : TrueVal;
3856 return TrueWhenUnset ? FalseVal : TrueVal;
3863 return TrueWhenUnset ? TrueVal : FalseVal;
3869 return TrueWhenUnset ? TrueVal : FalseVal;
3893 unsigned MaxRecurse) {
3895 Value *CmpLHS, *CmpRHS;
3919 if (
match(TrueVal, isFsh) && FalseVal == X && CmpLHS == ShAmt)
3926 if (
match(FalseVal, isFsh) && TrueVal == X && CmpLHS == ShAmt)
3997 if (
auto *CondC = dyn_cast<Constant>(Cond)) {
3998 if (
auto *TrueC = dyn_cast<Constant>(TrueVal))
3999 if (
auto *FalseC = dyn_cast<Constant>(FalseVal))
4003 if (isa<UndefValue>(CondC))
4004 return isa<Constant>(FalseVal) ? FalseVal : TrueVal;
4009 if (CondC->isAllOnesValue())
4012 if (CondC->isNullValue())
4017 if (TrueVal == FalseVal)
4020 if (isa<UndefValue>(TrueVal))
4022 if (isa<UndefValue>(FalseVal))
4037 return *Imp ? TrueVal : FalseVal;
4053 cast<PointerType>(Ops[0]->getType()->getScalarType())->getAddressSpace();
4056 if (Ops.
size() == 1)
4067 if (isa<UndefValue>(Ops[0]))
4070 if (Ops.
size() == 2) {
4072 if (
match(Ops[1],
m_Zero()) && Ops[0]->getType() == GEPTy)
4081 if (TyAllocSize == 0 && Ops[0]->
getType() == GEPTy)
4088 auto PtrToIntOrZero = [GEPTy](
Value *
P) ->
Value * {
4099 if (TyAllocSize == 1 &&
4101 if (
Value *
R = PtrToIntOrZero(P))
4109 TyAllocSize == 1ULL <<
C)
4110 if (
Value *
R = PtrToIntOrZero(P))
4118 if (
Value *
R = PtrToIntOrZero(P))
4130 APInt BasePtrOffset(IdxWidth, 0);
4131 Value *StrippedBasePtr =
4132 Ops[0]->stripAndAccumulateInBoundsConstantOffsets(Q.
DL,
4151 if (!
all_of(Ops, [](
Value *V) {
return isa<Constant>(V); }))
4171 if (
Constant *CAgg = dyn_cast<Constant>(Agg))
4172 if (
Constant *CVal = dyn_cast<Constant>(Val))
4181 if (EV->getAggregateOperand()->getType() == Agg->
getType() &&
4182 EV->getIndices() == Idxs) {
4185 return EV->getAggregateOperand();
4188 if (Agg == EV->getAggregateOperand())
4207 if (VecC && ValC && IdxC)
4211 if (
auto *CI = dyn_cast<ConstantInt>(Idx)) {
4212 uint64_t NumElements = cast<VectorType>(Vec->
getType())->getNumElements();
4213 if (CI->uge(NumElements))
4218 if (isa<UndefValue>(Idx))
4228 if (
auto *CAgg = dyn_cast<Constant>(Agg))
4232 unsigned NumIdxs = Idxs.
size();
4233 for (
auto *IVI = dyn_cast<InsertValueInst>(Agg); IVI !=
nullptr;
4236 unsigned NumInsertValueIdxs = InsertValueIdxs.
size();
4237 unsigned NumCommonIdxs = std::min(NumInsertValueIdxs, NumIdxs);
4238 if (InsertValueIdxs.
slice(0, NumCommonIdxs) ==
4239 Idxs.
slice(0, NumCommonIdxs)) {
4240 if (NumIdxs == NumInsertValueIdxs)
4241 return IVI->getInsertedValueOperand();
4258 if (
auto *CVec = dyn_cast<Constant>(Vec)) {
4259 if (
auto *CIdx = dyn_cast<Constant>(Idx))
4263 if (
auto *Splat = CVec->getSplatValue())
4266 if (isa<UndefValue>(Vec))
4272 if (
auto *IdxC = dyn_cast<ConstantInt>(Idx)) {
4282 if (isa<UndefValue>(Idx))
4297 Value *CommonValue =
nullptr;
4298 bool HasUndefInput =
false;
4301 if (Incoming == PN)
continue;
4302 if (isa<UndefValue>(Incoming)) {
4304 HasUndefInput =
true;
4307 if (CommonValue && Incoming != CommonValue)
4309 CommonValue = Incoming;
4328 if (
auto *
C = dyn_cast<Constant>(Op))
4331 if (
auto *CI = dyn_cast<CastInst>(Op)) {
4332 auto *Src = CI->getOperand(0);
4333 Type *SrcTy = Src->getType();
4334 Type *MidTy = CI->getType();
4336 if (Src->getType() == Ty) {
4346 SrcIntPtrTy, MidIntPtrTy,
4347 DstIntPtrTy) == Instruction::BitCast)
4353 if (CastOpc == Instruction::BitCast)
4369 int MaskVal,
Value *RootVec,
4370 unsigned MaxRecurse) {
4381 int RootElt = MaskVal;
4382 Value *SourceOp = Op0;
4383 if (MaskVal >= InVecNumElts) {
4384 RootElt = MaskVal - InVecNumElts;
4390 if (
auto *SourceShuf = dyn_cast<ShuffleVectorInst>(SourceOp)) {
4392 DestElt, SourceShuf->getOperand(0), SourceShuf->getOperand(1),
4393 SourceShuf->getMaskValue(RootElt), RootVec, MaxRecurse);
4405 if (RootVec != SourceOp)
4410 if (RootElt != DestElt)
4418 unsigned MaxRecurse) {
4419 if (isa<UndefValue>(Mask))
4429 "Size of Indices not same as number of mask elements?");
4433 bool MaskSelects0 =
false, MaskSelects1 =
false;
4434 for (
unsigned i = 0; i != MaskNumElts; ++i) {
4435 if (Indices[i] == -1)
4437 if ((
unsigned)Indices[i] < InVecNumElts)
4438 MaskSelects0 =
true;
4440 MaskSelects1 =
true;
4451 if (Op0Const && Op1Const)
4456 if (Op0Const && !Op1Const) {
4463 if (
auto *OpShuf = dyn_cast<ShuffleVectorInst>(Op0))
4464 if (isa<UndefValue>(Op1) && RetTy == InVecTy &&
4465 OpShuf->getMask()->getSplatValue())
4471 if (
find(Indices, -1) != Indices.
end())
4478 Value *RootVec =
nullptr;
4479 for (
unsigned i = 0; i != MaskNumElts; ++i) {
4486 if (!RootVec || RootVec->
getType() != RetTy)
4509 if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
4592 if (FMF.
noNaNs() && Op0 == Op1)
4627 if (Op0 == Op1 &&
match(Op0, m_Intrinsic<Intrinsic::sqrt>(
m_Value(X))) &&
4732 case Instruction::Sub:
4734 case Instruction::Mul:
4736 case Instruction::SDiv:
4738 case Instruction::UDiv:
4740 case Instruction::SRem:
4742 case Instruction::URem:
4744 case Instruction::Shl:
4746 case Instruction::LShr:
4748 case Instruction::AShr:
4750 case Instruction::And:
4752 case Instruction::Or:
4754 case Instruction::Xor:
4756 case Instruction::FAdd:
4758 case Instruction::FSub:
4760 case Instruction::FMul:
4762 case Instruction::FDiv:
4764 case Instruction::FRem:
4777 unsigned MaxRecurse) {
4779 case Instruction::FAdd:
4781 case Instruction::FSub:
4783 case Instruction::FMul:
4785 case Instruction::FDiv:
4817 default:
return false;
4845 if (!OffsetConstInt || OffsetConstInt->getType()->getBitWidth() > 64)
4849 if (OffsetInt % 4 != 0)
4863 if (LoadedCE->getOpcode() == Instruction::Trunc) {
4869 if (LoadedCE->getOpcode() != Instruction::Sub)
4873 if (!LoadedLHS || LoadedLHS->getOpcode() != Instruction::PtrToInt)
4875 auto *LoadedLHSPtr = LoadedLHS->
getOperand(0);
4879 APInt LoadedRHSOffset;
4882 PtrSym != LoadedRHSSym || PtrOffset != LoadedRHSOffset)
4892 if (ConstMask->isNullValue() || isa<UndefValue>(ConstMask))
4894 for (
unsigned I = 0,
E = ConstMask->getType()->getVectorNumElements();
I !=
E;
4896 if (
auto *MaskElt = ConstMask->getAggregateElement(
I))
4897 if (MaskElt->isNullValue() || isa<UndefValue>(MaskElt))
4909 if (
auto *II = dyn_cast<IntrinsicInst>(Op0))
4910 if (II->getIntrinsicID() == IID)
4929 match(Op0, m_Intrinsic<Intrinsic::log>(
m_Value(X))))
return X;
4934 match(Op0, m_Intrinsic<Intrinsic::log2>(
m_Value(X))))
return X;
4939 match(Op0, m_Intrinsic<Intrinsic::exp>(
m_Value(X))))
return X;
4944 match(Op0, m_Intrinsic<Intrinsic::exp2>(
m_Value(X))))
return X;
4965 if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
4971 if (isa<UndefValue>(Op0) || isa<UndefValue>(Op1))
5020 if (
auto *C0 = dyn_cast<Constant>(Op0))
5021 if (
auto *C1 = dyn_cast<Constant>(Op1))
5025 if (
auto *Power = dyn_cast<ConstantInt>(Op1)) {
5027 if (Power->isZero())
5039 if (Op0 == Op1)
return Op0;
5050 return PropagateNaN ? Op0 : Op1;
5052 return PropagateNaN ? Op1 : Op0;
5056 if (
auto *M0 = dyn_cast<IntrinsicInst>(Op0))
5057 if (M0->getIntrinsicID() == IID &&
5058 (M0->getOperand(0) == Op1 || M0->getOperand(1) == Op1))
5060 if (
auto *M1 = dyn_cast<IntrinsicInst>(Op1))
5061 if (M1->getIntrinsicID() == IID &&
5062 (M1->getOperand(0) == Op0 || M1->getOperand(1) == Op0))
5088 template <
typename IterTy>
5092 unsigned NumOperands = std::distance(ArgBegin, ArgEnd);
5093 if (NumOperands == 0)
5097 if (NumOperands == 1)
5100 if (NumOperands == 2)
5106 Value *MaskArg = ArgBegin[2];
5107 Value *PassthruArg = ArgBegin[3];
5115 Value *Op0 = ArgBegin[0], *Op1 = ArgBegin[1], *ShAmtArg = ArgBegin[2];
5125 const APInt *ShAmtC;
5140 template <
typename IterTy>
5143 unsigned MaxRecurse) {
5146 Ty = PTy->getElementType();
5151 if (isa<UndefValue>(V) || isa<ConstantPointerNull>(V))
5158 if (F->isIntrinsic())
5166 ConstantArgs.
reserve(ArgEnd - ArgBegin);
5167 for (IterTy
I = ArgBegin,
E = ArgEnd;
I !=
E; ++
I) {
5206 case Instruction::FAdd:
5216 case Instruction::FSub:
5220 case Instruction::Sub:
5226 case Instruction::FMul:
5230 case Instruction::Mul:
5233 case Instruction::SDiv:
5236 case Instruction::UDiv:
5239 case Instruction::FDiv:
5243 case Instruction::SRem:
5246 case Instruction::URem:
5249 case Instruction::FRem:
5253 case Instruction::Shl:
5259 case Instruction::LShr:
5263 case Instruction::AShr:
5267 case Instruction::And:
5270 case Instruction::Or:
5273 case Instruction::Xor:
5276 case Instruction::ICmp:
5280 case Instruction::FCmp:
5289 case Instruction::GetElementPtr: {
5291 Result =
SimplifyGEPInst(cast<GetElementPtrInst>(I)->getSourceElementType(),
5295 case Instruction::InsertValue: {
5302 case Instruction::InsertElement: {
5303 auto *
IE = cast<InsertElementInst>(
I);
5305 IE->getOperand(2), Q);
5308 case Instruction::ExtractValue: {
5309 auto *EVI = cast<ExtractValueInst>(
I);
5311 EVI->getIndices(), Q);
5314 case Instruction::ExtractElement: {
5315 auto *EEI = cast<ExtractElementInst>(
I);
5317 EEI->getIndexOperand(), Q);
5320 case Instruction::ShuffleVector: {
5321 auto *SVI = cast<ShuffleVectorInst>(
I);
5323 SVI->getMask(), SVI->getType(), Q);
5326 case Instruction::PHI:
5334 #define HANDLE_CAST_INST(num, opc, clas) case Instruction::opc: 5335 #include "llvm/IR/Instruction.def" 5336 #undef HANDLE_CAST_INST 5340 case Instruction::Alloca:
5384 Worklist.
insert(cast<Instruction>(U));
5399 for (
unsigned Idx = 0; Idx != Worklist.
size(); ++Idx) {
5413 Worklist.
insert(cast<Instruction>(U));
5438 assert(I != SimpleV &&
"replaceAndRecursivelySimplify(X,X) is not valid!");
5439 assert(SimpleV &&
"Must provide a simplified value.");
5446 auto *DT = DTWP ? &DTWP->
getDomTree() :
nullptr;
5448 auto *TLI = TLIWP ? &TLIWP->
getTLI() :
nullptr;
5456 return {DL, &AR.
TLI, &AR.
DT, &AR.
AC};
5459 template <
class T,
class... TArgs>
5462 auto *DT = AM.template getCachedResult<DominatorTreeAnalysis>(
F);
5463 auto *TLI = AM.template getCachedResult<TargetLibraryAnalysis>(
F);
5464 auto *AC = AM.template getCachedResult<AssumptionAnalysis>(
F);
Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
static Value * SimplifyURemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for a URem, see if we can fold the result.
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
APInt abs() const
Get the absolute value;.
Pass interface - Implemented by all 'passes'.
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Compute the size of the object pointed by Ptr.
bool isFPPredicate() const
Type * getVectorElementType() const
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
Value * SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an ICmpInst, fold the result or return null.
static Value * SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an AShr, see if we can fold the result.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This class is the base class for the comparison instructions.
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static Value * SimplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an SRem, see if we can fold the result.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
static Value * SimplifyMulInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for a Mul, see if we can fold the result.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
This class represents an incoming formal argument to a Function.
const T & back() const
back - Get the last element.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Value * getAggregateOperand()
bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
static void setLimitsForIntrinsic(IntrinsicInst &II, APInt &Lower, APInt &Upper)
Some intrinsics with a constant operand have an easy-to-compute range of outputs. ...
Value * SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FCmpInst, fold the result or return null.
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 Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register...
This class represents lattice values for constants.
SimplifyQuery getWithInstruction(Instruction *I) const
BinaryOps getOpcode() const
static Value * SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for a SelectInst, see if we can fold the result.
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.
size_type size() const
Determine the number of elements in the SetVector.
static Constant * propagateNaN(Constant *In)
static Value * SimplifyCastInst(unsigned, Value *, Type *, const SimplifyQuery &, unsigned)
static Value * SimplifyRightShift(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an Shl, LShr or AShr, see if we can fold the result.
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static Constant * getInfinity(Type *Ty, bool Negative=false)
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...
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
bool decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate &Pred, Value *&X, APInt &Mask, bool LookThroughTrunc=true)
Decompose an icmp into the form ((X & Mask) pred 0) if possible.
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
BinaryOp_match< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
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.
This class represents zero extension of integer types.
void push_back(const T &Elt)
static Value * SimplifyCall(ImmutableCallSite CS, Value *V, IterTy ArgBegin, IterTy ArgEnd, const SimplifyQuery &Q, unsigned MaxRecurse)
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated...
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices...
constexpr T getValueOr(U &&value) const LLVM_LVALUE_FUNCTION
APInt udiv(const APInt &RHS) const
Unsigned division operation.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
static Value * simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp, ICmpInst *UnsignedICmp, bool IsAnd)
Commuted variants are assumed to be handled by calling this function again with the parameters swappe...
An immutable pass that tracks lazily created AssumptionCache objects.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
static Value * SimplifyGEPInst(Type *, ArrayRef< Value *>, const SimplifyQuery &, unsigned)
Given operands for an GetElementPtrInst, see if we can fold the result.
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
const Value * getTrueValue() const
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A cache of @llvm.assume calls within a function.
0 1 0 0 True if ordered and less than
bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &DL)
If this constant is a constant offset from a global, return the global and the constant.
LLVMContext & getContext() const
All values hold a context through their type.
bool isTerminator() const
1 1 1 0 True if unordered or not equal
Value * SimplifySDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SDiv, fold the result or return null.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
static Value * SimplifyShift(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an Shl, LShr or AShr, see if we can fold the result.
static Value * simplifyICmpWithMinMax(CmpInst::Predicate 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 bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Value * SimplifyUDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a UDiv, fold the result or return null.
STATISTIC(NumFunctions, "Total number of functions")
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
This class represents a sign extension of integer types.
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
Value * SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for a Shl, fold the result or return null.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
An instruction for reading from memory.
static IntegerType * getInt64Ty(LLVMContext &C)
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 Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool isVectorTy() const
True if this is an instance of VectorType.
static Value * simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
Try to simplify a select instruction when its condition operand is an integer comparison.
const SimplifyQuery getBestSimplifyQuery(Pass &, Function &)
void reserve(size_type N)
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
unsigned getBitWidth() const
Get the bit width of this value.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
const TargetLibraryInfo * TLI
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT)
Does the given value dominate the specified phi node?
Value * SimplifyOrInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Or, fold the result or return null.
static Value * SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an LShr, see if we can fold the result.
static Value * simplifyAndOfICmpsWithSameOperands(ICmpInst *Op0, ICmpInst *Op1)
Commuted variants are assumed to be handled by calling this function again with the parameters swappe...
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Value * SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q)
Given operands for a LShr, fold the result or return null.
Value * SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FP BinaryOperator, fold the result or return null.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
bool match(Val *V, const Pattern &P)
Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an ExtractValueInst, fold the result or return null.
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
CmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R)
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
static Value * SimplifyXorInst(Value *, Value *, const SimplifyQuery &, unsigned)
Given operands for a Xor, see if we can fold the result.
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined. ...
This class represents the LLVM 'select' instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
static Value * simplifyICmpWithBinOp(CmpInst::Predicate 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 * SimplifyFPBinOp(unsigned, Value *, Value *, const FastMathFlags &, const SimplifyQuery &, unsigned)
Given operands for a BinaryOperator, see if we can fold the result.
TargetLibraryInfo & getTLI()
static Constant * getNegativeZero(Type *Ty)
APInt shl(unsigned shiftAmt) const
Left-shift function.
Exact_match< T > m_Exact(const T &SubPattern)
Value * SimplifyGEPInst(Type *SrcTy, ArrayRef< Value *> Ops, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
A Use represents the edge between a Value definition and its users.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
static Value * simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
static Value * simplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd, const SimplifyQuery &Q)
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
static bool isImpliedTrueByMatchingCmp(Predicate Pred1, Predicate Pred2)
Determine if Pred1 implies Pred2 is true when two compares have matching operands.
static Value * simplifySelectWithFCmp(Value *Cond, Value *T, Value *F)
Try to simplify a select instruction when its condition operand is a floating-point comparison...
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.
0 1 0 1 True if ordered and less than or equal
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if 'V & Mask' is known to be zero.
InstrTy * getInstruction() const
bool hasNoUnsignedWrap(const InstT *Op) const
static Value * SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an FSub, see if we can fold the result.
DominatorTree & getDomTree()
static Value * SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an Shl, see if we can fold the result.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
static Value * SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an FCmpInst, see if we can fold the result.
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...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
This class represents a cast from a pointer to an integer.
static Constant * foldOrCommuteConstant(Instruction::BinaryOps Opcode, Value *&Op0, Value *&Op1, const SimplifyQuery &Q)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
static bool isICmpTrue(ICmpInst::Predicate 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 * SimplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned)
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Class to represent function types.
A constant value that is initialized with an expression using other constant values.
Value * SimplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FAdd, fold the result or return null.
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
static Value * SimplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned)
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a CmpInst, fold the result or return null.
Type * getType() const
All values are typed, get the type of this value.
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
bool insert(const value_type &X)
Insert a new element into the SetVector.
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
static Value * ExtractEquivalentCondition(Value *V, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
Rummage around inside V looking for something equivalent to the comparison "LHS Pred RHS"...
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
This instruction compares its operands according to the predicate given to the constructor.
Value * SimplifyMulInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a Mul, fold the result or return null.
static Value * SimplifyRelativeLoad(Constant *Ptr, Constant *Offset, const DataLayout &DL)
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
This header provides classes for managing per-loop analyses.
static bool maskIsAllZeroOrUndef(Value *Mask)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Value * getInsertedValueOperand()
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
static Value * ExpandBinOp(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, Instruction::BinaryOps OpcodeToExpand, const SimplifyQuery &Q, unsigned MaxRecurse)
Simplify "A op (B op' C)" by distributing op over op', turning it into "(A op B) op' (A op C)"...
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static Value * SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an ICmpInst, see if we can fold the result.
static Function * getFunction(Constant *C)
bool isExact(const BinaryOperator *Op) const
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
static Value * simplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
These are simplifications common to SDiv and UDiv.
The operation itself must be expressed in terms of simpler actions on this target.
Value * getOperand(unsigned i) const
static Value * SimplifyAndInst(Value *, Value *, const SimplifyQuery &, unsigned)
Given operands for an And, see if we can fold the result.
Class to represent pointers.
static ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the largest range such that all values in the returned range satisfy the given predicate with...
bool CannotBeNegativeZero(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if we can prove that the specified FP value is never equal to -0.0.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
bool isNegative() const
Returns true if this value is known to be negative.
static Value * SimplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
Given the operands for an FMul, see if we can fold the result.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * SimplifyInsertElementInst(Value *Vec, Value *Elt, Value *Idx, const SimplifyQuery &Q)
Given operands for an InsertElement, fold the result or return null.
static Value * SimplifyCmpInst(unsigned, Value *, Value *, const SimplifyQuery &, unsigned)
Given operands for a CmpInst, see if we can fold the result.
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
MDNode * getMetadata(const Instruction *I, unsigned KindID) const
static Value * SimplifyUDivInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for a UDiv, see if we can fold the result.
bool isNegative() const
Determine sign of this APInt.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and indices...
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Type * getReturnType() const
Returns the type of the ret val.
Value * SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q)
Given operands for a SelectInst, fold the result or return null.
bool isAllOnesValue() const
Determine if all bits are set.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
static Value * SimplifySDivInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an SDiv, see if we can fold the result.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
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.
bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW=false)
Return true if the two given values are negation.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
Value * SimplifyURemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a URem, fold the result or return null.
static Value * simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, const SimplifyQuery &Q)
static Constant * stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V, bool AllowNonInbounds=false)
Compute the base pointer and cumulative constant offsets for V.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
size_t size() const
size - Get the array size.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
const APInt & getConstant() const
Returns the value when all bits have a known value.
bool isPointerTy() const
True if this is an instance of PointerType.
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.
static Value * ThreadCmpOverSelect(CmpInst::Predicate 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...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isMask(unsigned numBits) const
bool isOneValue() const
Determine if this is a value of 1.
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
static void setLimitsForBinOp(BinaryOperator &BO, APInt &Lower, APInt &Upper, const InstrInfoQuery &IIQ)
Many binary operators with a constant operand have an easy-to-compute range of outputs.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
InstrInfoQuery provides an interface to query additional information for instructions like metadata o...
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Value * SimplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
static Value * ThreadCmpOverPHI(CmpInst::Predicate 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 ...
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for an Add, fold the result or return null.
bool isAssociative() const LLVM_READONLY
Return true if the instruction is associative:
bool isMinSignedValue() const
Determine if this is the smallest signed value.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool isConstant() const
Returns true if we know the value of all bits.
This instruction compares its operands according to the predicate given to the constructor.
Value * SimplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FDiv, fold the result or return null.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
0 1 1 1 True if ordered (no nans)
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
const Function * getFunction() const
Return the function this instruction belongs to.
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
static Value * simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const InstrInfoQuery &IIQ)
const Value * getCondition() const
static Constant * getAllOnesValue(Type *Ty)
1 1 1 1 Always true (always folded)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
static Value * simplifyAndOrOfICmpsWithZero(ICmpInst *Cmp0, ICmpInst *Cmp1, 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 UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
static wasm::ValType getType(const TargetRegisterClass *RC)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static Constant * simplifyFPBinop(Value *Op0, Value *Op1)
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCompareInstOperands - Attempt to constant fold a compare instruction (icmp/fcmp) with the...
1 1 0 1 True if unordered, less than, or equal
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Value * SimplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FRem, fold the result or return null.
Value * SimplifyShuffleVectorInst(Value *Op0, Value *Op1, Constant *Mask, Type *RetTy, const SimplifyQuery &Q)
Given operands for a ShuffleVectorInst, fold the result or return null.
bool recursivelySimplifyInstruction(Instruction *I, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
Recursively attempt to simplify an instruction.
static Value * simplifyICmpWithAbsNabs(CmpInst::Predicate Pred, Value *Op0, Value *Op1)
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
bool isEmptySet() const
Return true if this set contains no members.
0 0 1 0 True if ordered and greater than
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
A SetVector that performs no allocations if smaller than a certain size.
static 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...
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.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
SelectPatternFlavor Flavor
static Value * simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
static Value * simplifyICmpOfBools(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Fold an icmp when its operands have i1 scalar type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
static Value * simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv)
Check for common or similar folds of integer division or integer remainder.
1 1 0 0 True if unordered or less than
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
SelectPatternFlavor
Specific patterns of select instructions we can match.
Provides information about what library functions are available for the current target.
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 * SimplifyOrInst(Value *, Value *, const SimplifyQuery &, unsigned)
Given operands for an Or, see if we can fold the result.
static Value * simplifyAndOrOfFCmps(const TargetLibraryInfo *TLI, FCmpInst *LHS, FCmpInst *RHS, bool IsAnd)
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
This class represents a range of values.
static Value * SimplifyBinOp(unsigned, Value *, Value *, const SimplifyQuery &, unsigned)
Given operands for a BinaryOperator, see if we can fold the result.
static Value * simplifyUnaryIntrinsic(Function *F, Value *Op0, const SimplifyQuery &Q)
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
Type * getReturnType() const
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine how a pair of casts can be eliminated, if they can be at all.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
CastClass_match< OpTy, Instruction::UIToFP > m_UIToFP(const OpTy &Op)
Matches UIToFP.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Value * SimplifyCall(ImmutableCallSite CS, const SimplifyQuery &Q)
Given a callsite, fold the result or return null.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
static ConstantInt * getTrue(LLVMContext &Context)
bool isCommutative() const
Return true if the instruction is commutative:
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
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...
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
bool isIntPredicate() const
bool isTrueWhenEqual() const
This is just a convenience.
Class to represent vector types.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
bool isFalseWhenEqual() const
This is just a convenience.
static Constant * getFalse(Type *Ty)
For a boolean type or a vector of boolean type, return false or a vector with every element false...
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
static Value * simplifyOrOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
Value * SimplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FSub, fold the result or return null.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
iterator_range< user_iterator > users()
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
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...
static Value * simplifyOrOfICmpsWithSameOperands(ICmpInst *Op0, ICmpInst *Op1)
Commuted variants are assumed to be handled by calling this function again with the parameters swappe...
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
const Value * getFalseValue() const
static Value * simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1, const InstrInfoQuery &IIQ)
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FMul, fold the result or return null.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
Value * SimplifyAndInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an And, fold the result or return null.
Predicate getPredicate() const
Return the predicate for this instruction.
static Value * SimplifyAssociativeBinOp(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
Generic simplifications for associative binary operations.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
static Constant * computePointerDifference(const DataLayout &DL, Value *LHS, Value *RHS)
Compute the constant difference between two pointer values.
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
static Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &, unsigned)
Given operands for an ExtractValueInst, see if we can fold the result.
static Type * getIndexedType(Type *Ty, ArrayRef< Value *> IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned greater or equal
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
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...
static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC)
Implementation of recursive simplification through an instruction's uses.
Establish a view to a call site for examination.
Value * SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, const SimplifyQuery &Q)
Given operands for a AShr, fold the result or return nulll.
static const Value * SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, unsigned MaxRecurse)
See if V simplifies when its operand Op is replaced with RepOp.
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given values are known to be non-equal when defined.
bool isEquality() const
Return true if this predicate is either EQ or NE.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
bool SignBitMustBeZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value's sign bit is 0.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices...
static Value * SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for a Sub, see if we can fold the result.
static void Query(const MachineInstr &MI, AliasAnalysis &AA, bool &Read, bool &Write, bool &Effects, bool &StackPointer)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static Value * SimplifyShuffleVectorInst(Value *Op0, Value *Op1, Constant *Mask, Type *RetTy, const SimplifyQuery &Q, unsigned MaxRecurse)
Constant * ConstantFoldInstOperands(Instruction *I, ArrayRef< Constant *> Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands...
Value * SimplifyXorInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Xor, fold the result or return null.
static bool IsIdempotent(Intrinsic::ID ID)
static Value * SimplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an Add, see if we can fold the result.
1 0 1 0 True if unordered or greater than
bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
Value * SimplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SRem, fold the result or return null.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
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.
void GetUnderlyingObjects(Value *V, SmallVectorImpl< Value *> &Objects, const DataLayout &DL, LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to GetUnderlyingObject except that it can look through phi and select instruct...
static Value * simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0, Value *Op1, bool IsAnd)
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Value * SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an FAdd, see if we can fold the result.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
static Constant * computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, CmpInst::Predicate Pred, AssumptionCache *AC, const Instruction *CxtI, const InstrInfoQuery &IIQ, Value *LHS, Value *RHS)
SmallVector< int, 16 > getShuffleMask() const
static Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &, unsigned)
Given operands for an ExtractElementInst, see if we can fold the result.
static Value * SimplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q, unsigned)
Given operands for an InsertValueInst, see if we can fold the result.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
ArrayRef< unsigned > getIndices() const
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...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
static Value * simplifyICmpWithZero(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Try hard to fold icmp with zero RHS because this is a common case.
1 0 1 1 True if unordered, greater than, or equal
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
bool hasAllowReassoc() const
Determine whether the allow-reassociation flag is set.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
static VectorType * get(Type *ElementType, unsigned NumElements)
This static method is the primary way to construct an VectorType.
bool canConstantFoldCallTo(ImmutableCallSite CS, const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &Q)
Given operands for an ExtractElementInst, fold the result or return null.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool allowReassoc() const
Flag queries.
static Value * SimplifyPHINode(PHINode *PN, const SimplifyQuery &Q)
See if we can fold the given phi. If not, returns null.
Value * SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for a Sub, fold the result or return null.
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
AssumptionCache & getAssumptionCache(Function &F)
Get the cached assumptions for a function.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
Value * SimplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an InsertValueInst, fold the result or return null.
Convenience struct for specifying and reasoning about fast-math flags.
Various options to control the behavior of getObjectSize.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
unsigned countLeadingOnes() const
Count the number of leading one bits.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
static bool isUndefShift(Value *Amount)
Returns true if a shift by Amount always yields undef.
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices...
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool CannotBeOrderedLessThanZero(const Value *V, const TargetLibraryInfo *TLI)
Return true if we can prove that the specified FP value is either NaN or never less than -0...
static APInt getNullValue(unsigned numBits)
Get the '0' value.
specific_intval m_SpecificInt(uint64_t V)
Match a specific integer value or vector with all elements equal to the value.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
static bool isSameCompare(Value *V, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
Replace all uses of 'I' with 'SimpleV' and simplify the uses recursively.
op_range incoming_values()
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
0 0 1 1 True if ordered and greater than or equal
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
bool hasNoSignedWrap(const InstT *Op) const
Constant * ConstantFoldCall(ImmutableCallSite CS, Function *F, ArrayRef< Constant *> Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
static Value * simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *CmpRHS, ICmpInst::Predicate Pred, Value *TrueVal, Value *FalseVal)
An alternative way to test if a bit is set or not uses sgt/slt instead of eq/ne.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static Value * simplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
These are simplifications common to SRem and URem.
static Type * GetCompareTy(Value *Op)
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
0 0 0 0 Always false (always folded)
bool isNullValue() const
Determine if all bits are clear.
static Value * foldSelectWithBinaryOp(Value *Cond, Value *TrueVal, Value *FalseVal)
A wrapper class for inspecting calls to intrinsic functions.
bool noSignedZeros() const
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.