43 using namespace llvm::PatternMatch;
45 #define DEBUG_TYPE "instsimplify"
49 STATISTIC(NumExpand,
"Number of expansions");
50 STATISTIC(NumReassoc,
"Number of reassociations");
86 if (CPred == Pred && CLHS == LHS && CRHS == RHS)
132 if (Op0->getOpcode() == OpcodeToExpand) {
134 Value *
A = Op0->getOperand(0), *
B = Op0->getOperand(1), *
C = RHS;
141 &&
L ==
B && R == A)) {
155 if (Op1->getOpcode() == OpcodeToExpand) {
157 Value *
A = LHS, *
B = Op1->getOperand(0), *
C = Op1->getOperand(1);
164 &&
L ==
C && R == B)) {
184 unsigned MaxRecurse) {
204 if (V == B)
return LHS;
214 if (Op1 && Op1->getOpcode() == Opcode) {
216 Value *
B = Op1->getOperand(0);
217 Value *
C = Op1->getOperand(1);
223 if (V == B)
return RHS;
246 if (V == A)
return LHS;
256 if (Op1 && Op1->getOpcode() == Opcode) {
258 Value *
B = Op1->getOperand(0);
259 Value *
C = Op1->getOperand(1);
265 if (V == C)
return RHS;
283 unsigned MaxRecurse) {
289 if (isa<SelectInst>(LHS)) {
290 SI = cast<SelectInst>(LHS);
292 assert(isa<SelectInst>(RHS) &&
"No select instruction operand!");
293 SI = cast<SelectInst>(RHS);
313 if (TV && isa<UndefValue>(TV))
315 if (FV && isa<UndefValue>(FV))
326 if ((FV && !TV) || (TV && !FV)) {
330 if (Simplified && Simplified->
getOpcode() == Opcode) {
335 Value *UnsimplifiedLHS = SI == LHS ? UnsimplifiedBranch : LHS;
336 Value *UnsimplifiedRHS = SI == LHS ? RHS : UnsimplifiedBranch;
337 if (Simplified->
getOperand(0) == UnsimplifiedLHS &&
341 Simplified->
getOperand(1) == UnsimplifiedLHS &&
355 unsigned MaxRecurse) {
361 if (!isa<SelectInst>(LHS)) {
365 assert(isa<SelectInst>(LHS) &&
"Not comparing with a select instruction!");
377 TCmp =
getTrue(Cond->getType());
383 TCmp =
getTrue(Cond->getType());
437 unsigned MaxRecurse) {
443 if (isa<PHINode>(LHS)) {
444 PI = cast<PHINode>(LHS);
449 assert(isa<PHINode>(RHS) &&
"No PHI instruction operand!");
450 PI = cast<PHINode>(RHS);
457 Value *CommonValue =
nullptr;
460 if (Incoming == PI)
continue;
461 Value *V = PI == LHS ?
466 if (!V || (CommonValue && V != CommonValue))
485 if (!isa<PHINode>(LHS)) {
489 assert(isa<PHINode>(LHS) &&
"Not comparing with a phi instruction!");
490 PHINode *PI = cast<PHINode>(LHS);
497 Value *CommonValue =
nullptr;
500 if (Incoming == PI)
continue;
504 if (!V || (CommonValue && V != CommonValue))
515 if (
auto *CLHS = dyn_cast<Constant>(Op0)) {
516 if (
auto *CRHS = dyn_cast<Constant>(Op1))
600 bool AllowNonInbounds =
false) {
612 if ((!AllowNonInbounds && !
GEP->isInBounds()) ||
613 !
GEP->accumulateConstantOffset(DL, Offset))
615 V =
GEP->getPointerOperand();
617 V = cast<Operator>(V)->getOperand(0);
618 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
619 if (GA->isInterposable())
621 V = GA->getAliasee();
624 if (
Value *RV = CS.getReturnedArgOperand()) {
631 }
while (Visited.insert(V).second);
699 Value *
X =
nullptr, *
Y =
nullptr, *
Z = Op1;
813 Value *SubOp =
nullptr;
855 if (FMF.
noNaNs() && Op0 == Op1)
881 unsigned MaxRecurse) {
920 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
927 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
974 for (
unsigned i = 0; i != NumElts; ++i) {
1016 bool isSigned = Opcode == Instruction::SDiv;
1019 Value *
X =
nullptr, *
Y =
nullptr;
1029 if (Div->getOpcode() == Opcode && Div->getOperand(1) ==
Y)
1050 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1056 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1066 unsigned MaxRecurse) {
1080 unsigned MaxRecurse) {
1088 if (
C->isAllOnesValue()) {
1158 if ((Opcode == Instruction::SRem &&
1160 (Opcode == Instruction::URem &&
1166 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1172 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1182 unsigned MaxRecurse) {
1196 unsigned MaxRecurse) {
1204 if (
C->isAllOnesValue()) {
1251 if (isa<UndefValue>(C))
1256 if (CI->getValue().getLimitedValue() >=
1257 CI->getType()->getScalarSizeInBits())
1261 if (isa<ConstantVector>(C) || isa<ConstantDataVector>(
C)) {
1292 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1298 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1321 unsigned MaxRecurse) {
1337 if (Op0Known.
One[0])
1422 ICmpInst *UnsignedICmp,
bool IsAnd) {
1434 else if (
match(UnsignedICmp,
1444 return IsAnd ? UnsignedICmp : ZeroICmp;
1451 return UnsignedICmp;
1522 const APInt *C0, *C1;
1532 if (IsAnd && Range0.intersectWith(Range1).isEmptySet())
1537 if (!IsAnd && Range0.unionWith(Range1).isFullSet())
1545 if (Range0.contains(Range1))
1546 return IsAnd ? Cmp1 : Cmp0;
1547 if (Range1.contains(Range0))
1548 return IsAnd ? Cmp0 : Cmp1;
1556 const APInt *C0, *C1;
1564 auto *AddInst = cast<BinaryOperator>(Op0->
getOperand(0));
1565 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1569 bool isNSW = AddInst->hasNoSignedWrap();
1570 bool isNUW = AddInst->hasNoUnsignedWrap();
1572 const APInt Delta = *C1 - *C0;
1573 if (C0->isStrictlyPositive()) {
1587 if (C0->getBoolValue() && isNUW) {
1624 const APInt *C0, *C1;
1632 auto *AddInst = cast<BinaryOperator>(Op0->
getOperand(0));
1633 if (AddInst->getOperand(1) != Op1->
getOperand(1))
1637 bool isNSW = AddInst->hasNoSignedWrap();
1638 bool isNUW = AddInst->hasNoUnsignedWrap();
1640 const APInt Delta = *C1 - *C0;
1641 if (C0->isStrictlyPositive()) {
1655 if (C0->getBoolValue() && isNUW) {
1693 if (Cast0 && Cast1 && Cast0->getOpcode() == Cast1->getOpcode() &&
1694 Cast0->getSrcTy() == Cast1->getSrcTy()) {
1695 Op0 = Cast0->getOperand(0);
1696 Op1 = Cast1->getOperand(0);
1713 if (
auto *
C = dyn_cast<Constant>(V))
1722 unsigned MaxRecurse) {
1763 (~(*Mask)).lshr(*ShAmt).isNullValue())
1769 (~(*Mask)).shl(*ShAmt).isNullValue())
1804 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1811 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1826 unsigned MaxRecurse) {
1920 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1926 const APInt *C1, *C2;
1953 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1967 unsigned MaxRecurse) {
2026 if (Pred == Cmp->
getPredicate() && LHS == CmpLHS && RHS == CmpRHS)
2029 LHS == CmpRHS && RHS == CmpLHS)
2143 if (isa<AllocaInst>(LHS) &&
2144 (isa<AllocaInst>(RHS) || isa<GlobalVariable>(RHS))) {
2147 uint64_t LHSSize, RHSSize;
2148 if (LHSOffsetCI && RHSOffsetCI &&
2152 const APInt &RHSOffsetValue = RHSOffsetCI->getValue();
2155 LHSOffsetValue.
ult(LHSSize) &&
2156 RHSOffsetValue.
ult(RHSSize)) {
2164 if (!cast<PointerType>(LHS->
getType())->isEmptyTy() &&
2165 !cast<PointerType>(RHS->
getType())->isEmptyTy() &&
2205 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2206 return AI->getParent() && AI->getFunction() && AI->isStaticAlloca();
2207 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
2208 return (GV->hasLocalLinkage() || GV->hasHiddenVisibility() ||
2209 GV->hasProtectedVisibility() || GV->hasGlobalUnnamedAddr()) &&
2210 !GV->isThreadLocal();
2211 if (
const Argument *
A = dyn_cast<Argument>(V))
2212 return A->hasByValAttr();
2217 if ((IsNAC(LHSUObjs) && IsAllocDisjoint(RHSUObjs)) ||
2218 (IsNAC(RHSUObjs) && IsAllocDisjoint(LHSUObjs)))
2405 case Instruction::And:
2411 case Instruction::Or:
2417 case Instruction::AShr:
2423 unsigned ShiftAmount = Width - 1;
2429 Upper = C->
ashr(ShiftAmount) + 1;
2432 Lower = C->
ashr(ShiftAmount);
2438 case Instruction::LShr:
2444 unsigned ShiftAmount = Width - 1;
2447 Lower = C->
lshr(ShiftAmount);
2452 case Instruction::Shl:
2462 Lower = C->
shl(ShiftAmount);
2468 Upper = C->
shl(ShiftAmount) + 1;
2474 case Instruction::SDiv:
2486 Lower = IntMin.
sdiv(*C);
2487 Upper = IntMax.
sdiv(*C);
2488 if (Lower.
sgt(Upper))
2491 assert(Upper != Lower &&
"Upper part of range has wrapped!");
2497 Upper = Lower.
lshr(1) + 1;
2500 Upper = C->
abs() + 1;
2501 Lower = (-Upper) + 1;
2506 case Instruction::UDiv:
2516 case Instruction::SRem:
2520 Lower = (-Upper) + 1;
2524 case Instruction::URem:
2552 if (
auto *BO = dyn_cast<BinaryOperator>(LHS))
2556 Lower != Upper ?
ConstantRange(Lower, Upper) : ConstantRange(Width,
true);
2558 if (
auto *
I = dyn_cast<Instruction>(LHS))
2577 unsigned MaxRecurse) {
2582 if (MaxRecurse && (LBO || RBO)) {
2584 Value *
A =
nullptr, *
B =
nullptr, *
C =
nullptr, *
D =
nullptr;
2586 bool NoLHSWrapProblem =
false, NoRHSWrapProblem =
false;
2596 C = RBO->getOperand(0);
2597 D = RBO->getOperand(1);
2605 if ((A == RHS ||
B == RHS) && NoLHSWrapProblem)
2612 if ((
C == LHS ||
D == LHS) && NoRHSWrapProblem)
2615 C == LHS ?
D :
C, Q, MaxRecurse - 1))
2619 if (A && C && (A == C || A ==
D ||
B == C ||
B ==
D) && NoLHSWrapProblem &&
2627 }
else if (A ==
D) {
2631 }
else if (
B == C) {
2699 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
2700 if (RHSC->getValue().isStrictlyPositive()) {
2710 if (RHSC->getValue().isNonNegative()) {
2806 if (
auto *CI = dyn_cast<ConstantInt>(RHS)) {
2807 const APInt *CI2Val, *CIVal = &CI->getValue();
2836 if (MaxRecurse && LBO && RBO && LBO->
getOpcode() == RBO->getOpcode() &&
2841 case Instruction::UDiv:
2842 case Instruction::LShr:
2846 RBO->getOperand(0), Q, MaxRecurse - 1))
2849 case Instruction::SDiv:
2853 RBO->getOperand(0), Q, MaxRecurse - 1))
2856 case Instruction::AShr:
2857 if (!LBO->
isExact() || !RBO->isExact())
2860 RBO->getOperand(0), Q, MaxRecurse - 1))
2863 case Instruction::Shl: {
2871 RBO->getOperand(0), Q, MaxRecurse - 1))
2884 unsigned MaxRecurse) {
2898 (A == LHS || B == LHS)) {
2905 (A == RHS || B == RHS)) {
2913 (A == LHS || B == LHS)) {
2972 (A == LHS || B == LHS)) {
2979 (A == RHS || B == RHS)) {
2987 (A == LHS || B == LHS)) {
3041 (A == C || A == D || B == C || B == D)) {
3051 (A == C || A == D || B == C || B == D)) {
3061 (A == C || A == D || B == C || B == D)) {
3071 (A == C || A == D || B == C || B == D)) {
3091 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
3092 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
3105 if (LHS == RHS || isa<UndefValue>(RHS))
3119 if (isa<Instruction>(RHS) && isa<Instruction>(LHS)) {
3120 auto RHS_Instr = cast<Instruction>(RHS);
3121 auto LHS_Instr = cast<Instruction>(LHS);
3131 if (Satisfied_CR.contains(LHS_CR))
3136 if (InversedSatisfied_CR.contains(LHS_CR))
3142 if (isa<CastInst>(LHS) && (isa<Constant>(RHS) || isa<CastInst>(RHS))) {
3145 Type *SrcTy = SrcOp->getType();
3150 if (MaxRecurse && isa<PtrToIntInst>(LI) &&
3152 if (
Constant *RHSC = dyn_cast<Constant>(RHS)) {
3158 }
else if (
PtrToIntInst *RI = dyn_cast<PtrToIntInst>(RHS)) {
3159 if (RI->getOperand(0)->getType() == SrcTy)
3167 if (isa<ZExtInst>(LHS)) {
3170 if (
ZExtInst *RI = dyn_cast<ZExtInst>(RHS)) {
3171 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
3174 SrcOp, RI->getOperand(0), Q,
3180 else if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
3188 if (RExt == CI && MaxRecurse)
3190 SrcOp, Trunc, Q, MaxRecurse-1))
3213 return CI->getValue().isNegative() ?
3219 return CI->getValue().isNegative() ?
3227 if (isa<SExtInst>(LHS)) {
3230 if (
SExtInst *RI = dyn_cast<SExtInst>(RHS)) {
3231 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
3239 else if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
3247 if (RExt == CI && MaxRecurse)
3265 return CI->getValue().isNegative() ?
3270 return CI->getValue().isNegative() ?
3317 if (
auto *CLHS = dyn_cast<PtrToIntOperator>(LHS))
3318 if (
auto *CRHS = dyn_cast<PtrToIntOperator>(RHS))
3324 CLHS->getPointerOperand(),
3325 CRHS->getPointerOperand()))
3329 if (
GEPOperator *GRHS = dyn_cast<GEPOperator>(RHS)) {
3330 if (GLHS->getPointerOperand() == GRHS->getPointerOperand() &&
3331 GLHS->hasAllConstantIndices() && GRHS->hasAllConstantIndices() &&
3333 (GLHS->isInBounds() && GRHS->isInBounds() &&
3341 GLHS->getSourceElementType(),
Null, IndicesLHS);
3345 GLHS->getSourceElementType(),
Null, IndicesRHS);
3353 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3359 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3375 unsigned MaxRecurse) {
3379 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
3380 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
3405 if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS)) {
3421 if (
const auto *RHSC = dyn_cast<Constant>(RHS)) {
3423 CFP = dyn_cast_or_null<ConstantFP>(RHSC->getSplatValue());
3433 "Comparison must be either ordered or unordered!");
3482 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3488 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3503 unsigned MaxRecurse) {
3509 if (isa<Constant>(Op))
3517 if (
auto *
B = dyn_cast<BinaryOperator>(
I)) {
3524 if (isa<OverflowingBinaryOperator>(
B))
3525 if (
B->hasNoSignedWrap() ||
B->hasNoUnsignedWrap())
3527 if (isa<PossiblyExactOperator>(
B))
3532 if (
B->getOperand(0) ==
Op)
3535 if (
B->getOperand(1) ==
Op)
3542 if (
CmpInst *
C = dyn_cast<CmpInst>(
I)) {
3544 if (
C->getOperand(0) ==
Op)
3547 if (
C->getOperand(1) ==
Op)
3557 if (
Constant *CRepOp = dyn_cast<Constant>(RepOp)) {
3560 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i) {
3561 if (
I->getOperand(i) ==
Op)
3563 else if (
Constant *COp = dyn_cast<Constant>(
I->getOperand(i)))
3570 if (ConstOps.
size() ==
I->getNumOperands()) {
3573 ConstOps[1], Q.
DL, Q.
TLI);
3575 if (
LoadInst *LI = dyn_cast<LoadInst>(
I))
3576 if (!LI->isVolatile())
3589 const APInt *
Y,
bool TrueWhenUnset) {
3596 return TrueWhenUnset ? FalseVal : TrueVal;
3602 return TrueWhenUnset ? FalseVal : TrueVal;
3609 return TrueWhenUnset ? TrueVal : FalseVal;
3615 return TrueWhenUnset ? TrueVal : FalseVal;
3625 bool TrueWhenUnset) {
3630 APInt MinSignedValue;
3655 unsigned MaxRecurse) {
3657 Value *CmpLHS, *CmpRHS;
3734 unsigned MaxRecurse) {
3737 if (
Constant *CB = dyn_cast<Constant>(CondVal)) {
3738 if (CB->isAllOnesValue())
3740 if (CB->isNullValue())
3745 if (TrueVal == FalseVal)
3748 if (isa<UndefValue>(CondVal)) {
3749 if (isa<Constant>(FalseVal))
3753 if (isa<UndefValue>(TrueVal))
3755 if (isa<UndefValue>(FalseVal))
3776 cast<PointerType>(Ops[0]->getType()->getScalarType())->getAddressSpace();
3779 if (Ops.
size() == 1)
3790 if (isa<UndefValue>(Ops[0]))
3793 if (Ops.
size() == 2) {
3804 if (TyAllocSize == 0)
3809 if (Ops[1]->
getType()->getScalarSizeInBits() ==
3811 auto PtrToIntOrZero = [GEPTy](
Value *
P) ->
Value * {
3822 if (TyAllocSize == 1 &&
3824 if (
Value *R = PtrToIntOrZero(P))
3832 TyAllocSize == 1ULL <<
C)
3833 if (
Value *R = PtrToIntOrZero(P))
3841 if (
Value *R = PtrToIntOrZero(P))
3853 APInt BasePtrOffset(PtrWidth, 0);
3854 Value *StrippedBasePtr =
3855 Ops[0]->stripAndAccumulateInBoundsConstantOffsets(Q.
DL,
3874 if (!
all_of(Ops, [](
Value *V) {
return isa<Constant>(V); }))
3894 if (
Constant *CAgg = dyn_cast<Constant>(Agg))
3895 if (
Constant *CVal = dyn_cast<Constant>(Val))
3904 if (EV->getAggregateOperand()->getType() == Agg->
getType() &&
3905 EV->getIndices() == Idxs) {
3908 return EV->getAggregateOperand();
3911 if (Agg == EV->getAggregateOperand())
3928 if (
auto *CAgg = dyn_cast<Constant>(Agg))
3932 unsigned NumIdxs = Idxs.
size();
3933 for (
auto *IVI = dyn_cast<InsertValueInst>(Agg); IVI !=
nullptr;
3936 unsigned NumInsertValueIdxs = InsertValueIdxs.
size();
3937 unsigned NumCommonIdxs =
std::min(NumInsertValueIdxs, NumIdxs);
3938 if (InsertValueIdxs.
slice(0, NumCommonIdxs) ==
3939 Idxs.
slice(0, NumCommonIdxs)) {
3940 if (NumIdxs == NumInsertValueIdxs)
3941 return IVI->getInsertedValueOperand();
3958 if (
auto *CVec = dyn_cast<Constant>(Vec)) {
3959 if (
auto *CIdx = dyn_cast<Constant>(Idx))
3963 if (
auto *Splat = CVec->getSplatValue())
3966 if (isa<UndefValue>(Vec))
3972 if (
auto *IdxC = dyn_cast<ConstantInt>(Idx))
3988 Value *CommonValue =
nullptr;
3989 bool HasUndefInput =
false;
3992 if (Incoming == PN)
continue;
3993 if (isa<UndefValue>(Incoming)) {
3995 HasUndefInput =
true;
3998 if (CommonValue && Incoming != CommonValue)
4000 CommonValue = Incoming;
4019 if (
auto *
C = dyn_cast<Constant>(Op))
4022 if (
auto *CI = dyn_cast<CastInst>(Op)) {
4023 auto *Src = CI->getOperand(0);
4024 Type *SrcTy = Src->getType();
4025 Type *MidTy = CI->getType();
4027 if (Src->getType() == Ty) {
4037 SrcIntPtrTy, MidIntPtrTy,
4038 DstIntPtrTy) == Instruction::BitCast)
4044 if (CastOpc == Instruction::BitCast)
4060 int MaskVal,
Value *RootVec,
4061 unsigned MaxRecurse) {
4072 int RootElt = MaskVal;
4073 Value *SourceOp = Op0;
4074 if (MaskVal >= InVecNumElts) {
4075 RootElt = MaskVal - InVecNumElts;
4081 if (
auto *SourceShuf = dyn_cast<ShuffleVectorInst>(SourceOp)) {
4083 DestElt, SourceShuf->getOperand(0), SourceShuf->getOperand(1),
4084 SourceShuf->getMaskValue(RootElt), RootVec, MaxRecurse);
4096 if (RootVec != SourceOp)
4101 if (RootElt != DestElt)
4109 unsigned MaxRecurse) {
4110 if (isa<UndefValue>(Mask))
4120 "Size of Indices not same as number of mask elements?");
4124 bool MaskSelects0 =
false, MaskSelects1 =
false;
4125 for (
unsigned i = 0; i != MaskNumElts; ++i) {
4126 if (Indices[i] == -1)
4128 if ((
unsigned)Indices[i] < InVecNumElts)
4129 MaskSelects0 =
true;
4131 MaskSelects1 =
true;
4142 if (Op0Const && Op1Const)
4147 if (Op0Const && !Op1Const) {
4154 if (
auto *OpShuf = dyn_cast<ShuffleVectorInst>(Op0))
4155 if (isa<UndefValue>(Op1) && RetTy == InVecTy &&
4156 OpShuf->getMask()->getSplatValue())
4162 if (
find(Indices, -1) != Indices.
end())
4169 Value *RootVec =
nullptr;
4170 for (
unsigned i = 0; i != MaskNumElts; ++i) {
4177 if (!RootVec || RootVec->
getType() != RetTy)
4198 case Instruction::FAdd:
4200 case Instruction::Sub:
4202 case Instruction::FSub:
4204 case Instruction::Mul:
4206 case Instruction::FMul:
4208 case Instruction::SDiv:
4210 case Instruction::UDiv:
4212 case Instruction::FDiv:
4214 case Instruction::SRem:
4216 case Instruction::URem:
4218 case Instruction::FRem:
4220 case Instruction::Shl:
4222 case Instruction::LShr:
4224 case Instruction::AShr:
4226 case Instruction::And:
4228 case Instruction::Or:
4230 case Instruction::Xor:
4243 unsigned MaxRecurse) {
4245 case Instruction::FAdd:
4247 case Instruction::FSub:
4249 case Instruction::FMul:
4251 case Instruction::FDiv:
4283 default:
return false;
4286 case Intrinsic::fabs:
4287 case Intrinsic::floor:
4288 case Intrinsic::ceil:
4289 case Intrinsic::trunc:
4290 case Intrinsic::rint:
4291 case Intrinsic::nearbyint:
4310 if (!OffsetConstInt || OffsetConstInt->getType()->getBitWidth() > 64)
4314 if (OffsetInt % 4 != 0)
4328 if (LoadedCE->getOpcode() == Instruction::Trunc) {
4334 if (LoadedCE->getOpcode() != Instruction::Sub)
4338 if (!LoadedLHS || LoadedLHS->getOpcode() != Instruction::PtrToInt)
4340 auto *LoadedLHSPtr = LoadedLHS->
getOperand(0);
4344 APInt LoadedRHSOffset;
4347 PtrSym != LoadedRHSSym || PtrOffset != LoadedRHSOffset)
4357 if (ConstMask->isNullValue() || isa<UndefValue>(ConstMask))
4359 for (
unsigned I = 0,
E = ConstMask->getType()->getVectorNumElements();
I !=
E;
4361 if (
auto *MaskElt = ConstMask->getAggregateElement(
I))
4362 if (MaskElt->isNullValue() || isa<UndefValue>(MaskElt))
4369 template <
typename IterTy>
4373 unsigned NumOperands = std::distance(ArgBegin, ArgEnd);
4376 if (NumOperands == 1) {
4379 if (
IntrinsicInst *II = dyn_cast<IntrinsicInst>(*ArgBegin)) {
4380 if (II->getIntrinsicID() == IID)
4386 case Intrinsic::fabs: {
4397 if (NumOperands == 2) {
4398 Value *LHS = *ArgBegin;
4399 Value *RHS = *(ArgBegin + 1);
4403 case Intrinsic::usub_with_overflow:
4404 case Intrinsic::ssub_with_overflow: {
4411 if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS))
4416 case Intrinsic::uadd_with_overflow:
4417 case Intrinsic::sadd_with_overflow: {
4419 if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS))
4424 case Intrinsic::umul_with_overflow:
4425 case Intrinsic::smul_with_overflow: {
4438 case Intrinsic::load_relative: {
4452 case Intrinsic::masked_load: {
4453 Value *MaskArg = ArgBegin[2];
4454 Value *PassthruArg = ArgBegin[3];
4465 template <
typename IterTy>
4468 unsigned MaxRecurse) {
4471 Ty = PTy->getElementType();
4476 if (isa<UndefValue>(V) || isa<ConstantPointerNull>(V))
4483 if (F->isIntrinsic())
4491 ConstantArgs.
reserve(ArgEnd - ArgBegin);
4492 for (IterTy
I = ArgBegin,
E = ArgEnd;
I !=
E; ++
I) {
4525 case Instruction::FAdd:
4531 cast<BinaryOperator>(
I)->hasNoSignedWrap(),
4532 cast<BinaryOperator>(
I)->hasNoUnsignedWrap(), Q);
4534 case Instruction::FSub:
4538 case Instruction::Sub:
4540 cast<BinaryOperator>(
I)->hasNoSignedWrap(),
4541 cast<BinaryOperator>(
I)->hasNoUnsignedWrap(), Q);
4543 case Instruction::FMul:
4547 case Instruction::Mul:
4550 case Instruction::SDiv:
4553 case Instruction::UDiv:
4556 case Instruction::FDiv:
4560 case Instruction::SRem:
4563 case Instruction::URem:
4566 case Instruction::FRem:
4570 case Instruction::Shl:
4572 cast<BinaryOperator>(
I)->hasNoSignedWrap(),
4573 cast<BinaryOperator>(
I)->hasNoUnsignedWrap(), Q);
4575 case Instruction::LShr:
4577 cast<BinaryOperator>(
I)->isExact(), Q);
4579 case Instruction::AShr:
4581 cast<BinaryOperator>(
I)->isExact(), Q);
4583 case Instruction::And:
4586 case Instruction::Or:
4589 case Instruction::Xor:
4592 case Instruction::ICmp:
4596 case Instruction::FCmp:
4605 case Instruction::GetElementPtr: {
4607 Result =
SimplifyGEPInst(cast<GetElementPtrInst>(I)->getSourceElementType(),
4611 case Instruction::InsertValue: {
4618 case Instruction::ExtractValue: {
4619 auto *EVI = cast<ExtractValueInst>(
I);
4621 EVI->getIndices(), Q);
4624 case Instruction::ExtractElement: {
4625 auto *EEI = cast<ExtractElementInst>(
I);
4627 EEI->getIndexOperand(), Q);
4630 case Instruction::ShuffleVector: {
4631 auto *SVI = cast<ShuffleVectorInst>(
I);
4633 SVI->getMask(), SVI->getType(), Q);
4636 case Instruction::PHI:
4645 #define HANDLE_CAST_INST(num, opc, clas) case Instruction::opc:
4646 #include "llvm/IR/Instruction.def"
4647 #undef HANDLE_CAST_INST
4651 case Instruction::Alloca:
4695 Worklist.
insert(cast<Instruction>(U));
4710 for (
unsigned Idx = 0; Idx != Worklist.
size(); ++Idx) {
4724 Worklist.
insert(cast<Instruction>(U));
4749 assert(I != SimpleV &&
"replaceAndRecursivelySimplify(X,X) is not valid!");
4750 assert(SimpleV &&
"Must provide a simplified value.");
4757 auto *DT = DTWP ? &DTWP->
getDomTree() :
nullptr;
4759 auto *TLI = TLIWP ? &TLIWP->
getTLI() :
nullptr;
4767 return {DL, &AR.
TLI, &AR.
DT, &AR.
AC};
4770 template <
class T,
class... TArgs>
4773 auto *DT = AM.template getCachedResult<DominatorTreeAnalysis>(
F);
4774 auto *TLI = AM.template getCachedResult<TargetLibraryAnalysis>(
F);
4775 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)
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.
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.
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 countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
void push_back(const T &Elt)
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)
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)
Return true if the given value is known to have exactly one bit set when defined. ...
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 Value * SimplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an SRem, see if we can fold the result.
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.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Value * getAggregateOperand()
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 const Value * getFNegArgument(const Value *BinOp)
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...
STATISTIC(NumFunctions,"Total number of functions")
ArrayRef< unsigned > getIndices() const
bool ult(const APInt &RHS) const
Unsigned less than comparison.
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.
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.
static Value * SimplifyGEPInst(Type *SrcTy, ArrayRef< Value * > Ops, const SimplifyQuery &Q, unsigned)
Given operands for an GetElementPtrInst, see if we can fold the result.
bool isOneValue() const
Determine if this is a value of 1.
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
match_zero m_Zero()
Match an arbitrary zero/null constant.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
This class represents zero extension of integer types.
bool hasNoSignedWrap() const
Test whether this operation is known to never undergo signed overflow, aka the nsw property...
static Value * simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1)
static Value * SimplifyCall(ImmutableCallSite CS, Value *V, IterTy ArgBegin, IterTy ArgEnd, const SimplifyQuery &Q, unsigned MaxRecurse)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
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
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
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 uint64_t round(uint64_t Acc, uint64_t Input)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isSigned() const
Determine if this instruction is using a signed comparison.
A cache of .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.
Value * SimplifySDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SDiv, fold the result or return null.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
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...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
static Value * simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1)
const Function * getParent() const
Return the enclosing method, or null if none.
Value * SimplifyUDivInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a UDiv, fold the result or return null.
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)
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 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)
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)
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...
const TargetLibraryInfo * TLI
size_type size() const
Determine the number of elements in the SetVector.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static Constant * computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI, const DominatorTree *DT, CmpInst::Predicate Pred, const Instruction *CxtI, Value *LHS, Value *RHS)
Value * SimplifyOrInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Or, fold the result or return null.
const APInt & getConstant() const
Returns the value when all bits have a known value.
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.
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.
bool isNegative() const
Determine sign of this APInt.
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.
bool match(Val *V, const Pattern &P)
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 * simplifyICmpWithConstant(CmpInst::Predicate Pred, Value *LHS, Value *RHS)
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)
bool isNonNegative() const
Returns true if this value is known to be non-negative.
bool hasNoNaNs() const
Determine whether the no-NaNs flag is set.
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.
This class represents the LLVM 'select' instruction.
bool noSignedZeros() const
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.
const APInt & getValue() const
Return the constant as an APInt value reference.
TargetLibraryInfo & getTLI()
Exact_match< T > m_Exact(const T &SubPattern)
Value * SimplifyCall(ImmutableCallSite CS, Value *V, User::op_iterator ArgBegin, User::op_iterator ArgEnd, const SimplifyQuery &Q)
Given a function and iterators over arguments, fold the result or return null.
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
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...
A Use represents the edge between a Value definition and its users.
static Value * simplifyAndOrOfICmps(Value *Op0, Value *Op1, bool IsAnd)
ValTy * getCalledValue() const
Return the pointer to function that is being called.
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 * 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()
bool isMask(unsigned numBits) const
Type * getVectorElementType() const
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.
zlib-gnu style compression
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.
not_match< LHS > m_Not(const LHS &L)
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)
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
APInt shl(unsigned shiftAmt) const
Left-shift function.
static Value * SimplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF, const SimplifyQuery &Q, unsigned)
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.
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.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
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.
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)
bool sgt(const APInt &RHS) const
Signed greather than comparison.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
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.
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
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...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
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.
unsigned getBitWidth() const
Get the bit width of this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
size_t size() const
size - Get the array size.
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.
static void setLimitsForBinOp(BinaryOperator &BO, APInt &Lower, APInt &Upper)
Many binary operators with a constant operand have an easy-to-compute range of outputs.
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)
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static Value * SimplifyCmpInst(unsigned, Value *, Value *, const SimplifyQuery &, unsigned)
Given operands for a CmpInst, see if we can fold the result.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
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 isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static Value * simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *TrueVal, Value *FalseVal, bool TrueWhenUnset)
An alternative way to test if a bit is set or not uses sgt/slt instead of eq/ne.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and indices...
Type * getReturnType() const
Returns the type of the ret val.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Value * SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q)
Given operands for a SelectInst, fold the result or return null.
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.
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)
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
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.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
bool isNegative() const
Returns true if this value is known to be negative.
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
bool isExact() const
Determine whether the exact flag is set.
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.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isEquality() const
Return true if this predicate is either EQ or NE.
static Constant * stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V, bool AllowNonInbounds=false)
Compute the base pointer and cumulative constant offsets for V.
static Value * SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an SRem or URem, see if we can fold the result.
This is an important base class in LLVM.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
const Value * getCondition() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
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)
Return true if 'V & Mask' is known to be zero.
unsigned countLeadingOnes() const
Count the number of leading one bits.
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.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
ConstantFP - Floating Point Values [float, double].
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.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
bool isIntPredicate() const
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
bool isConstant() const
Returns true if we know the value of all bits.
static Value * SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd, const SimplifyQuery &Q, unsigned MaxRecurse)
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:
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool isFalseWhenEqual() const
This is just a convenience.
APInt ashr(unsigned ShiftAmt) const
Arithmetic right-shift function.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
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.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isMaxValue() const
Determine if this is the largest unsigned value.
APInt sdiv(const APInt &RHS) const
Signed division function for APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
bool isCommutative() const
Return true if the instruction is commutative:
SimplifyQuery getWithInstruction(Instruction *I) const
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...
Predicate getPredicate() const
Return the predicate for this instruction.
static bool ValueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT)
Does the given value dominate the specified phi node?
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
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 Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
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 * 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 ...
bool isEmptySet() const
Return true if this set contains no members.
bool isPointerTy() const
True if this is an instance of PointerType.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
LLVMContext & getContext() const
All values hold a context through their type.
static wasm::ValType getType(const TargetRegisterClass *RC)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
const Value * getTrueValue() const
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...
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
1 1 0 1 True if unordered, less than, or equal
static Value * simplifyOrOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1)
const T & back() const
back - Get the last element.
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.
neg_match< LHS > m_Neg(const LHS &L)
Match an integer negate.
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
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...
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
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.
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return the number of times the sign bit of the register is replicated into the other bits...
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
match_any_zero m_AnyZero()
Match an arbitrary zero/null constant.
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
static Value * simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv)
Check for common or similar folds of integer division or integer remainder.
static Value * SimplifySelectInst(Value *CondVal, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for a SelectInst, see if we can fold the result.
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
Type * getType() const
All values are typed, get the type of this value.
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.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
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.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isTrueWhenEqual() const
This is just a convenience.
static unsigned isEliminableCastPair(Instruction::CastOps firstOpcode, Instruction::CastOps secondOpcode, Type *SrcTy, Type *MidTy, Type *DstTy, Type *SrcIntPtrTy, Type *MidIntPtrTy, Type *DstIntPtrTy)
Determine how a pair of casts can be eliminated, if they can be at all.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
const BasicBlock & getEntryBlock() const
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 isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static Value * simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1)
static ConstantInt * getTrue(LLVMContext &Context)
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...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class to represent vector types.
Class for arbitrary precision integers.
static Constant * getFalse(Type *Ty)
For a boolean type or a vector of boolean type, return false or a vector with every element false...
Value * SimplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FSub, fold the result or return null.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
iterator_range< user_iterator > users()
unsigned getVectorNumElements() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
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.
bool isMinValue() const
Determine if this is the smallest unsigned value.
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FMul, fold the result or return null.
bool isFPPredicate() const
llvm_unreachable("Unknown RegBank!")
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
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...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Value * SimplifyGEPInst(Type *SrcTy, ArrayRef< Value * > Ops, const SimplifyQuery &Q)
Given operands for a GetElementPtrInst, fold the result or return null.
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.
bool isAllOnesValue() const
Determine if all bits are set.
static Value * SimplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const SimplifyQuery &Q, unsigned MaxRecurse)
Given operands for an SDiv or UDiv, see if we can fold the result.
static Value * SimplifyAssociativeBinOp(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse)
Generic simplifications for associative binary operations.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
static Constant * computePointerDifference(const DataLayout &DL, Value *LHS, Value *RHS)
Compute the constant difference between two pointer values.
bool isKnownNonNull(const Value *V)
Return true if this pointer couldn't possibly be null by its definition.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
static Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &, unsigned)
Given operands for an ExtractValueInst, see if we can fold the result.
APInt udiv(const APInt &RHS) const
Unsigned division operation.
static IntegerType * getInt32Ty(LLVMContext &C)
unsigned greater or equal
static bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
match_one m_One()
Match an integer 1 or a vector with all elements equal to 1.
static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC)
Implementation of recursive simplification through an instruction's uses.
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
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.
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
bool hasOneUse() const
Return true if there is exactly one user of this value.
bool hasNoInfs() const
Determine whether the no-infs flag is set.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
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)
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)
Value * SimplifyXorInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Xor, fold the result or return null.
bool isKnownNonNullAt(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if this pointer couldn't possibly be null.
static bool IsIdempotent(Intrinsic::ID ID)
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given values are known to be non-equal when defined.
Value * SimplifySRemInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an SRem, fold the result or return null.
const APFloat & getValueAPF() const
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
match_neg_zero m_NegZero()
Match an arbitrary zero/null constant.
Type * getReturnType() const
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.
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...
static Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQuery &, unsigned)
Given operands for an ExtractElementInst, see if we can fold the result.
match_all_ones m_AllOnes()
Match an integer or vector with all bits set to true.
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.
match_sign_mask m_SignMask()
Match an integer or vector with only the sign bit(s) set.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
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
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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...
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
static Value * SimplifyPHINode(PHINode *PN, const SimplifyQuery &Q)
See if we can fold the given phi. If not, returns null.
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
Value * SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const SimplifyQuery &Q)
Given operands for a Sub, fold the result or return null.
AssumptionCache & getAssumptionCache(Function &F)
Get the cached assumptions for a function.
Value * SimplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an InsertValueInst, 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)
Return true if the given value is known to be non-zero when defined.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
Optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsFalse=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if RHS is known to be implied true by LHS.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
const Value * getFalseValue() const
Convenience struct for specifying and reasoning about fast-math flags.
APInt zext(unsigned width) const
Zero extend to a new width.
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.
bool isNullValue() const
Determine if all bits are clear.
Legacy analysis pass which computes a DominatorTree.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
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.
APInt abs() const
Get the absolute value;.
static volatile int * Null
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()
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
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)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
const BasicBlock * getParent() const
static Type * GetCompareTy(Value *Op)
bool hasNoUnsignedWrap() const
Test whether this operation is known to never undergo unsigned overflow, aka the nuw property...
static void commuteShuffleMask(MutableArrayRef< int > Mask, unsigned InVecNumElts)
Change values in a shuffle permute mask assuming the two vector operands of length InVecNumElts have ...
SmallVector< int, 16 > getShuffleMask() const
0 0 0 0 Always false (always folded)
bool noNaNs() const
Flag queries.
A wrapper class for inspecting calls to intrinsic functions.
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)
Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.