25 using namespace PatternMatch;
58 Constant *In2,
bool IsSigned =
false) {
62 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
74 cast<ConstantInt>(In1), cast<ConstantInt>(In2),
93 Constant *In2,
bool IsSigned =
false) {
97 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
109 cast<ConstantInt>(In1), cast<ConstantInt>(In2),
118 bool &TrueIfSigned) {
127 TrueIfSigned =
false;
170 return (~CI->
getValue() + 1).isPowerOf2();
178 const APInt& KnownOne,
183 "KnownZero, KnownOne and Min, Max must have equal bitwidth.");
184 APInt UnknownBits = ~(KnownZero|KnownOne);
189 Max = KnownOne|UnknownBits;
191 if (UnknownBits.isNegative()) {
202 const APInt &KnownOne,
207 "Ty, KnownZero, KnownOne and Min, Max must have equal bitwidth.");
208 APInt UnknownBits = ~(KnownZero|KnownOne);
213 Max = KnownOne|UnknownBits;
234 if (!isa<ConstantArray>(Init) && !isa<ConstantDataArray>(Init))
238 if (ArrayElementCount > 1024)
return 0;
258 if (Idx == 0)
return 0;
261 if ((
unsigned)IdxVal != IdxVal)
return 0;
263 if (
StructType *STy = dyn_cast<StructType>(EltTy))
264 EltTy = STy->getElementType(IdxVal);
265 else if (
ArrayType *ATy = dyn_cast<ArrayType>(EltTy)) {
266 if (IdxVal >= ATy->getNumElements())
return 0;
267 EltTy = ATy->getElementType();
275 enum { Overdefined = -3, Undefined = -2 };
284 int FirstTrueElement = Undefined, SecondTrueElement = Undefined;
288 int FirstFalseElement = Undefined, SecondFalseElement = Undefined;
296 int TrueRangeEnd = Undefined, FalseRangeEnd = Undefined;
301 uint64_t MagicBitvector = 0;
306 for (
unsigned i = 0, e = ArrayElementCount; i != e; ++i) {
308 if (Elt == 0)
return 0;
311 if (!LaterIndices.
empty())
319 CompareRHS,
TD, TLI);
321 if (isa<UndefValue>(C)) {
324 if (TrueRangeEnd == (
int)i-1)
326 if (FalseRangeEnd == (
int)i-1)
333 if (!isa<ConstantInt>(C))
return 0;
337 bool IsTrueForElt = !cast<ConstantInt>(
C)->
isZero();
342 if (FirstTrueElement == Undefined)
343 FirstTrueElement = TrueRangeEnd = i;
346 if (SecondTrueElement == Undefined)
347 SecondTrueElement = i;
349 SecondTrueElement = Overdefined;
352 if (TrueRangeEnd == (
int)i-1)
355 TrueRangeEnd = Overdefined;
359 if (FirstFalseElement == Undefined)
360 FirstFalseElement = FalseRangeEnd = i;
363 if (SecondFalseElement == Undefined)
364 SecondFalseElement = i;
366 SecondFalseElement = Overdefined;
369 if (FalseRangeEnd == (
int)i-1)
372 FalseRangeEnd = Overdefined;
378 if (i < 64 && IsTrueForElt)
379 MagicBitvector |= 1ULL << i;
384 if ((i & 8) == 0 && i >= 64 && SecondTrueElement == Overdefined &&
385 SecondFalseElement == Overdefined && TrueRangeEnd == Overdefined &&
386 FalseRangeEnd == Overdefined)
401 Idx = Builder->CreateTrunc(Idx, IntPtrTy);
406 if (SecondTrueElement != Overdefined) {
408 if (FirstTrueElement == Undefined)
409 return ReplaceInstUsesWith(ICI, Builder->getFalse());
414 if (SecondTrueElement == Undefined)
418 Value *C1 = Builder->CreateICmpEQ(Idx, FirstTrueIdx);
420 Value *C2 = Builder->CreateICmpEQ(Idx, SecondTrueIdx);
421 return BinaryOperator::CreateOr(C1, C2);
426 if (SecondFalseElement != Overdefined) {
428 if (FirstFalseElement == Undefined)
429 return ReplaceInstUsesWith(ICI, Builder->getTrue());
434 if (SecondFalseElement == Undefined)
438 Value *C1 = Builder->CreateICmpNE(Idx, FirstFalseIdx);
440 Value *C2 = Builder->CreateICmpNE(Idx, SecondFalseIdx);
441 return BinaryOperator::CreateAnd(C1, C2);
446 if (TrueRangeEnd != Overdefined) {
447 assert(TrueRangeEnd != FirstTrueElement &&
"Should emit single compare");
450 if (FirstTrueElement) {
452 Idx = Builder->CreateAdd(Idx, Offs);
456 TrueRangeEnd-FirstTrueElement+1);
461 if (FalseRangeEnd != Overdefined) {
462 assert(FalseRangeEnd != FirstFalseElement &&
"Should emit single compare");
464 if (FirstFalseElement) {
466 Idx = Builder->CreateAdd(Idx, Offs);
470 FalseRangeEnd-FirstFalseElement);
485 if (ArrayElementCount <= Idx->
getType()->getIntegerBitWidth())
488 Ty =
TD->getSmallestLegalIntType(Init->
getContext(), ArrayElementCount);
489 else if (ArrayElementCount <= 32)
493 Value *V = Builder->CreateIntCast(Idx, Ty,
false);
525 for (i = 1; i != e; ++i, ++GTI) {
528 if (CI->isZero())
continue;
531 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
535 Offset += Size*CI->getSExtValue();
545 if (i == e)
return 0;
553 for (++i, ++GTI; i != e; ++i, ++GTI) {
558 if (CI->
isZero())
continue;
561 if (
StructType *STy = dyn_cast<StructType>(*GTI)) {
588 uint64_t PtrSizeMask = ~0ULL >> (64-IntPtrWidth);
590 Offset &= PtrSizeMask;
591 VariableScale &= PtrSizeMask;
597 int64_t NewOffs = Offset / (int64_t)VariableScale;
598 if (Offset != NewOffs*(int64_t)VariableScale)
602 if (VariableIdx->
getType() != IntPtrTy)
624 RHS = BCI->getOperand(0);
639 }
else if (
GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) {
642 if (PtrBase != GEPRHS->getOperand(0)) {
643 bool IndicesTheSame = GEPLHS->
getNumOperands()==GEPRHS->getNumOperands();
645 GEPRHS->getOperand(0)->getType();
648 if (GEPLHS->
getOperand(i) != GEPRHS->getOperand(i)) {
649 IndicesTheSame =
false;
660 if (
TD && GEPLHS->
isInBounds() && GEPRHS->isInBounds() &&
662 (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse()) &&
668 return ReplaceInstUsesWith(I, Cmp);
677 bool AllZeros =
true;
680 !cast<Constant>(GEPLHS->
getOperand(i))->isNullValue()) {
685 return FoldGEPICmp(GEPRHS, GEPLHS->
getOperand(0),
690 for (
unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)
691 if (!isa<Constant>(GEPRHS->getOperand(i)) ||
692 !cast<Constant>(GEPRHS->getOperand(i))->isNullValue()) {
697 return FoldGEPICmp(GEPLHS, GEPRHS->
getOperand(0), Cond,
I);
699 bool GEPsInBounds = GEPLHS->
isInBounds() && GEPRHS->isInBounds();
702 unsigned NumDifferences = 0;
703 unsigned DiffOperand = 0;
704 for (
unsigned i = 1, e = GEPRHS->getNumOperands(); i != e; ++i)
705 if (GEPLHS->
getOperand(i) != GEPRHS->getOperand(i)) {
707 GEPRHS->getOperand(i)->getType()->getPrimitiveSizeInBits()) {
712 if (NumDifferences++)
break;
717 if (NumDifferences == 0)
718 return ReplaceInstUsesWith(I,
721 else if (NumDifferences == 1 && GEPsInBounds) {
723 Value *RHSV = GEPRHS->getOperand(DiffOperand);
733 (isa<ConstantExpr>(GEPLHS) || GEPLHS->
hasOneUse()) &&
734 (isa<ConstantExpr>(GEPRHS) || GEPRHS->hasOneUse())) {
757 return ReplaceInstUsesWith(ICI, Builder->getFalse());
761 return ReplaceInstUsesWith(ICI, Builder->getTrue());
822 bool DivIsSigned = DivI->
getOpcode() == Instruction::SDiv;
829 if (DivRHS->
isOne()) {
861 int LoOverflow = 0, HiOverflow = 0;
862 Constant *LoBound = 0, *HiBound = 0;
867 HiOverflow = LoOverflow = ProdOV;
879 }
else if (CmpRHSV.isStrictlyPositive()) {
881 HiOverflow = LoOverflow = ProdOV;
887 LoOverflow = HiOverflow = ProdOV ? -1 : 0;
898 LoBound =
AddOne(RangeSize);
900 if (HiBound == DivRHS) {
904 }
else if (CmpRHSV.isStrictlyPositive()) {
907 HiOverflow = LoOverflow = ProdOV ? -1 : 0;
909 LoOverflow =
AddWithOverflow(LoBound, HiBound, RangeSize,
true) ? -1:0;
912 LoOverflow = HiOverflow = ProdOV;
925 if (LoOverflow && HiOverflow)
926 return ReplaceInstUsesWith(ICI, Builder->getFalse());
933 return ReplaceInstUsesWith(ICI, InsertRangeTest(X, LoBound, HiBound,
936 if (LoOverflow && HiOverflow)
937 return ReplaceInstUsesWith(ICI, Builder->getTrue());
940 ICmpInst::ICMP_ULT, X, LoBound);
943 ICmpInst::ICMP_UGE, X, HiBound);
944 return ReplaceInstUsesWith(ICI, InsertRangeTest(X, LoBound, HiBound,
945 DivIsSigned,
false));
946 case ICmpInst::ICMP_ULT:
948 if (LoOverflow == +1)
949 return ReplaceInstUsesWith(ICI, Builder->getTrue());
950 if (LoOverflow == -1)
951 return ReplaceInstUsesWith(ICI, Builder->getFalse());
952 return new ICmpInst(Pred, X, LoBound);
955 if (HiOverflow == +1)
956 return ReplaceInstUsesWith(ICI, Builder->getFalse());
957 if (HiOverflow == -1)
958 return ReplaceInstUsesWith(ICI, Builder->getTrue());
960 return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
968 const APInt &CmpRHSV = cast<ConstantInt>(ICI.
getOperand(1))->getValue();
975 if (ShAmtVal >= TypeBits || ShAmtVal == 0)
987 if (Shr->
getOpcode() == Instruction::AShr &&
988 (!Shr->
isExact() || ShAmtVal == TypeBits - 1))
1010 assert(TheDiv->
getOpcode() == Instruction::SDiv ||
1011 TheDiv->
getOpcode() == Instruction::UDiv);
1013 Instruction *Res = FoldICmpDivCst(ICI, TheDiv, cast<ConstantInt>(DivCst));
1014 assert(Res &&
"This div/cst should have folded!");
1021 APInt Comp = CmpRHSV << ShAmtVal;
1022 ConstantInt *ShiftedCmpRHS = Builder->getInt(Comp);
1023 if (Shr->
getOpcode() == Instruction::LShr)
1024 Comp = Comp.
lshr(ShAmtVal);
1026 Comp = Comp.
ashr(ShAmtVal);
1028 if (Comp != CmpRHSV) {
1030 Constant *Cst = Builder->getInt1(IsICMP_NE);
1031 return ReplaceInstUsesWith(ICI, Cst);
1043 Constant *Mask = Builder->getInt(Val);
1046 Mask, Shr->
getName()+
".mask");
1061 case Instruction::Trunc:
1067 APInt KnownZero(SrcBits, 0), KnownOne(SrcBits, 0);
1071 if ((KnownZero|KnownOne).countLeadingOnes() >= SrcBits-DstBits) {
1076 Builder->getInt(NewRHS));
1091 if (!XorCST->isNegative()) {
1101 isTrueIfPositive ^=
true;
1103 if (isTrueIfPositive)
1113 if (!ICI.
isEquality() && XorCST->getValue().isSignBit()) {
1114 const APInt &SignBit = XorCST->getValue();
1119 Builder->getInt(RHSV ^ SignBit));
1123 if (!ICI.
isEquality() && XorCST->isMaxValue(
true)) {
1124 const APInt &NotSignBit = XorCST->getValue();
1130 Builder->getInt(RHSV ^ NotSignBit));
1137 XorCST->getValue() == ~RHSV && (RHSV + 1).isPowerOf2())
1143 XorCST->getValue() == -RHSV && RHSV.isPowerOf2())
1163 Builder->CreateAnd(Cast->getOperand(0),
1174 IntegerType *Ty = cast<IntegerType>(Cast->getSrcTy());
1179 Builder->CreateAnd(Cast->getOperand(0),
1192 if (Shift && !Shift->
isShift())
1208 uint32_t TyBits = Ty->getPrimitiveSizeInBits();
1219 if (Shift->
getOpcode() == Instruction::Shl)
1227 NewCst, ShAmt) != RHS) {
1232 return ReplaceInstUsesWith(ICI, Builder->getFalse());
1234 return ReplaceInstUsesWith(ICI, Builder->getTrue());
1238 if (Shift->
getOpcode() == Instruction::Shl)
1244 Worklist.Add(Shift);
1253 if (Shift && Shift->
hasOneUse() && RHSV == 0 &&
1258 if (Shift->
getOpcode() == Instruction::LShr) {
1259 NS = Builder->CreateShl(AndCST, Shift->
getOperand(1));
1262 NS = Builder->CreateLShr(AndCST, Shift->
getOperand(1));
1287 dyn_cast<GetElementPtrInst>(
LI->getOperand(0)))
1288 if (
GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0)))
1289 if (GV->isConstant() && GV->hasDefinitiveInitializer() &&
1290 !
LI->isVolatile() && isa<ConstantInt>(LHSI->
getOperand(1))) {
1292 if (
Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV,ICI, C))
1320 Op = BinaryOperator::CreateAnd(ICIP, ICIQ);
1322 Op = BinaryOperator::CreateOr(ICIP, ICIQ);
1328 case Instruction::Mul: {
1336 cast<BinaryOperator>(LHSI)->hasNoSignedWrap())
1345 case Instruction::Shl: {
1355 if (!RHSVIsPowerOf2) {
1365 unsigned RHSLog2 = RHSV.
logBase2();
1371 if (RHSLog2 == TypeBits-1) {
1375 return ReplaceInstUsesWith(ICI, Builder->getFalse());
1377 return ReplaceInstUsesWith(ICI, Builder->getTrue());
1413 return ReplaceInstUsesWith(
1415 : Builder->getTrue());
1424 if (ShAmt->
uge(TypeBits))
1435 Constant *Cst = Builder->getInt1(IsICMP_NE);
1436 return ReplaceInstUsesWith(ICI, Cst);
1441 if (cast<BinaryOperator>(LHSI)->hasNoUnsignedWrap())
1447 if (cast<BinaryOperator>(LHSI)->hasNoSignedWrap() && RHSV == 0)
1455 TypeBits - ShAmtVal));
1468 cast<BinaryOperator>(LHSI)->hasNoSignedWrap())
1474 bool TrueIfSigned =
false;
1502 Builder->CreateTrunc(LHSI->
getOperand(0), NTy),
1509 case Instruction::LShr:
1510 case Instruction::AShr: {
1514 if (
Instruction *Res = FoldICmpShrCst(ICI, BO, ShAmt))
1526 case Instruction::SDiv:
1527 case Instruction::UDiv:
1535 if (
Instruction *R = FoldICmpDivCst(ICI, cast<BinaryOperator>(LHSI),
1540 case Instruction::Sub: {
1549 RHSV.
isPowerOf2() && (LHSV & (RHSV - 1)) == (RHSV - 1))
1551 Builder->CreateOr(LHSI->
getOperand(1), RHSV - 1),
1558 (RHSV + 1).isPowerOf2() && (LHSV & RHSV) == RHSV)
1560 Builder->CreateOr(LHSI->
getOperand(1), RHSV), LHSC);
1564 case Instruction::Add:
1596 RHSV.
isPowerOf2() && (LHSV & (RHSV - 1)) == 0)
1598 Builder->CreateAnd(LHSI->
getOperand(0), -RHSV),
1605 (RHSV + 1).isPowerOf2() && (LHSV & RHSV) == 0)
1607 Builder->CreateAnd(LHSI->
getOperand(0), ~RHSV),
1620 switch (BO->getOpcode()) {
1621 case Instruction::SRem:
1623 if (RHSV == 0 && isa<ConstantInt>(BO->getOperand(1)) &&BO->hasOneUse()){
1624 const APInt &V = cast<ConstantInt>(BO->getOperand(1))->getValue();
1627 Builder->CreateURem(BO->getOperand(0), BO->getOperand(1),
1634 case Instruction::Add:
1636 if (
ConstantInt *BOp1C = dyn_cast<ConstantInt>(BO->getOperand(1))) {
1637 if (BO->hasOneUse())
1640 }
else if (RHSV == 0) {
1643 Value *BOp0 = BO->getOperand(0), *BOp1 = BO->getOperand(1);
1645 if (
Value *NegVal = dyn_castNegVal(BOp1))
1647 if (
Value *NegVal = dyn_castNegVal(BOp0))
1649 if (BO->hasOneUse()) {
1650 Value *Neg = Builder->CreateNeg(BOp1);
1659 if (
Constant *BOC = dyn_cast<Constant>(BO->getOperand(1))) {
1662 }
else if (RHSV == 0) {
1668 case Instruction::Sub:
1670 if (
ConstantInt *BOp0C = dyn_cast<ConstantInt>(BO->getOperand(0))) {
1671 if (BO->hasOneUse())
1674 }
else if (RHSV == 0) {
1683 if (
ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1))) {
1686 return ReplaceInstUsesWith(ICI, Builder->getInt1(isICMP_NE));
1691 if (
ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1))) {
1694 if ((RHSV & ~BOC->getValue()) != 0)
1695 return ReplaceInstUsesWith(ICI, Builder->getInt1(isICMP_NE));
1704 if (!BO->hasOneUse())
1708 if (BOC->getValue().isSignBit()) {
1709 Value *
X = BO->getOperand(0);
1713 return new ICmpInst(pred, X, Zero);
1718 Value *
X = BO->getOperand(0);
1722 return new ICmpInst(pred, X, NegX);
1726 case Instruction::Mul:
1727 if (RHSV == 0 && BO->hasNoSignedWrap()) {
1728 if (
ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1))) {
1740 }
else if (
IntrinsicInst *II = dyn_cast<IntrinsicInst>(LHSI)) {
1742 switch (II->getIntrinsicID()) {
1781 Type *SrcTy = LHSCIOp->getType();
1787 if (
TD && LHSCI->
getOpcode() == Instruction::PtrToInt &&
1793 RHSOp = RHSC->getOperand(0);
1795 if (LHSCIOp->getType() != RHSOp->
getType())
1796 RHSOp = Builder->CreateBitCast(RHSOp, LHSCIOp->
getType());
1805 if (LHSCI->
getOpcode() != Instruction::ZExt &&
1806 LHSCI->
getOpcode() != Instruction::SExt)
1809 bool isSignedExt = LHSCI->
getOpcode() == Instruction::SExt;
1814 RHSCIOp = CI->getOperand(0);
1815 if (RHSCIOp->
getType() != LHSCIOp->getType())
1820 if (CI->getOpcode() != LHSCI->
getOpcode())
1829 if (isSignedCmp && isSignedExt)
1855 if (isSignedExt && isSignedCmp)
1867 if (isSignedCmp || !isSignedExt)
1876 Value *Result = Builder->CreateICmpSGT(LHSCIOp, NegOne, ICI.
getName());
1880 return ReplaceInstUsesWith(ICI, Result);
1909 if (NewWidth != 7 && NewWidth != 15 && NewWidth != 31)
return 0;
1922 unsigned NeededSignBits = CI1->
getBitWidth() - NewWidth + 1;
1934 if (*UI == AddWithCst)
continue;
1979 if (!isa<IntegerType>(OrigAddV->
getType()))
return 0;
1983 if (OrigAdd == 0)
return 0;
2008 unsigned BitWidth,
bool isSignCheck) {
2050 const Value * Op1) {
2062 int GlobalSwapBenefits = 0;
2065 if (!BinOp || BinOp->
getOpcode() != Instruction::Sub)
2069 int LocalSwapBenefits = -1;
2070 unsigned Op1Idx = 1;
2073 LocalSwapBenefits = 1;
2077 GlobalSwapBenefits += LocalSwapBenefits;
2079 return GlobalSwapBenefits > 0;
2083 bool Changed =
false;
2091 if (Op0Cplxity < Op1Cplxity ||
2092 (Op0Cplxity == Op1Cplxity &&
2100 return ReplaceInstUsesWith(I, V);
2106 Value *Cond, *SelectTrue, *SelectFalse;
2109 if (
Value *V = dyn_castNegVal(SelectTrue)) {
2110 if (V == SelectFalse)
2113 else if (
Value *V = dyn_castNegVal(SelectFalse)) {
2114 if (V == SelectTrue)
2131 return BinaryOperator::CreateXor(Op0, Op1);
2138 return BinaryOperator::CreateAnd(Not, Op1);
2145 return BinaryOperator::CreateAnd(Not, Op0);
2152 return BinaryOperator::CreateOr(Not, Op1);
2159 return BinaryOperator::CreateOr(Not, Op0);
2164 unsigned BitWidth = 0;
2170 bool isSignBit =
false;
2173 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
2210 assert(!CI->isMaxValue(
false));
2212 Builder->getInt(CI->getValue()+1));
2214 assert(!CI->isMaxValue(
true));
2216 Builder->getInt(CI->getValue()+1));
2218 assert(!CI->isMinValue(
false));
2220 Builder->getInt(CI->getValue()-1));
2222 assert(!CI->isMinValue(
true));
2224 Builder->getInt(CI->getValue()-1));
2235 if (BitWidth != 0) {
2236 APInt Op0KnownZero(BitWidth, 0), Op0KnownOne(BitWidth, 0);
2237 APInt Op1KnownZero(BitWidth, 0), Op1KnownOne(BitWidth, 0);
2241 Op0KnownZero, Op0KnownOne, 0))
2245 Op1KnownZero, Op1KnownOne, 0))
2251 APInt Op0Min(BitWidth, 0), Op0Max(BitWidth, 0);
2252 APInt Op1Min(BitWidth, 0), Op1Max(BitWidth, 0);
2268 if (!isa<Constant>(Op0) && Op0Min == Op0Max)
2271 if (!isa<Constant>(Op1) && Op1Min == Op1Max)
2280 if (Op0Max.
ult(Op1Min) || Op0Min.ugt(Op1Max))
2286 APInt Op0KnownZeroInverted = ~Op0KnownZero;
2287 if (~Op1KnownZero == 0 && Op0KnownZeroInverted.
isPowerOf2()) {
2292 LHSC->
getValue() != Op0KnownZeroInverted)
2307 if (Op0KnownZeroInverted == 1 &&
2317 if (Op0Max.
ult(Op1Min) || Op0Min.ugt(Op1Max))
2323 APInt Op0KnownZeroInverted = ~Op0KnownZero;
2324 if (~Op1KnownZero == 0 && Op0KnownZeroInverted.
isPowerOf2()) {
2329 LHSC->
getValue() != Op0KnownZeroInverted)
2344 if (Op0KnownZeroInverted == 1 &&
2354 if (Op0Max.
ult(Op1Min))
2356 if (Op0Min.uge(Op1Max))
2358 if (Op1Min == Op0Max)
2360 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
2361 if (Op1Max == Op0Min+1)
2363 Builder->getInt(CI->getValue()-1));
2366 if (CI->isMinValue(
true))
2372 if (Op0Min.ugt(Op1Max))
2374 if (Op0Max.
ule(Op1Min))
2377 if (Op1Max == Op0Min)
2379 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
2380 if (Op1Min == Op0Max-1)
2382 Builder->getInt(CI->getValue()+1));
2385 if (CI->isMaxValue(
true))
2391 if (Op0Max.
slt(Op1Min))
2393 if (Op0Min.sge(Op1Max))
2395 if (Op1Min == Op0Max)
2397 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
2398 if (Op1Max == Op0Min+1)
2400 Builder->getInt(CI->getValue()-1));
2404 if (Op0Min.sgt(Op1Max))
2406 if (Op0Max.
sle(Op1Min))
2409 if (Op1Max == Op0Min)
2411 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
2412 if (Op1Min == Op0Max-1)
2414 Builder->getInt(CI->getValue()+1));
2418 assert(!isa<ConstantInt>(Op1) &&
"ICMP_SGE with ConstantInt not folded!");
2419 if (Op0Min.sge(Op1Max))
2421 if (Op0Max.
slt(Op1Min))
2425 assert(!isa<ConstantInt>(Op1) &&
"ICMP_SLE with ConstantInt not folded!");
2426 if (Op0Max.
sle(Op1Min))
2428 if (Op0Min.sgt(Op1Max))
2432 assert(!isa<ConstantInt>(Op1) &&
"ICMP_UGE with ConstantInt not folded!");
2433 if (Op0Min.uge(Op1Max))
2435 if (Op0Max.
ult(Op1Min))
2439 assert(!isa<ConstantInt>(Op1) &&
"ICMP_ULE with ConstantInt not folded!");
2440 if (Op0Max.
ule(Op1Min))
2442 if (Op0Min.ugt(Op1Max))
2450 ((Op0KnownZero.isNegative() && Op1KnownZero.isNegative()) ||
2451 (Op0KnownOne.isNegative() && Op1KnownOne.isNegative())))
2464 if ((SI->getOperand(1) == Op0 && SI->getOperand(2) == Op1) ||
2465 (SI->getOperand(2) == Op0 && SI->getOperand(1) == Op1))
2470 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
2474 if (
Instruction *LHSI = dyn_cast<Instruction>(Op0))
2475 if (
Instruction *Res = visitICmpInstWithInstAndIntCst(I, LHSI, CI))
2480 if (
Constant *RHSC = dyn_cast<Constant>(Op1)) {
2481 if (
Instruction *LHSI = dyn_cast<Instruction>(Op0))
2482 switch (LHSI->getOpcode()) {
2483 case Instruction::GetElementPtr:
2485 if (RHSC->isNullValue() &&
2486 cast<GetElementPtrInst>(LHSI)->hasAllZeroIndices())
2502 Value *Op1 = 0, *Op2 = 0;
2503 if (
Constant *
C = dyn_cast<Constant>(LHSI->getOperand(1)))
2505 if (
Constant *
C = dyn_cast<Constant>(LHSI->getOperand(2)))
2514 if ((Op1 && Op2) || (LHSI->hasOneUse() && (Op1 || Op2))) {
2516 Op1 = Builder->CreateICmp(I.
getPredicate(), LHSI->getOperand(1),
2519 Op2 = Builder->CreateICmp(I.
getPredicate(), LHSI->getOperand(2),
2525 case Instruction::IntToPtr:
2527 if (RHSC->isNullValue() &&
TD &&
2528 TD->getIntPtrType(RHSC->getType()) ==
2529 LHSI->getOperand(0)->getType())
2537 dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) {
2538 if (
GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0)))
2539 if (GV->isConstant() && GV->hasDefinitiveInitializer() &&
2540 !cast<LoadInst>(LHSI)->isVolatile())
2541 if (
Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV, I))
2549 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(Op0))
2552 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(Op1))
2560 if (
BitCastInst *CI = dyn_cast<BitCastInst>(Op0)) {
2562 (isa<Constant>(Op1) || isa<BitCastInst>(Op1))) {
2565 Op0 = CI->getOperand(0);
2569 if (
BitCastInst *CI2 = dyn_cast<BitCastInst>(Op1))
2570 Op1 = CI2->getOperand(0);
2573 if (Op0->
getType() != Op1->getType()) {
2574 if (
Constant *Op1C = dyn_cast<Constant>(Op1)) {
2578 Op1 = Builder->CreateBitCast(Op1, Op0->
getType());
2585 if (isa<CastInst>(Op0)) {
2592 if (isa<Constant>(Op1) || isa<CastInst>(Op1))
2593 if (
Instruction *R = visitICmpInstWithCastAndCast(I))
2602 bool NoOp0WrapProblem =
false, NoOp1WrapProblem =
false;
2603 if (BO0 && isa<OverflowingBinaryOperator>(BO0))
2607 if (BO1 && isa<OverflowingBinaryOperator>(BO1))
2614 Value *
A = 0, *B = 0, *
C = 0, *D = 0;
2615 if (BO0 && BO0->
getOpcode() == Instruction::Add)
2617 if (BO1 && BO1->getOpcode() == Instruction::Add)
2618 C = BO1->getOperand(0), D = BO1->getOperand(1);
2621 if ((A == Op1 || B == Op1) && NoOp0WrapProblem)
2622 return new ICmpInst(Pred, A == Op1 ? B : A,
2626 if ((
C == Op0 || D == Op0) && NoOp1WrapProblem)
2631 if (A && C && (A == C || A == D || B == C || B == D) &&
2632 NoOp0WrapProblem && NoOp1WrapProblem &&
2641 }
else if (A == D) {
2645 }
else if (B == C) {
2685 if (A && C && NoOp0WrapProblem && NoOp1WrapProblem &&
2689 const APInt &AP1 = C1->getValue();
2690 const APInt &AP2 = C2->getValue();
2692 APInt AP1Abs = C1->getValue().
abs();
2693 APInt AP2Abs = C2->getValue().
abs();
2694 if (AP1Abs.
uge(AP2Abs)) {
2696 Value *NewAdd = Builder->CreateNSWAdd(A, C3);
2697 return new ICmpInst(Pred, NewAdd, C);
2700 Value *NewAdd = Builder->CreateNSWAdd(C, C3);
2701 return new ICmpInst(Pred, A, NewAdd);
2709 A = 0; B = 0; C = 0; D = 0;
2710 if (BO0 && BO0->
getOpcode() == Instruction::Sub)
2712 if (BO1 && BO1->getOpcode() == Instruction::Sub)
2713 C = BO1->getOperand(0), D = BO1->getOperand(1);
2716 if (A == Op1 && NoOp0WrapProblem)
2720 if (C == Op0 && NoOp1WrapProblem)
2724 if (B && D && B == D && NoOp0WrapProblem && NoOp1WrapProblem &&
2730 if (A && C && A == C && NoOp0WrapProblem && NoOp1WrapProblem &&
2737 if (BO0 && BO0->
getOpcode() == Instruction::SRem &&
2741 else if (BO1 && BO1->getOpcode() == Instruction::SRem &&
2742 Op0 == BO1->getOperand(1))
2764 if (BO0 && BO1 && BO0->
getOpcode() == BO1->getOpcode() &&
2769 case Instruction::Add:
2770 case Instruction::Sub:
2774 BO1->getOperand(0));
2777 if (CI->getValue().isSignBit()) {
2782 BO1->getOperand(0));
2785 if (CI->isMaxValue(
true)) {
2791 BO1->getOperand(0));
2795 case Instruction::Mul:
2802 if (!CI->isZero() && !CI->isOne()) {
2803 const APInt &AP = CI->getValue();
2809 Value *And2 = Builder->CreateAnd(BO1->getOperand(0), Mask);
2814 case Instruction::UDiv:
2815 case Instruction::LShr:
2819 case Instruction::SDiv:
2820 case Instruction::AShr:
2821 if (!BO0->
isExact() || !BO1->isExact())
2824 BO1->getOperand(0));
2825 case Instruction::Shl: {
2833 BO1->getOperand(0));
2846 Builder->CreateAnd(A, B),
2854 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1))
2862 (Op1 == A || Op1 == B))
2870 (Op0 == A || Op0 == B))
2879 if (A == Op1 || B == Op1) {
2880 Value *OtherVal = A == Op1 ? B :
A;
2891 Value *
Xor = Builder->CreateXor(C, NC);
2904 (A == Op0 || B == Op0)) {
2906 Value *OtherVal = A == Op0 ? B :
A;
2917 X = B;
Y = D; Z =
A;
2918 }
else if (A == D) {
2919 X = B;
Y =
C; Z =
A;
2920 }
else if (B == C) {
2921 X =
A;
Y = D; Z = B;
2922 }
else if (B == D) {
2923 X =
A;
Y =
C; Z = B;
2927 Op1 = Builder->CreateXor(X,
Y);
2928 Op1 = Builder->CreateAnd(Op1, Z);
2941 (Op1->hasOneUse() &&
2948 Builder->CreateTrunc(B, A->
getType()));
2959 if (ShAmt < TypeBits && ShAmt != 0) {
2965 return new ICmpInst(Pred, Xor, Builder->getInt(CmpVal));
2979 unsigned ASize =cast<IntegerType>(A->
getType())->getPrimitiveSizeInBits();
2981 if (ShAmt < ASize) {
2989 Value *Mask = Builder->CreateAnd(A, Builder->getInt(MaskV));
3005 return Changed ? &I : 0;
3013 if (!isa<ConstantFP>(RHSC))
return 0;
3014 const APFloat &RHS = cast<ConstantFP>(RHSC)->getValueAPF();
3019 if (MantissaWidth == -1)
return 0;
3027 bool LHSUnsigned = isa<UIToFPInst>(LHSI);
3032 if ((
int)InputSize > MantissaWidth)
3038 assert(!RHS.
isNaN() &&
"NaN comparison not already folded!");
3068 return ReplaceInstUsesWith(I, Builder->getTrue());
3070 return ReplaceInstUsesWith(I, Builder->getFalse());
3090 return ReplaceInstUsesWith(I, Builder->getTrue());
3091 return ReplaceInstUsesWith(I, Builder->getFalse());
3102 return ReplaceInstUsesWith(I, Builder->getTrue());
3103 return ReplaceInstUsesWith(I, Builder->getFalse());
3115 return ReplaceInstUsesWith(I, Builder->getTrue());
3116 return ReplaceInstUsesWith(I, Builder->getFalse());
3126 return ReplaceInstUsesWith(I, Builder->getTrue());
3127 return ReplaceInstUsesWith(I, Builder->getFalse());
3139 bool Equal = LHSUnsigned
3149 return ReplaceInstUsesWith(I, Builder->getTrue());
3151 return ReplaceInstUsesWith(I, Builder->getFalse());
3156 return ReplaceInstUsesWith(I, Builder->getFalse());
3168 return ReplaceInstUsesWith(I, Builder->getFalse());
3181 return ReplaceInstUsesWith(I, Builder->getTrue());
3193 return ReplaceInstUsesWith(I, Builder->getTrue());
3212 bool Changed =
false;
3225 return ReplaceInstUsesWith(I, V);
3252 if (
Constant *RHSC = dyn_cast<Constant>(Op1)) {
3253 if (
Instruction *LHSI = dyn_cast<Instruction>(Op0))
3254 switch (LHSI->getOpcode()) {
3255 case Instruction::FPExt: {
3257 FPExtInst *LHSExt = cast<FPExtInst>(LHSI);
3303 case Instruction::SIToFP:
3304 case Instruction::UIToFP:
3312 Value *Op1 = 0, *Op2 = 0;
3313 if (LHSI->hasOneUse()) {
3314 if (
Constant *
C = dyn_cast<Constant>(LHSI->getOperand(1))) {
3319 LHSI->getOperand(2), RHSC, I.
getName());
3320 }
else if (
Constant *
C = dyn_cast<Constant>(LHSI->getOperand(2))) {
3324 Op1 = Builder->CreateFCmp(I.
getPredicate(), LHSI->getOperand(1),
3333 case Instruction::FSub: {
3343 dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) {
3344 if (
GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0)))
3345 if (GV->isConstant() && GV->hasDefinitiveInitializer() &&
3346 !cast<LoadInst>(LHSI)->isVolatile())
3347 if (
Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV, I))
3352 CallInst *CI = cast<CallInst>(LHSI);
3364 return ReplaceInstUsesWith(I, Builder->getFalse());
3398 if (
FPExtInst *LHSExt = dyn_cast<FPExtInst>(Op0))
3399 if (
FPExtInst *RHSExt = dyn_cast<FPExtInst>(Op1))
3400 if (LHSExt->getSrcTy() == RHSExt->getSrcTy())
3402 RHSExt->getOperand(0));
3404 return Changed ? &I : 0;
bool isArithmeticShift() const
isArithmeticShift - Return true if this is an arithmetic shift right.
const Use & getOperandUse(unsigned i) const
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
static bool isHighOnes(const ConstantInt *CI)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT ashr(unsigned shiftAmt) const
Arithmetic right-shift function.
void push_back(const T &Elt)
Type * getIndexedType() const
static ConstantInt * getFalse(LLVMContext &Context)
IntegerType * getType() const
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
class_match< Value > m_Value()
m_Value() - Match an arbitrary value and ignore it.
Abstract base class of comparison instructions.
static APInt getSignBit(unsigned BitWidth)
Get the SignBit for a specific bit width.
APInt LLVM_ATTRIBUTE_UNUSED_RESULT byteSwap() const
static Constant * getSIToFP(Constant *C, Type *Ty)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT abs() const
Get the absolute value;.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Instruction * FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, ICmpInst::Predicate Cond, Instruction &I)
static bool HasSubOverflow(ConstantInt *Result, ConstantInt *In1, ConstantInt *In2, bool IsSigned)
bool isNaN() const
Returns true if and only if the float is a quiet or signaling NaN.
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
unsigned getScalarSizeInBits()
static const fltSemantics IEEEdouble
The main container class for the LLVM Intermediate Representation.
static void ComputeSignedMinMaxValuesFromKnownBits(const APInt &KnownZero, const APInt &KnownOne, APInt &Min, APInt &Max)
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=0)
void setBit(unsigned bitPosition)
Set a given bit to 1.
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
This class represents zero extension of integer types.
unsigned getNumOperands() const
static Constant * getFPToUI(Constant *C, Type *Ty)
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
static bool SubWithOverflow(Constant *&Result, Constant *In1, Constant *In2, bool IsSigned=false)
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Predicate getInversePredicate() const
Return the inverse of the instruction's predicate.
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &TD, User *GEP, bool NoAssumptions=false)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
bool isSigned() const
Determine if this instruction is using a signed comparison.
static Constant * getExtractElement(Constant *Vec, Constant *Idx)
0 1 0 0 True if ordered and less than
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
1 1 1 0 True if unordered or not equal
int getFPMantissaWidth() const
static bool isEquality(Predicate P)
const Function * getParent() const
Return the enclosing method, or null if none.
static Constant * getUIToFP(Constant *C, Type *Ty)
Instruction * FoldFCmp_IntToFP_Cst(FCmpInst &I, Instruction *LHSI, Constant *RHSC)
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
fneg_match< LHS > m_FNeg(const LHS &L)
m_FNeg - Match a floating point negate.
const Constant * getInitializer() const
Value * SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
LoopInfoBase< BlockT, LoopT > * LI
static Constant * getNullValue(Type *Ty)
StringRef getName() const
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool hasAllConstantIndices() const
APInt Not(const APInt &APIVal)
Bitwise complement function.
bool isNegative() const
Determine sign of this APInt.
bool uge(uint64_t Num) const
Determine if the value is greater or equal to the given number.
1 0 0 1 True if unordered or equal
long double fabsl(long double x);
bool match(Val *V, const Pattern &P)
static const fltSemantics x87DoubleExtended
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static unsigned getComplexity(Value *V)
DataLayout * getDataLayout() const
static unsigned getBitWidth(Type *Ty, const DataLayout *TD)
unsigned ComputeNumSignBits(Value *Op, unsigned Depth=0) const
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
const StructLayout * getStructLayout(StructType *Ty) const
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0)
Base class of casting instructions.
const APInt & getValue() const
Return the constant's value.
#define llvm_unreachable(msg)
Type * getArrayElementType() const
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT lshr(unsigned shiftAmt) const
Logical right-shift function.
static Instruction * ProcessUAddIdiom(Instruction &I, Value *OrigAddV, InstCombiner &IC)
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
m_Trunc
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
InstCombiner - The -instcombine pass.
0 1 0 1 True if ordered and less than or equal
static Constant * SubOne(Constant *C)
SubOne - Subtract one from a ConstantInt.
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs)
static const fltSemantics IEEEquad
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
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.
uint64_t getZExtValue() const
Return the zero extended value.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
m_ZExt
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS)
Represents a floating point comparison operator.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
Get the constant's value with a saturation limit.
bool sgt(const APInt &RHS) const
Signed greather than comparison.
This class represents a no-op cast from one type to another.
bool isLogicalShift() const
static APInt DemandedBitsLHSMask(ICmpInst &I, unsigned BitWidth, bool isSignCheck)
unsigned getActiveBits() const
Compute the number of active bits in the value.
class_match< ConstantInt > m_ConstantInt()
m_ConstantInt() - Match an arbitrary ConstantInt and ignore it.
Predicate getUnsignedPredicate() const
Return the unsigned version of the predicate.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
static bool AddWithOverflow(Constant *&Result, Constant *In1, Constant *In2, bool IsSigned=false)
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
m_Power2() - Match an integer or vector power of 2.
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
static Constant * getIntToPtr(Constant *C, Type *Ty)
Value * SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0, const DominatorTree *DT=0)
Instruction * visitICmpInstWithCastAndCast(ICmpInst &ICI)
bool isPPC_FP128Ty() const
isPPC_FP128Ty - Return true if this is powerpc long double.
This class represents a truncation of integer types.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
bool isInBounds() const
isInBounds - Determine whether the GEP has the inbounds flag.
void ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne, const DataLayout *TD=0, unsigned Depth=0)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
opStatus convertFromAPInt(const APInt &, bool, roundingMode)
uint64_t getElementOffset(unsigned Idx) const
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
Instruction * FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV, CmpInst &ICI, ConstantInt *AndCst=0)
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isIntOrIntVectorTy() const
static Instruction * ProcessUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B, ConstantInt *CI2, ConstantInt *CI1, InstCombiner &IC)
static bool isSignTest(ICmpInst::Predicate &pred, const ConstantInt *RHS)
static Constant * getFNeg(Constant *C)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
static void ComputeUnsignedMinMaxValuesFromKnownBits(const APInt &KnownZero, const APInt &KnownOne, APInt &Min, APInt &Max)
cmpResult compare(const APFloat &) const
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
bool isMaxValue(bool isSigned) const
Determine if the value is maximal.
LLVM Constant Representation.
Instruction * ReplaceInstUsesWith(Instruction &I, Value *V)
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
Instruction * FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *DivI, ConstantInt *DivRHS)
FoldICmpShrCst - Handle "icmp(([al]shr X, cst1), cst2)".
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static Value * EvaluateGEPOffsetExpression(User *GEP, InstCombiner &IC)
cst_pred_ty< is_all_ones > m_AllOnes()
m_AllOnes() - Match an integer or vector with all bits set to true.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
specificval_ty m_Specific(const Value *V)
m_Specific - Match if we have a specific specified value.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
Represent an integer comparison operator.
unsigned getBitWidth() const
Return the number of bits in the APInt.
opStatus convert(const fltSemantics &, roundingMode, bool *)
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
Instruction * visitICmpInst(ICmpInst &I)
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout *TD=0, const TargetLibraryInfo *TLI=0)
Integer representation type.
Type * getSrcTy() const
Return the source type, as a convenience.
Predicate getPredicate() const
Return the predicate for this instruction.
static Constant * getNot(Constant *C)
Constant * getAggregateElement(unsigned Elt) const
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
bool isFP128Ty() const
isFP128Ty - Return true if this is 'fp128'.
void swapOperands()
Swap operands and adjust predicate.
LLVMContext & getContext() const
All values hold a context through their type.
bool hasNoSignedWrap() const
hasNoSignedWrap - Determine whether the no signed wrap flag is set.
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 const fltSemantics IEEEhalf
bool isRelational() const
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
unsigned countTrailingZeros() const
Count the number of trailing zero bits.
static bool isZero(Value *V, DataLayout *DL)
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
static IntegerType * get(LLVMContext &C, unsigned NumBits)
Get or create an IntegerType instance.
static Constant * getBitCast(Constant *C, Type *Ty)
static const fltSemantics PPCDoubleDouble
unsigned getIntegerBitWidth() const
Class for constant integers.
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="")
bool slt(const APInt &RHS) const
Signed less than comparison.
uint64_t getTypeAllocSize(Type *Ty) const
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
unsigned logBase2() const
1 1 0 0 True if unordered or less than
const APInt & getLower() const
bool isTrueWhenEqual() const
Determine if this is true when both operands are the same.
SequentialType * getType() const
bool isKnownToBeAPowerOfTwo(Value *V, bool OrZero=false, unsigned Depth=0)
Value * stripPointerCasts()
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value...
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
Predicate getSwappedPredicate() const
Return the predicate as if the operands were swapped.
static APInt getMinValue(unsigned numBits)
Gets minimum unsigned value of APInt for a specific bit width.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
Function * getCalledFunction() const
static Constant * AddOne(Constant *C)
AddOne - Add one to a ConstantInt.
static Constant * getTrunc(Constant *C, Type *Ty)
static Constant * get(Type *Ty, double V)
bool isExact() const
isExact - Determine whether the exact flag is set.
static ConstantInt * getTrue(LLVMContext &Context)
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
static Constant * getFPToSI(Constant *C, Type *Ty)
void setOperand(unsigned i, Value *Val)
bool isAllOnesValue() const
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Value * getArgOperand(unsigned i) const
Class for arbitrary precision integers.
static bool HasAddOverflow(ConstantInt *Result, ConstantInt *In1, ConstantInt *In2, bool IsSigned)
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
m_PtrToInt
static ConstantInt * getOne(Constant *C)
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.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
bool isAllOnesValue() const
Determine if all bits are set.
static CmpInst * Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=0)
Create a CmpInst.
static bool isSignBitCheck(ICmpInst::Predicate pred, ConstantInt *RHS, bool &TrueIfSigned)
static const fltSemantics IEEEsingle
bool isX86_FP80Ty() const
isX86_FP80Ty - Return true if this is x86 long double.
static IntegerType * getInt32Ty(LLVMContext &C)
static Constant * getZExt(Constant *C, Type *Ty)
unsigned greater or equal
void clearBit(unsigned bitPosition)
Set a given bit to 0.
0 1 1 0 True if ordered and operands are unequal
bool isSignBit() const
Check if the APInt's value is returned by getSignBit.
static ConstantRange makeConstantRange(Predicate pred, const APInt &C)
Make a ConstantRange for a relation with a constant value.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Instruction * visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Instruction *LHS, ConstantInt *RHS)
const Type * getScalarType() const
uint64_t getArrayNumElements() const
unsigned getPrimitiveSizeInBits() const
1 0 1 0 True if unordered or greater than
Instruction * FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI, ConstantInt *DivRHS)
bool isUnsigned() const
Determine if this instruction is using an unsigned comparison.
CallInst * CreateCall2(Value *Callee, Value *Arg1, Value *Arg2, const Twine &Name="")
const APInt & getUpper() const
void swapOperands()
Swap operands and adjust predicate.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
static bool swapMayExposeCSEOpportunities(const Value *Op0, const Value *Op1)
Check if the order of Op0 and Op1 as operand in an ICmpInst should be swapped. The descision is based...
0 0 0 1 True if ordered and equal
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="")
LLVM Value Representation.
bool hasNoUnsignedWrap() const
hasNoUnsignedWrap - 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.
bool isZero() const
Returns true if and only if the float is plus or minus zero.
cst_pred_ty< is_one > m_One()
m_One() - Match an integer 1 or a vector with all elements equal to 1.
Predicate getSignedPredicate() const
Return the signed version of the predicate.
Instruction * visitFCmpInst(FCmpInst &I)
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2)
Return an ICmp or FCmp comparison operator constant expression.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=0)
This class represents an extension of floating point types.
int64_t getSExtValue() const
Return the sign extended value.
0 0 1 1 True if ordered and greater than or equal
static Constant * getCast(unsigned ops, Constant *C, Type *Ty)
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
const fltSemantics & getSemantics() const
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
bool isOne() const
Determine if the value is one.
Instruction * FoldICmpAddOpCst(Instruction &ICI, Value *X, ConstantInt *CI, ICmpInst::Predicate Pred)
FoldICmpAddOpCst - Fold "icmp pred (X+CI), X".
static Constant * getXor(Constant *C1, Constant *C2)
gep_type_iterator gep_type_begin(const User *GEP)