38 using namespace llvm::PatternMatch;
40 #define DEBUG_TYPE "instsimplify"
44 STATISTIC(NumExpand,
"Number of expansions");
45 STATISTIC(NumReassoc,
"Number of reassociations");
58 : DL(DL), TLI(tli), DT(dt), AC(ac), CxtI(cxti) {}
66 const Query &,
unsigned);
77 "Expected i1 type or a vector of i1!");
85 "Expected i1 type or a vector of i1!");
97 if (CPred == Pred && CLHS == LHS && CRHS == RHS)
140 unsigned OpcToExpand,
const Query &Q,
141 unsigned MaxRecurse) {
149 if (Op0->getOpcode() == OpcodeToExpand) {
151 Value *
A = Op0->getOperand(0), *B = Op0->getOperand(1), *C = RHS;
158 && L == B && R == A)) {
172 if (Op1->getOpcode() == OpcodeToExpand) {
174 Value *
A = LHS, *B = Op1->getOperand(0), *C = Op1->getOperand(1);
181 && L == C && R == B)) {
199 const Query &Q,
unsigned MaxRecurse) {
220 if (V == B)
return LHS;
230 if (Op1 && Op1->getOpcode() == Opcode) {
232 Value *B = Op1->getOperand(0);
233 Value *C = Op1->getOperand(1);
239 if (V == B)
return RHS;
262 if (V == A)
return LHS;
272 if (Op1 && Op1->getOpcode() == Opcode) {
274 Value *B = Op1->getOperand(0);
275 Value *C = Op1->getOperand(1);
281 if (V == C)
return RHS;
298 const Query &Q,
unsigned MaxRecurse) {
304 if (isa<SelectInst>(LHS)) {
305 SI = cast<SelectInst>(LHS);
307 assert(isa<SelectInst>(RHS) &&
"No select instruction operand!");
308 SI = cast<SelectInst>(RHS);
328 if (TV && isa<UndefValue>(TV))
330 if (FV && isa<UndefValue>(FV))
341 if ((FV && !TV) || (TV && !FV)) {
345 if (Simplified && Simplified->
getOpcode() == Opcode) {
350 Value *UnsimplifiedLHS = SI == LHS ? UnsimplifiedBranch : LHS;
351 Value *UnsimplifiedRHS = SI == LHS ? RHS : UnsimplifiedBranch;
352 if (Simplified->
getOperand(0) == UnsimplifiedLHS &&
356 Simplified->
getOperand(1) == UnsimplifiedLHS &&
370 Value *RHS,
const Query &Q,
371 unsigned MaxRecurse) {
377 if (!isa<SelectInst>(LHS)) {
381 assert(isa<SelectInst>(LHS) &&
"Not comparing with a select instruction!");
393 TCmp =
getTrue(Cond->getType());
399 TCmp =
getTrue(Cond->getType());
452 const Query &Q,
unsigned MaxRecurse) {
458 if (isa<PHINode>(LHS)) {
459 PI = cast<PHINode>(LHS);
464 assert(isa<PHINode>(RHS) &&
"No PHI instruction operand!");
465 PI = cast<PHINode>(RHS);
472 Value *CommonValue =
nullptr;
475 if (Incoming == PI)
continue;
476 Value *V = PI == LHS ?
481 if (!V || (CommonValue && V != CommonValue))
494 const Query &Q,
unsigned MaxRecurse) {
500 if (!isa<PHINode>(LHS)) {
504 assert(isa<PHINode>(LHS) &&
"Not comparing with a phi instruction!");
505 PHINode *PI = cast<PHINode>(LHS);
512 Value *CommonValue =
nullptr;
515 if (Incoming == PI)
continue;
519 if (!V || (CommonValue && V != CommonValue))
530 const Query &Q,
unsigned MaxRecurse) {
531 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
532 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
604 bool AllowNonInbounds =
false) {
616 if ((!AllowNonInbounds && !
GEP->isInBounds()) ||
617 !
GEP->accumulateConstantOffset(DL, Offset))
619 V =
GEP->getPointerOperand();
621 V = cast<Operator>(V)->getOperand(0);
622 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
623 if (GA->mayBeOverridden())
625 V = GA->getAliasee();
630 "Unexpected operand type!");
631 }
while (Visited.insert(V).second);
662 const Query &Q,
unsigned MaxRecurse) {
663 if (
Constant *CLHS = dyn_cast<Constant>(Op0))
664 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
689 Value *
X =
nullptr, *
Y =
nullptr, *Z = Op1;
789 const Query &Q,
unsigned MaxRecurse) {
790 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
791 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
813 Value *SubOp =
nullptr;
831 const Query &Q,
unsigned MaxRecurse) {
832 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
833 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
859 if (FMF.
noNaNs() && Op0 == Op1)
869 unsigned MaxRecurse) {
870 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
871 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
895 unsigned MaxRecurse) {
896 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
897 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
942 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
949 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
995 const Query &Q,
unsigned MaxRecurse) {
996 if (
Constant *C0 = dyn_cast<Constant>(Op0)) {
997 if (
Constant *C1 = dyn_cast<Constant>(Op1)) {
1003 bool isSigned = Opcode == Instruction::SDiv;
1034 Value *
X =
nullptr, *
Y =
nullptr;
1044 if (Div->getOpcode() == Opcode && Div->getOperand(1) ==
Y)
1065 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1071 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1081 unsigned MaxRecurse) {
1099 unsigned MaxRecurse) {
1115 const Query &Q,
unsigned) {
1160 const Query &Q,
unsigned MaxRecurse) {
1161 if (
Constant *C0 = dyn_cast<Constant>(Op0)) {
1162 if (
Constant *C1 = dyn_cast<Constant>(Op1)) {
1197 if ((Opcode == Instruction::SRem &&
1199 (Opcode == Instruction::URem &&
1205 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1211 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1221 unsigned MaxRecurse) {
1239 unsigned MaxRecurse) {
1255 const Query &,
unsigned) {
1289 if (isa<UndefValue>(C))
1294 if (CI->getValue().getLimitedValue() >=
1295 CI->getType()->getScalarSizeInBits())
1299 if (isa<ConstantVector>(C) || isa<ConstantDataVector>(C)) {
1312 const Query &Q,
unsigned MaxRecurse) {
1313 if (
Constant *C0 = dyn_cast<Constant>(Op0)) {
1314 if (
Constant *C1 = dyn_cast<Constant>(Op1)) {
1334 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1340 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1350 bool isExact,
const Query &Q,
1351 unsigned MaxRecurse) {
1367 APInt Op0KnownZero(BitWidth, 0);
1368 APInt Op0KnownOne(BitWidth, 0);
1381 const Query &Q,
unsigned MaxRecurse) {
1408 const Query &Q,
unsigned MaxRecurse) {
1433 const Query &Q,
unsigned MaxRecurse) {
1465 ICmpInst *UnsignedICmp,
bool IsAnd) {
1477 else if (
match(UnsignedICmp,
1487 return IsAnd ? UnsignedICmp : ZeroICmp;
1494 return UnsignedICmp;
1524 auto *AddInst = cast<BinaryOperator>(Op0->
getOperand(0));
1525 bool isNSW = AddInst->hasNoSignedWrap();
1526 bool isNUW = AddInst->hasNoUnsignedWrap();
1530 const APInt Delta = CI2V - CI1V;
1531 if (CI1V.isStrictlyPositive()) {
1545 if (CI1V.getBoolValue() && isNUW) {
1560 unsigned MaxRecurse) {
1561 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
1562 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
1594 Value *
A =
nullptr, *B =
nullptr;
1596 (A == Op1 || B == Op1))
1601 (A == Op0 || B == Op0))
1615 if (
auto *ICILHS = dyn_cast<ICmpInst>(Op0)) {
1616 if (
auto *ICIRHS = dyn_cast<ICmpInst>(Op1)) {
1641 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1648 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1683 auto *AddInst = cast<BinaryOperator>(Op0->
getOperand(0));
1684 bool isNSW = AddInst->hasNoSignedWrap();
1685 bool isNUW = AddInst->hasNoUnsignedWrap();
1689 const APInt Delta = CI2V - CI1V;
1690 if (CI1V.isStrictlyPositive()) {
1704 if (CI1V.getBoolValue() && isNUW) {
1719 unsigned MaxRecurse) {
1720 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
1721 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
1753 Value *
A =
nullptr, *B =
nullptr;
1755 (A == Op1 || B == Op1))
1760 (A == Op0 || B == Op0))
1765 (A == Op1 || B == Op1))
1770 (A == Op0 || B == Op0))
1773 if (
auto *ICILHS = dyn_cast<ICmpInst>(Op0)) {
1774 if (
auto *ICIRHS = dyn_cast<ICmpInst>(Op1)) {
1794 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1800 Value *C =
nullptr, *D =
nullptr;
1805 if (C1 && C2 && (C1->
getValue() == ~C2->getValue())) {
1811 if ((C2->getValue() & (C2->getValue() + 1)) == 0 &&
1837 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1855 unsigned MaxRecurse) {
1856 if (
Constant *CLHS = dyn_cast<Constant>(Op0)) {
1857 if (
Constant *CRHS = dyn_cast<Constant>(Op1)) {
1925 if (Pred == Cmp->
getPredicate() && LHS == CmpLHS && RHS == CmpRHS)
1928 LHS == CmpRHS && RHS == CmpLHS)
2042 if (isa<AllocaInst>(LHS) &&
2043 (isa<AllocaInst>(RHS) || isa<GlobalVariable>(RHS))) {
2046 uint64_t LHSSize, RHSSize;
2047 if (LHSOffsetCI && RHSOffsetCI &&
2051 const APInt &RHSOffsetValue = RHSOffsetCI->getValue();
2054 LHSOffsetValue.
ult(LHSSize) &&
2055 RHSOffsetValue.
ult(RHSSize)) {
2063 if (!cast<PointerType>(LHS->
getType())->isEmptyTy() &&
2064 !cast<PointerType>(RHS->
getType())->isEmptyTy() &&
2093 return std::all_of(Objects.begin(), Objects.end(),
2104 return std::all_of(Objects.begin(), Objects.end(),
2106 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2107 return AI->getParent() && AI->getParent()->getParent() &&
2108 AI->isStaticAlloca();
2109 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V))
2110 return (GV->hasLocalLinkage() ||
2111 GV->hasHiddenVisibility() ||
2112 GV->hasProtectedVisibility() ||
2113 GV->hasUnnamedAddr()) &&
2114 !GV->isThreadLocal();
2115 if (
const Argument *
A = dyn_cast<Argument>(V))
2116 return A->hasByValAttr();
2121 if ((IsNAC(LHSUObjs) && IsAllocDisjoint(RHSUObjs)) ||
2122 (IsNAC(RHSUObjs) && IsAllocDisjoint(LHSUObjs)))
2134 const Query &Q,
unsigned MaxRecurse) {
2138 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
2139 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
2153 if (LHS == RHS || isa<UndefValue>(RHS))
2195 bool LHSKnownNonNegative, LHSKnownNegative;
2213 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2215 if (LHSKnownNegative)
2217 if (LHSKnownNonNegative)
2221 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2223 if (LHSKnownNegative)
2225 if (LHSKnownNonNegative &&
2230 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2232 if (LHSKnownNegative)
2234 if (LHSKnownNonNegative)
2238 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.DL, 0, Q.AC,
2240 if (LHSKnownNegative)
2242 if (LHSKnownNonNegative &&
2250 if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
2270 Lower = (-Upper) + 1;
2283 Upper = Lower.
lshr(1) + 1;
2287 Lower = (-Upper) + 1;
2301 Lower = IntMin.
sdiv(Val);
2302 Upper = IntMax.
sdiv(Val);
2303 if (Lower.
sgt(Upper))
2306 assert(Upper != Lower &&
"Upper part of range has wrapped!");
2331 unsigned ShiftAmount = Width - 1;
2332 if (!CI2->
isZero() && cast<BinaryOperator>(LHS)->isExact())
2345 unsigned ShiftAmount = Width - 1;
2346 if (!CI2->
isZero() && cast<BinaryOperator>(LHS)->isExact())
2364 if (Lower != Upper) {
2374 if (isa<CastInst>(LHS) && (isa<Constant>(RHS) || isa<CastInst>(RHS))) {
2377 Type *SrcTy = SrcOp->getType();
2382 if (MaxRecurse && isa<PtrToIntInst>(LI) &&
2384 if (
Constant *RHSC = dyn_cast<Constant>(RHS)) {
2390 }
else if (
PtrToIntInst *RI = dyn_cast<PtrToIntInst>(RHS)) {
2391 if (RI->getOperand(0)->getType() == SrcTy)
2399 if (isa<ZExtInst>(LHS)) {
2402 if (
ZExtInst *RI = dyn_cast<ZExtInst>(RHS)) {
2403 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
2406 SrcOp, RI->getOperand(0), Q,
2412 else if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
2420 if (RExt == CI && MaxRecurse)
2422 SrcOp, Trunc, Q, MaxRecurse-1))
2445 return CI->getValue().isNegative() ?
2451 return CI->getValue().isNegative() ?
2459 if (isa<SExtInst>(LHS)) {
2462 if (
SExtInst *RI = dyn_cast<SExtInst>(RHS)) {
2463 if (MaxRecurse && SrcTy == RI->getOperand(0)->getType())
2471 else if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
2479 if (RExt == CI && MaxRecurse)
2497 return CI->getValue().isNegative() ?
2502 return CI->getValue().isNegative() ?
2535 if (MaxRecurse && (LBO || RBO)) {
2537 Value *
A =
nullptr, *B =
nullptr, *C =
nullptr, *D =
nullptr;
2539 bool NoLHSWrapProblem =
false, NoRHSWrapProblem =
false;
2540 if (LBO && LBO->
getOpcode() == Instruction::Add) {
2546 if (RBO && RBO->getOpcode() == Instruction::Add) {
2547 C = RBO->getOperand(0); D = RBO->getOperand(1);
2554 if ((A == RHS || B == RHS) && NoLHSWrapProblem)
2561 if ((C == LHS || D == LHS) && NoRHSWrapProblem)
2564 C == LHS ? D : C, Q, MaxRecurse-1))
2568 if (A && C && (A == C || A == D || B == C || B == D) &&
2569 NoLHSWrapProblem && NoRHSWrapProblem) {
2576 }
else if (A == D) {
2580 }
else if (B == C) {
2631 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
2632 if (RHSC->getValue().isStrictlyPositive()) {
2642 if (RHSC->getValue().isNonNegative()) {
2653 bool KnownNonNegative, KnownNegative;
2659 ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2661 if (!KnownNonNegative)
2670 ComputeSignBit(RHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2672 if (!KnownNonNegative)
2684 bool KnownNonNegative, KnownNegative;
2690 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2692 if (!KnownNonNegative)
2701 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.DL, 0, Q.AC,
2703 if (!KnownNonNegative)
2727 if (
auto *CI = dyn_cast<ConstantInt>(RHS)) {
2728 const APInt *CI2Val, *CIVal = &CI->getValue();
2741 *CI2Val == 1 || !CI->isZero()) {
2748 if (CIVal->
isSignBit() && *CI2Val == 1) {
2757 if (MaxRecurse && LBO && RBO && LBO->
getOpcode() == RBO->getOpcode() &&
2761 case Instruction::UDiv:
2762 case Instruction::LShr:
2766 case Instruction::SDiv:
2767 case Instruction::AShr:
2768 if (!LBO->
isExact() || !RBO->isExact())
2771 RBO->getOperand(0), Q, MaxRecurse-1))
2774 case Instruction::Shl: {
2782 RBO->getOperand(0), Q, MaxRecurse-1))
2801 (A == LHS || B == LHS)) {
2807 (A == RHS || B == RHS)) {
2814 (A == LHS || B == LHS)) {
2871 (A == LHS || B == LHS)) {
2877 (A == RHS || B == RHS)) {
2884 (A == LHS || B == LHS)) {
2937 (A == C || A == D || B == C || B == D)) {
2947 (A == C || A == D || B == C || B == D)) {
2957 (A == C || A == D || B == C || B == D)) {
2967 (A == C || A == D || B == C || B == D)) {
2984 if (
GEPOperator *GRHS = dyn_cast<GEPOperator>(RHS)) {
2985 if (GLHS->getPointerOperand() == GRHS->getPointerOperand() &&
2986 GLHS->hasAllConstantIndices() && GRHS->hasAllConstantIndices() &&
2988 (GLHS->isInBounds() && GRHS->isInBounds() &&
2996 GLHS->getSourceElementType(), Null, IndicesLHS);
3000 GLHS->getSourceElementType(), Null, IndicesRHS);
3009 if (
ConstantInt *CI = dyn_cast<ConstantInt>(RHS)) {
3010 uint32_t BitWidth = CI->getBitWidth();
3011 APInt LHSKnownZero(BitWidth, 0);
3012 APInt LHSKnownOne(BitWidth, 0);
3015 const APInt &RHSVal = CI->getValue();
3016 if (((LHSKnownZero & RHSVal) != 0) || ((LHSKnownOne & ~RHSVal) != 0))
3025 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3031 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3051 unsigned MaxRecurse) {
3055 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
3056 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
3080 if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS)) {
3095 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(RHS)) {
3097 if (CFP->getValueAPF().isNaN()) {
3101 "Comparison must be either ordered or unordered!");
3106 if (CFP->getValueAPF().isInfinity()) {
3107 if (CFP->getValueAPF().isNegative()) {
3131 if (CFP->getValueAPF().isZero()) {
3150 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3156 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3176 unsigned MaxRecurse) {
3186 if (
auto *B = dyn_cast<BinaryOperator>(
I)) {
3193 if (isa<OverflowingBinaryOperator>(B))
3194 if (B->hasNoSignedWrap() || B->hasNoUnsignedWrap())
3196 if (isa<PossiblyExactOperator>(B))
3201 if (B->getOperand(0) == Op)
3202 return SimplifyBinOp(B->getOpcode(), RepOp, B->getOperand(1), Q,
3204 if (B->getOperand(1) == Op)
3205 return SimplifyBinOp(B->getOpcode(), B->getOperand(0), RepOp, Q,
3211 if (
CmpInst *C = dyn_cast<CmpInst>(
I)) {
3213 if (C->getOperand(0) == Op)
3216 if (C->getOperand(1) == Op)
3226 if (
Constant *CRepOp = dyn_cast<Constant>(RepOp)) {
3229 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i) {
3230 if (
I->getOperand(i) == Op)
3232 else if (
Constant *COp = dyn_cast<Constant>(
I->getOperand(i)))
3239 if (ConstOps.
size() ==
I->getNumOperands()) {
3240 if (
CmpInst *C = dyn_cast<CmpInst>(
I))
3242 ConstOps[1], Q.DL, Q.TLI);
3244 if (
LoadInst *LI = dyn_cast<LoadInst>(
I))
3245 if (!LI->isVolatile())
3259 Value *FalseVal,
const Query &Q,
3260 unsigned MaxRecurse) {
3263 if (
Constant *CB = dyn_cast<Constant>(CondVal)) {
3264 if (CB->isAllOnesValue())
3266 if (CB->isNullValue())
3271 if (TrueVal == FalseVal)
3274 if (isa<UndefValue>(CondVal)) {
3275 if (isa<Constant>(TrueVal))
3279 if (isa<UndefValue>(TrueVal))
3281 if (isa<UndefValue>(FalseVal))
3284 if (
const auto *ICI = dyn_cast<ICmpInst>(CondVal)) {
3285 unsigned BitWidth = Q.DL.getTypeSizeInBits(TrueVal->
getType());
3287 Value *CmpLHS = ICI->getOperand(0);
3288 Value *CmpRHS = ICI->getOperand(1);
3293 bool IsBitTest =
false;
3301 Y = &MinSignedValue;
3303 TrueWhenUnset =
false;
3306 Y = &MinSignedValue;
3308 TrueWhenUnset =
true;
3316 return TrueWhenUnset ? FalseVal : TrueVal;
3321 return TrueWhenUnset ? FalseVal : TrueVal;
3328 return TrueWhenUnset ? TrueVal : FalseVal;
3333 return TrueWhenUnset ? TrueVal : FalseVal;
3336 if (ICI->hasOneUse()) {
3397 const Query &Q,
unsigned) {
3400 cast<PointerType>(Ops[0]->getType()->getScalarType())->getAddressSpace();
3403 if (Ops.
size() == 1)
3412 if (isa<UndefValue>(Ops[0]))
3415 if (Ops.
size() == 2) {
3424 uint64_t TyAllocSize = Q.DL.getTypeAllocSize(Ty);
3426 if (TyAllocSize == 0)
3431 if (Ops[1]->
getType()->getScalarSizeInBits() ==
3432 Q.DL.getPointerSizeInBits(AS)) {
3433 auto PtrToIntOrZero = [GEPTy](
Value *
P) ->
Value * {
3444 if (TyAllocSize == 1 &&
3446 if (
Value *R = PtrToIntOrZero(P))
3454 TyAllocSize == 1ULL << C)
3455 if (
Value *R = PtrToIntOrZero(P))
3463 if (
Value *R = PtrToIntOrZero(P))
3470 for (
unsigned i = 0, e = Ops.
size(); i != e; ++i)
3471 if (!isa<Constant>(Ops[i]))
3483 cast<PointerType>(Ops[0]->
getType()->getScalarType())->getElementType(),
3492 if (
Constant *CAgg = dyn_cast<Constant>(Agg))
3493 if (
Constant *CVal = dyn_cast<Constant>(Val))
3502 if (EV->getAggregateOperand()->getType() == Agg->
getType() &&
3503 EV->getIndices() == Idxs) {
3506 return EV->getAggregateOperand();
3509 if (Agg == EV->getAggregateOperand())
3527 const Query &,
unsigned) {
3528 if (
auto *CAgg = dyn_cast<Constant>(Agg))
3532 unsigned NumIdxs = Idxs.
size();
3533 for (
auto *IVI = dyn_cast<InsertValueInst>(Agg); IVI !=
nullptr;
3536 unsigned NumInsertValueIdxs = InsertValueIdxs.
size();
3537 unsigned NumCommonIdxs =
std::min(NumInsertValueIdxs, NumIdxs);
3538 if (InsertValueIdxs.
slice(0, NumCommonIdxs) ==
3539 Idxs.
slice(0, NumCommonIdxs)) {
3540 if (NumIdxs == NumInsertValueIdxs)
3541 return IVI->getInsertedValueOperand();
3563 if (
auto *CVec = dyn_cast<Constant>(Vec)) {
3564 if (
auto *CIdx = dyn_cast<Constant>(Idx))
3568 if (
auto *Splat = CVec->getSplatValue())
3571 if (isa<UndefValue>(Vec))
3577 if (
auto *IdxC = dyn_cast<ConstantInt>(Idx))
3595 Value *CommonValue =
nullptr;
3596 bool HasUndefInput =
false;
3599 if (Incoming == PN)
continue;
3600 if (isa<UndefValue>(Incoming)) {
3602 HasUndefInput =
true;
3605 if (CommonValue && Incoming != CommonValue)
3607 CommonValue = Incoming;
3625 if (
Constant *C = dyn_cast<Constant>(Op))
3644 const Query &Q,
unsigned MaxRecurse) {
3646 case Instruction::Add:
3649 case Instruction::FAdd:
3652 case Instruction::Sub:
3655 case Instruction::FSub:
3658 case Instruction::Mul:
return SimplifyMulInst (LHS, RHS, Q, MaxRecurse);
3659 case Instruction::FMul:
3663 case Instruction::FDiv:
3667 case Instruction::FRem:
3669 case Instruction::Shl:
3672 case Instruction::LShr:
3674 case Instruction::AShr:
3680 if (
Constant *CLHS = dyn_cast<Constant>(LHS))
3681 if (
Constant *CRHS = dyn_cast<Constant>(RHS)) {
3694 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
3700 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
3714 unsigned MaxRecurse) {
3716 case Instruction::FAdd:
3718 case Instruction::FSub:
3720 case Instruction::FMul:
3747 const Query &Q,
unsigned MaxRecurse) {
3763 default:
return false;
3766 case Intrinsic::fabs:
3767 case Intrinsic::floor:
3768 case Intrinsic::ceil:
3769 case Intrinsic::trunc:
3770 case Intrinsic::rint:
3771 case Intrinsic::nearbyint:
3772 case Intrinsic::round:
3777 template <
typename IterTy>
3779 const Query &Q,
unsigned MaxRecurse) {
3781 unsigned NumOperands = std::distance(ArgBegin, ArgEnd);
3785 if (NumOperands == 2) {
3786 Value *LHS = *ArgBegin;
3787 Value *RHS = *(ArgBegin + 1);
3788 if (IID == Intrinsic::usub_with_overflow ||
3789 IID == Intrinsic::ssub_with_overflow) {
3796 if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS))
3800 if (IID == Intrinsic::uadd_with_overflow ||
3801 IID == Intrinsic::sadd_with_overflow) {
3803 if (isa<UndefValue>(RHS))
3807 if (IID == Intrinsic::umul_with_overflow ||
3808 IID == Intrinsic::smul_with_overflow) {
3824 if (NumOperands == 1)
3826 if (II->getIntrinsicID() == IID)
3832 template <
typename IterTy>
3834 const Query &Q,
unsigned MaxRecurse) {
3837 Ty = PTy->getElementType();
3841 if (isa<UndefValue>(V))
3856 ConstantArgs.
reserve(ArgEnd - ArgBegin);
3857 for (IterTy
I = ArgBegin, E = ArgEnd;
I != E; ++
I) {
3894 case Instruction::FAdd:
3898 case Instruction::Add:
3900 cast<BinaryOperator>(
I)->hasNoSignedWrap(),
3901 cast<BinaryOperator>(
I)->hasNoUnsignedWrap(), DL,
3904 case Instruction::FSub:
3908 case Instruction::Sub:
3910 cast<BinaryOperator>(
I)->hasNoSignedWrap(),
3911 cast<BinaryOperator>(
I)->hasNoUnsignedWrap(), DL,
3914 case Instruction::FMul:
3918 case Instruction::Mul:
3922 case Instruction::SDiv:
3926 case Instruction::UDiv:
3930 case Instruction::FDiv:
3934 case Instruction::SRem:
3938 case Instruction::URem:
3942 case Instruction::FRem:
3946 case Instruction::Shl:
3948 cast<BinaryOperator>(
I)->hasNoSignedWrap(),
3949 cast<BinaryOperator>(
I)->hasNoUnsignedWrap(), DL,
3952 case Instruction::LShr:
3954 cast<BinaryOperator>(
I)->isExact(), DL, TLI, DT,
3957 case Instruction::AShr:
3959 cast<BinaryOperator>(
I)->isExact(), DL, TLI, DT,
3974 case Instruction::ICmp:
3979 case Instruction::FCmp:
3988 case Instruction::GetElementPtr: {
3993 case Instruction::InsertValue: {
4000 case Instruction::ExtractValue: {
4001 auto *EVI = cast<ExtractValueInst>(
I);
4003 EVI->getIndices(), DL, TLI, DT, AC,
I);
4007 auto *EEI = cast<ExtractElementInst>(
I);
4009 EEI->getVectorOperand(), EEI->getIndexOperand(), DL, TLI, DT, AC,
I);
4013 Result =
SimplifyPHINode(cast<PHINode>(I), Query(DL, TLI, DT, AC, I));
4021 case Instruction::Trunc:
4057 Worklist.
insert(cast<Instruction>(U));
4071 for (
unsigned Idx = 0; Idx != Worklist.
size(); ++Idx) {
4085 Worklist.
insert(cast<Instruction>(U));
4109 assert(I != SimpleV &&
"replaceAndRecursivelySimplify(X,X) is not valid!");
4110 assert(SimpleV &&
"Must provide a simplified value.");
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
static Value * SimplifyBinOp(unsigned, Value *, Value *, const Query &, unsigned)
SimplifyBinOp - Given operands for a BinaryOperator, see if we can fold the result.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
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.
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
static const Value * SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const Query &Q, unsigned MaxRecurse)
SimplifyWithOpReplaced - See if V simplifies when its operand Op is replaced with RepOp...
Value * SimplifyCall(Value *V, User::op_iterator ArgBegin, User::op_iterator ArgEnd, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given a function and iterators over arguments, see if we can fold the result.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const
Get the absolute value;.
Value * SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, Instruction *CxtI=nullptr)
SimplifyICmpInst - Given operands for an ICmpInst, see if we can fold the result. ...
static Constant * computePointerICmp(const DataLayout &DL, const TargetLibraryInfo *TLI, CmpInst::Predicate Pred, Value *LHS, Value *RHS)
static Value * SimplifyAddInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const Query &Q, unsigned MaxRecurse)
SimplifyAddInst - Given operands for an Add, see if we can fold the result.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
LLVM Argument representation.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Value * getAggregateOperand()
static const Value * getFNegArgument(const Value *BinOp)
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
STATISTIC(NumFunctions,"Total number of functions")
ArrayRef< unsigned > getIndices() const
bool canConstantFoldCallTo(const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
static Value * SimplifyCmpInst(unsigned, Value *, Value *, const Query &, unsigned)
SimplifyCmpInst - Given operands for a CmpInst, see if we can fold the result.
static Value * SimplifyAndInst(Value *, Value *, const Query &, unsigned)
SimplifyAndInst - Given operands for an And, see if we can fold the result.
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
match_zero m_Zero()
Match an arbitrary zero/null constant.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
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 bool isOrdered(unsigned short predicate)
Determine if the predicate is an ordered operation.
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL, const TargetLibraryInfo *TLI, bool RoundToAlign=false)
Compute the size of the object pointed by Ptr.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices...
static Value * SimplifyAssociativeBinOp(unsigned Opc, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
SimplifyAssociativeBinOp - Generic simplifications for associative binary operations.
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)
void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
Value * SimplifySDivInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifySDivInst - Given operands for an SDiv, see if we can fold the result.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
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
Type * getReturnType() const
Value * SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyFCmpInst - Given operands for an FCmpInst, see if we can fold the result. ...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
const Function * getParent() const
Return the enclosing method, or null if none.
This class represents a sign extension of integer types.
bool isNoAliasCall(const Value *V)
isNoAliasCall - Return true if this pointer is returned by a noalias function.
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
LoadInst - an instruction for reading from memory.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
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 * SimplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1)
static Constant * getTrue(Type *Ty)
getTrue - For a boolean type, or a vector of boolean type, return true, or a vector with every elemen...
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Value * SimplifyAddInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyAddInst - Given operands for an Add, see if we can fold the result.
static Value * SimplifySubInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const Query &Q, unsigned MaxRecurse)
SimplifySubInst - Given operands for a Sub, see if we can fold the result.
void reserve(size_type N)
static Value * SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, const Query &Q, unsigned MaxRecurse)
SimplifyLShrInst - Given operands for an LShr, see if we can fold the result.
size_type size() const
Determine the number of elements in the SetVector.
static Value * SimplifyXorInst(Value *, Value *, const Query &, unsigned)
SimplifyXorInst - Given operands for a Xor, see if we can fold the result.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const Query &, unsigned)
SimplifyExtractValueInst - Given operands for an ExtractValueInst, see if we can fold the result...
static Constant * getNullValue(Type *Ty)
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool isNegative() const
Determine sign of this APInt.
static Value * ThreadCmpOverPHI(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
ThreadCmpOverPHI - In the case of a comparison with a PHI instruction, try try to simplify the compar...
bool match(Val *V, const Pattern &P)
static Value * SimplifySDivInst(Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifySDivInst - Given operands for an SDiv, see if we can fold the result.
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
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.
SelectInst - This class represents the LLVM 'select' instruction.
bool noSignedZeros() const
const APInt & getValue() const
Return the constant as an APInt value reference.
static Value * SimplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned)
Exact_match< T > m_Exact(const T &SubPattern)
BinOp2_match< LHS, RHS, Instruction::LShr, Instruction::AShr > m_Shr(const LHS &L, const RHS &R)
Matches LShr or AShr.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
Value * SimplifyFSubInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an FSub, see if we can fold the result.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
Constant * ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout &DL)
ConstantFoldLoadFromConstPtr - Return the value that a load from C would produce if it is constant an...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
Value * SimplifyFAddInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an FAdd, see if we can fold the result.
bool isSized(SmallPtrSetImpl< const Type * > *Visited=nullptr) const
isSized - Return true if it makes sense to take the size of this type.
bool MaskedValueIsZero(Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
MaskedValueIsZero - Return true if 'V & Mask' is known to be zero.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static Value * SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
SimplifyICmpInst - Given operands for an ICmpInst, see if we can fold the result. ...
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
Type * getVectorElementType() const
static Value * SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, const Query &Q, unsigned MaxRecurse)
SimplifyAShrInst - Given operands for an AShr, see if we can fold the result.
not_match< LHS > m_Not(const LHS &L)
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 Value * SimplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
Given operands for an FAdd, see if we can fold the result.
FunctionType - Class to represent function types.
bool insert(const value_type &X)
Insert a new element into the SetVector.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
ValTy * getCalledValue() const
getCalledValue - Return the pointer to function that is being called.
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)
ExtractEquivalentCondition - Rummage around inside V looking for something equivalent to the comparis...
bool isAssociative() const
isAssociative - Return true if the instruction is associative:
static Value * SimplifyPHINode(PHINode *PN, const Query &Q)
SimplifyPHINode - See if we can fold the given phi. If not, returns null.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool isKnownToBeAPowerOfTwo(Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
isKnownToBeAPowerOfTwo - Return true if the given value is known to have exactly one bit set when def...
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)
static Value * SimplifyTruncInst(Value *, Type *, const Query &, unsigned)
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.
Value * SimplifyFMulInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an FMul, see if we can fold the result.
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
APInt LLVM_ATTRIBUTE_UNUSED_RESULT shl(unsigned shiftAmt) const
Left-shift function.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static Value * ThreadBinOpOverSelect(unsigned Opcode, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
ThreadBinOpOverSelect - In the case of a binary operation with a select instruction as an operand...
static Value * SimplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
Given operands for an FSub, see if we can fold the result.
APInt umul_ov(const APInt &RHS, bool &Overflow) const
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
static Value * SimplifyOrInst(Value *, Value *, const Query &, unsigned)
SimplifyOrInst - Given operands for an Or, see if we can fold the result.
size_t size() const
size - Get the array size.
static Value * SimplifyURemInst(Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifyURemInst - Given operands for a URem, see if we can fold the result.
PointerType - Class to represent pointers.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
Value * findScalarElement(Value *V, unsigned EltNo)
Given a vector and an element number, see if the scalar value is already around as a register...
Value * SimplifyOrInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyOrInst - Given operands for an Or, see if we can fold the result.
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
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)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
static Value * SimplifySelectInst(Value *CondVal, Value *TrueVal, Value *FalseVal, const Query &Q, unsigned MaxRecurse)
SimplifySelectInst - Given operands for a SelectInst, see if we can fold the result.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
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)
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
bool isEquality() const
isEquality - 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.
This is an important base class in LLVM.
static Value * SimplifyCall(Value *V, IterTy ArgBegin, IterTy ArgEnd, const Query &Q, unsigned MaxRecurse)
bool isMaxSignedValue() const
Determine if this is the largest signed value.
const Value * getCondition() const
static Value * ThreadCmpOverSelect(CmpInst::Predicate Pred, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
ThreadCmpOverSelect - In the case of a comparison with a select instruction, try to simplify the comp...
static Value * SimplifySRemInst(Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifySRemInst - Given operands for an SRem, see if we can fold the result.
static Value * SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
SimplifyFCmpInst - Given operands for an FCmpInst, see if we can fold the result. ...
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
static Value * SimplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF, const Query &Q, unsigned MaxRecurse)
Given the operands for an FMul, see if we can fold the result.
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static Value * SimplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifyDiv - Given operands for an SDiv or UDiv, see if we can fold the result.
Constant * ConstantFoldInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstruction - Try to constant fold the specified instruction.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set to true.
bool isIntPredicate() const
Value * SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyShlInst - Given operands for a Shl, see if we can fold the result.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
bool isFalseWhenEqual() const
This is just a convenience.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Utility class for integer arithmetic operators which may exhibit overflow - Add, Sub, and Mul.
bool isMaxValue() const
Determine if this is the largest unsigned value.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT sdiv(const APInt &RHS) const
Signed division function for APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
Value * SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS, const FastMathFlags &FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyFPBinOp - Given operands for a BinaryOperator, see if we can fold the result.
bool isCommutative() const
isCommutative - Return true if the instruction is commutative:
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)
ValueDominatesPHI - Does the given value dominate the specified phi node?
void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeSignBit - Determine whether the sign bit is known to be zero or one.
Constant * getAggregateElement(unsigned Elt) const
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to th...
Value * SimplifySRemInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifySRemInst - Given operands for an SRem, see if we can fold the result.
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
static Value * SimplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Query &Q, unsigned)
SimplifyInsertValueInst - Given operands for an InsertValueInst, see if we can fold the result...
match_combine_or< match_zero, match_neg_zero > m_AnyZero()
Match an arbitrary zero/null constant.
bool isEmptySet() const
Return true if this set contains no members.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
Value * SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifySelectInst - Given operands for a SelectInst, see if we can fold the result.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
static Value * SimplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1)
LLVMContext & getContext() const
All values hold a context through their type.
bool hasNoSignedWrap() const
Determine whether the no signed wrap flag is set.
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 * ExpandBinOp(unsigned Opcode, Value *LHS, Value *RHS, unsigned OpcToExpand, const Query &Q, unsigned MaxRecurse)
ExpandBinOp - Simplify "A op (B op' C)" by distributing op over op', turning it into "(A op B) op'...
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.
static Value * SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd, const Query &Q, unsigned MaxRecurse)
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
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...
static Value * SimplifyUDivInst(Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifyUDivInst - Given operands for a UDiv, see if we can fold the result.
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
static Constant * getSplat(unsigned NumElts, Constant *Elt)
getSplat - Return a ConstantVector with the specified constant in each element.
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
static Value * SimplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifyRem - Given operands for an SRem or URem, see if we can fold the result.
This is the shared class of boolean and integer constants.
static Value * SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, const Query &Q, unsigned MaxRecurse)
SimplifyShlInst - Given operands for an Shl, see if we can fold the result.
unsigned getVectorNumElements() const
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Constant * ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands...
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.
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
This class represents a range of values.
Value * SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyCmpInst - Given operands for a CmpInst, see if we can fold the result.
unsigned ComputeNumSignBits(Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
ComputeNumSignBits - Return the number of times the sign bit of the register is replicated into the o...
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isTrueWhenEqual() const
This is just a convenience.
Value * SimplifyGEPInst(ArrayRef< Value * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can fold the result...
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
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.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Value * SimplifyInsertValueInst(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyInsertValueInst - Given operands for an InsertValueInst, see if we can fold the result...
static Value * SimplifyShift(unsigned Opcode, Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifyShift - Given operands for an Shl, LShr or AShr, see if we can fold the result.
const BasicBlock & getEntryBlock() const
static Constant * get(Type *Ty, double V)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
bool isExact() const
Determine whether the exact flag is set.
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...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
VectorType - Class to represent vector types.
Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an ExtractElementInst, see if we can fold the result.
Class for arbitrary precision integers.
static Constant * getFalse(Type *Ty)
getFalse - For a boolean type, or a vector of boolean type, return false, or a vector with every elem...
static Value * SimplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF, const Query &, unsigned)
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
iterator_range< user_iterator > users()
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyBinOp - Given operands for a BinaryOperator, see if we can fold the result.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * SimplifySubInst(Value *LHS, Value *RHS, bool isNSW, bool isNUW, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifySubInst - Given operands for a Sub, see if we can fold the result.
bool isMinValue() const
Determine if this is the smallest unsigned value.
bool isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI=nullptr)
isKnownNonNull - Return true if this pointer couldn't possibly be null by its definition.
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
bool isFPPredicate() const
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Value * SimplifyTruncInst(Value *Op, Type *Ty, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyTruncInst - Given operands for an TruncInst, see if we can fold the result.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
bool isKnownNonZero(Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
isKnownNonZero - Return true if the given value is known to be non-zero when defined.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
bool isAllOnesValue() const
Determine if all bits are set.
unsigned countLeadingOnes() const
Count the number of leading one bits.
bool CannotBeOrderedLessThanZero(const Value *V, unsigned Depth=0)
CannotBeOrderedLessThanZero - Return true if we can prove that the specified FP value is either a NaN...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static Constant * computePointerDifference(const DataLayout &DL, Value *LHS, Value *RHS)
Compute the constant difference between two pointer values.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Value * SimplifyAndInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyAndInst - Given operands for an And, see if we can fold the result.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT udiv(const APInt &RHS) const
Unsigned division operation.
static Value * SimplifyGEPInst(Type *SrcTy, ArrayRef< Value * > Ops, const Query &Q, unsigned)
SimplifyGEPInst - Given operands for an GetElementPtrInst, see if we can fold the result...
static Value * SimplifyFPBinOp(unsigned, Value *, Value *, const FastMathFlags &, const Query &, unsigned)
SimplifyFPBinOp - Given operands for a BinaryOperator, see if we can fold the result.
unsigned greater or equal
static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI, const DominatorTree *DT, AssumptionCache *AC)
Implementation of recursive simplification through an instructions uses.
static bool isFNeg(const Value *V, bool IgnoreZeroSign=false)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
bool hasNoInfs() const
Determine whether the no-infs flag is set.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
bool isSignBit() const
Check if the APInt's value is returned by getSignBit.
Value * SimplifyURemInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyURemInst - Given operands for a URem, see if we can fold the result.
static Value * SimplifyMulInst(Value *Op0, Value *Op1, const Query &Q, unsigned MaxRecurse)
SimplifyMulInst - Given operands for a Mul, see if we can fold the result.
static ConstantRange makeConstantRange(Predicate pred, const APInt &C)
Initialize a set of values that all satisfy the predicate with C.
static bool IsIdempotent(Intrinsic::ID ID)
Value * SimplifyMulInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyMulInst - Given operands for a Mul, see if we can fold the result.
Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an ExtractValueInst, see if we can fold the result.
static Value * SimplifyExtractElementInst(Value *Vec, Value *Idx, const Query &, unsigned)
SimplifyExtractElementInst - Given operands for an ExtractElementInst, see if we can fold the result...
Value * SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyLShrInst - Given operands for a LShr, see if we can fold the result.
bool all_of(R &&Range, UnaryPredicate &&P)
Provide wrappers to std::all_of which take ranges instead of having to pass being/end explicitly...
Value * SimplifyUDivInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyUDivInst - Given operands for a UDiv, see if we can fold the result.
BinOp2_match< LHS, RHS, Instruction::SDiv, Instruction::UDiv > m_IDiv(const LHS &L, const RHS &R)
Matches UDiv and SDiv.
bool CannotBeNegativeZero(const Value *V, unsigned Depth=0)
CannotBeNegativeZero - Return true if we can prove that the specified FP value is never equal to -0...
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
Value * SimplifyXorInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyXorInst - Given operands for a Xor, see if we can fold the result.
match_neg_zero m_NegZero()
Match an arbitrary zero/null constant.
Type * getReturnType() const
Value * SimplifyFRemInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyFRemInst - Given operands for an FRem, see if we can fold the result.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
LLVM Value Representation.
Value * SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyAShrInst - Given operands for a AShr, see if we can fold the result.
bool hasNoUnsignedWrap() const
Determine whether the no unsigned wrap flag is set.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
static Value * SimplifyRightShift(unsigned Opcode, Value *Op0, Value *Op1, bool isExact, const Query &Q, unsigned MaxRecurse)
Given operands for an Shl, LShr or AShr, see if we can fold the result.
static bool isUnordered(unsigned short predicate)
Determine if the predicate is an unordered operation.
static Value * ThreadBinOpOverPHI(unsigned Opcode, Value *LHS, Value *RHS, const Query &Q, unsigned MaxRecurse)
ThreadBinOpOverPHI - In the case of a binary operation with an operand that is a PHI instruction...
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
const Value * getFalseValue() const
Convenience struct for specifying and reasoning about fast-math flags.
static bool isUndefShift(Value *Amount)
isUndefShift - 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...
Value * SimplifyInstruction(Instruction *I, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
SimplifyInstruction - See if we can compute a simplified version of this instruction.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
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.
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()
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...
0 0 0 0 Always false (always folded)
bool noNaNs() const
Flag queries.
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
Constant * ConstantFoldCall(Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
Value * SimplifyFDivInst(Value *LHS, Value *RHS, FastMathFlags FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
SimplifyFDivInst - Given operands for an FDiv, see if we can fold the result.
AllocaInst - an instruction to allocate memory on the stack.
InsertValueInst - This instruction inserts a struct field of array element value into an aggregate va...
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)