Home | History | Annotate | Download | only in InstCombine

Lines Matching refs:ICmpInst

117 static bool isSignBitCheck(ICmpInst::Predicate pred, ConstantInt *RHS,
120 case ICmpInst::ICMP_SLT: // True if LHS s< 0
123 case ICmpInst::ICMP_SLE: // True if LHS s<= RHS and RHS == -1
126 case ICmpInst::ICMP_SGT: // True if LHS s> -1
129 case ICmpInst::ICMP_UGT:
133 case ICmpInst::ICMP_UGE:
145 static bool isSignTest(ICmpInst::Predicate &pred, const ConstantInt *RHS) {
146 if (!ICmpInst::isSigned(pred))
150 return ICmpInst::isRelational(pred);
153 if (pred == ICmpInst::ICMP_SLT) {
154 pred = ICmpInst::ICMP_SLE;
158 if (pred == ICmpInst::ICMP_SGT) {
159 pred = ICmpInst::ICMP_SGE;
411 return new ICmpInst(ICmpInst::ICMP_EQ, Idx, FirstTrueIdx);
431 return new ICmpInst(ICmpInst::ICMP_NE, Idx, FirstFalseIdx);
453 return new ICmpInst(ICmpInst::ICMP_ULT, Idx, End);
467 return new ICmpInst(ICmpInst::ICMP_UGT, Idx, End);
492 return new ICmpInst(ICmpInst::ICMP_NE, V, ConstantInt::get(Ty, 0));
607 ICmpInst::Predicate Cond,
614 if (ICmpInst::isSigned(Cond))
632 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
650 return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0));
660 Value *Cmp = Builder->CreateICmp(ICmpInst::getSignedPredicate(Cond),
681 ICmpInst::getSwappedPredicate(Cond), I);
714 Builder->getInt1(ICmpInst::isTrueWhenEqual(Cond)));
720 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), LHSV, RHSV);
733 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), L, R);
740 Instruction *InstCombiner::FoldICmpAddOpCst(ICmpInst &ICI,
742 ICmpInst::Predicate Pred,
747 bool isTrue = ICmpInst::isTrueWhenEqual(Pred);
752 if (Pred == ICmpInst::ICMP_EQ)
756 if (Pred == ICmpInst::ICMP_NE)
766 if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_ULE) {
769 return new ICmpInst(ICmpInst::ICMP_UGT, X, R);
775 if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE)
776 return new ICmpInst(ICmpInst::ICMP_ULT, X, ConstantExpr::getNeg(CI));
788 if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE)
789 return new ICmpInst(ICmpInst::ICMP_SGT, X, ConstantExpr::getSub(SMax, CI));
798 assert(Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE);
800 ICmpInst(ICmpInst::ICMP_SLT, X, ConstantExpr::getSub(SMax, C));
805 Instruction *InstCombiner::FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
844 ICmpInst::Predicate Pred = ICI.getPredicate();
914 Pred = ICmpInst::getSwappedPredicate(Pred);
920 case ICmpInst::ICMP_EQ:
924 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
925 ICmpInst::ICMP_UGE, X, LoBound);
927 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
928 ICmpInst::ICMP_ULT, X, HiBound);
931 case ICmpInst::ICMP_NE:
935 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
936 ICmpInst::ICMP_ULT, X, LoBound);
938 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
939 ICmpInst::ICMP_UGE, X, HiBound);
942 case ICmpInst::ICMP_ULT:
943 case ICmpInst::ICMP_SLT:
948 return new ICmpInst(Pred, X, LoBound);
949 case ICmpInst::ICMP_UGT:
950 case ICmpInst::ICMP_SGT:
955 if (Pred == ICmpInst::ICMP_UGT)
956 return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
957 return new ICmpInst(ICmpInst::ICMP_SGE, X, HiBound);
962 Instruction *InstCombiner::FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *Shr,
1025 bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1034 return new ICmpInst(ICI.getPredicate(), Shr->getOperand(0), ShiftedCmpRHS);
1043 return new ICmpInst(ICI.getPredicate(), And, ShiftedCmpRHS);
1051 Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
1071 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
1081 if ((ICI.getPredicate() == ICmpInst::ICMP_SLT && RHSV == 0) ||
1082 (ICI.getPredicate() == ICmpInst::ICMP_SGT && RHSV.isAllOnesValue())) {
1094 bool isTrueIfPositive = ICI.getPredicate() == ICmpInst::ICMP_SGT;
1100 return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal,
1103 return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal,
1111 ICmpInst::Predicate Pred = ICI.isSigned()
1114 return new ICmpInst(Pred, LHSI->getOperand(0),
1121 ICmpInst::Predicate Pred = ICI.isSigned()
1125 return new ICmpInst(Pred, LHSI->getOperand(0),
1132 if (ICI.getPredicate() == ICmpInst::ICMP_UGT &&
1134 return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0), XorCST);
1138 if (ICI.getPredicate() == ICmpInst::ICMP_ULT &&
1140 return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0), XorCST);
1162 return new ICmpInst(ICI.getPredicate(), NewAnd,
1178 return new ICmpInst(ICI.getPredicate(), NewAnd,
1227 if (ICI.getPredicate() == ICmpInst::ICMP_EQ)
1229 if (ICI.getPredicate() == ICmpInst::ICMP_NE)
1271 if (ICI.getPredicate() == ICmpInst::ICMP_UGT) {
1275 return new ICmpInst(ICmpInst::ICMP_NE, LHSI,
1297 return new ICmpInst(
1298 ICI.getPredicate() == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_UGT
1299 : ICmpInst::ICMP_ULE,
1315 if (ICI.getPredicate() == ICmpInst::ICMP_EQ)
1330 ICmpInst::Predicate pred = ICI.getPredicate();
1333 return new ICmpInst(Val->isNegative() ?
1334 ICmpInst::getSwappedPredicate(pred) : pred,
1349 ICmpInst::Predicate Pred = ICI.getPredicate();
1356 if (Pred == ICmpInst::ICMP_ULT)
1357 Pred = ICmpInst::ICMP_ULE;
1358 else if (Pred == ICmpInst::ICMP_UGE)
1359 Pred = ICmpInst::ICMP_UGT;
1368 if (Pred == ICmpInst::ICMP_UGE)
1369 Pred = ICmpInst::ICMP_EQ;
1370 else if (Pred == ICmpInst::ICMP_UGT)
1372 else if (Pred == ICmpInst::ICMP_ULE)
1374 else if (Pred == ICmpInst::ICMP_ULT)
1375 Pred = ICmpInst::ICMP_NE;
1378 return new ICmpInst(Pred, X,
1383 if (Pred == ICmpInst::ICMP_SLE)
1384 return new ICmpInst(ICmpInst::ICMP_EQ, X,
1388 if (Pred == ICmpInst::ICMP_SGT)
1389 return new ICmpInst(ICmpInst::ICMP_NE, X,
1394 if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE)
1395 return new ICmpInst(ICmpInst::ICMP_EQ, X,
1400 if (Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE)
1401 return new ICmpInst(ICmpInst::ICMP_NE, X,
1406 return new ICmpInst(
1410 ICI, Pred == ICmpInst::ICMP_EQ ? Builder->getFalse()
1430 bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1438 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
1444 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
1455 return new ICmpInst(ICI.getPredicate(), And,
1462 ICmpInst::Predicate pred = ICI.getPredicate();
1465 return new ICmpInst(pred,
1479 return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
1497 return new ICmpInst(ICI.getPredicate(),
1517 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0), RHS);
1544 if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() &&
1546 return new ICmpInst(ICmpInst::ICMP_EQ,
1553 if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() &&
1555 return new ICmpInst(ICmpInst::ICMP_NE,
1572 return new ICmpInst(ICmpInst::ICMP_SLT, LHSI->getOperand(0),
1575 return new ICmpInst(ICmpInst::ICMP_SGE, LHSI->getOperand(0),
1580 return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0),
1583 return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0),
1591 if (ICI.getPredicate() == ICmpInst::ICMP_ULT && LHSI->hasOneUse() &&
1593 return new ICmpInst(ICmpInst::ICMP_EQ,
1600 if (ICI.getPredicate() == ICmpInst::ICMP_UGT && LHSI->hasOneUse() &&
1602 return new ICmpInst(ICmpInst::ICMP_NE,
1611 bool isICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1625 return new ICmpInst(ICI.getPredicate(), NewRem,
1634 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1642 return new ICmpInst(ICI.getPredicate(), BOp0, NegVal);
1644 return new ICmpInst(ICI.getPredicate(), NegVal, BOp1);
1648 return new ICmpInst(ICI.getPredicate(), BOp0, Neg);
1656 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1660 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1668 return new ICmpInst(ICI.getPredicate(), BO->getOperand(1),
1672 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1695 return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ :
1696 ICmpInst::ICMP_NE, LHSI,
1707 ICmpInst::Predicate pred = isICMP_NE ?
1708 ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
1709 return new ICmpInst(pred, X, Zero);
1716 ICmpInst::Predicate pred = isICMP_NE ?
1717 ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
1718 return new ICmpInst(pred, X, NegX);
1729 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1774 Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
1797 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSOp);
1822 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
1827 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
1830 return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp);
1848 return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
1853 return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
1856 return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, Res1);
1876 if (ICI.getPredicate() == ICmpInst::ICMP_ULT)
1879 assert(ICI.getPredicate() == ICmpInst::ICMP_UGT && "ICmp should be folded!");
1890 static Instruction *ProcessUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B,
2004 static APInt DemandedBitsLHSMask(ICmpInst &I,
2018 case ICmpInst::ICMP_UGT: {
2026 case ICmpInst::ICMP_ULT: {
2038 Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
2056 if (I.getPredicate() == ICmpInst::ICMP_NE && match(Op1, m_Zero()))
2078 case ICmpInst::ICMP_EQ: { // icmp eq i1 A, B -> ~(A^B)
2082 case ICmpInst::ICMP_NE: // icmp eq i1 A, B -> A^B
2085 case ICmpInst::ICMP_UGT:
2088 case ICmpInst::ICMP_ULT:{ // icmp ult i1 A, B -> ~A & B
2092 case ICmpInst::ICMP_SGT:
2095 case ICmpInst::ICMP_SLT: { // icmp slt i1 A, B -> A & ~B
2099 case ICmpInst::ICMP_UGE:
2102 case ICmpInst::ICMP_ULE: { // icmp ule i1 A, B -> ~A | B
2106 case ICmpInst::ICMP_SGE:
2109 case ICmpInst::ICMP_SLE: { // icmp sle i1 A, B -> A | ~B
2142 if (I.getPredicate() == ICmpInst::ICMP_UGT &&
2152 return new ICmpInst(I.getPredicate(), A, B);
2161 case ICmpInst::ICMP_ULE:
2163 return new ICmpInst(ICmpInst::ICMP_ULT, Op0,
2165 case ICmpInst::ICMP_SLE:
2167 return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
2169 case ICmpInst::ICMP_UGE:
2171 return new ICmpInst(ICmpInst::ICMP_UGT, Op0,
2173 case ICmpInst::ICMP_SGE:
2175 return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
2221 return new ICmpInst(I.getPredicate(),
2224 return new ICmpInst(I.getPredicate(), Op0,
2231 case ICmpInst::ICMP_EQ: {
2252 return new ICmpInst(ICmpInst::ICMP_NE, X,
2261 return new ICmpInst(ICmpInst::ICMP_NE, X,
2268 case ICmpInst::ICMP_NE: {
2289 return new ICmpInst(ICmpInst::ICMP_EQ, X,
2298 return new ICmpInst(ICmpInst::ICMP_EQ, X,
2305 case ICmpInst::ICMP_ULT:
2311 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2314 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2319 return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
2323 case ICmpInst::ICMP_UGT:
2330 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2333 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2338 return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
2342 case ICmpInst::ICMP_SLT:
2348 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2351 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2355 case ICmpInst::ICMP_SGT:
2362 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2365 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2369 case ICmpInst::ICMP_SGE:
2376 case ICmpInst::ICMP_SLE:
2383 case ICmpInst::ICMP_UGE:
2390 case ICmpInst::ICMP_ULE:
2404 return new ICmpInst(I.getUnsignedPredicate(), Op0, Op1);
2407 // Test if the ICmpInst instruction is used exclusively by a select as
2439 return new ICmpInst(I.getPredicate(), LHSI->getOperand(0),
2482 return new ICmpInst(I.getPredicate(), LHSI->getOperand(0),
2506 ICmpInst::getSwappedPredicate(I.getPredicate()), I))
2533 return new ICmpInst(I.getPredicate(), Op0, Op1);
2556 NoOp0WrapProblem = ICmpInst::isEquality(Pred) ||
2560 NoOp1WrapProblem = ICmpInst::isEquality(Pred) ||
2574 return new ICmpInst(Pred, A == Op1 ? B : A,
2579 return new ICmpInst(Pred, Constant::getNullValue(Op0->getType()),
2607 return new ICmpInst(Pred, Y, Z);
2613 return new ICmpInst(CmpInst::ICMP_SLE, A, Op1);
2618 return new ICmpInst(CmpInst::ICMP_SGT, A, Op1);
2623 return new ICmpInst(CmpInst::ICMP_SLT, A, Op1);
2628 return new ICmpInst(CmpInst::ICMP_SGE, A, Op1);
2649 return new ICmpInst(Pred, NewAdd, C);
2653 return new ICmpInst(Pred, A, NewAdd);
2669 return new ICmpInst(Pred, Constant::getNullValue(Op1->getType()), B);
2673 return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType()));
2679 return new ICmpInst(Pred, A, C);
2685 return new ICmpInst(Pred, D, B);
2699 switch (SRem == BO0 ? ICmpInst::getSwappedPredicate(Pred) : Pred) {
2701 case ICmpInst::ICMP_EQ:
2703 case ICmpInst::ICMP_NE:
2705 case ICmpInst::ICMP_SGT:
2706 case ICmpInst::ICMP_SGE:
2707 return new ICmpInst(ICmpInst::ICMP_SGT, SRem->getOperand(1),
2709 case ICmpInst::ICMP_SLT:
2710 case ICmpInst::ICMP_SLE:
2711 return new ICmpInst(ICmpInst::ICMP_SLT, SRem->getOperand(1),
2725 return new ICmpInst(I.getPredicate(), BO0->getOperand(0),
2730 ICmpInst::Predicate Pred = I.isSigned()
2733 return new ICmpInst(Pred, BO0->getOperand(0),
2738 ICmpInst::Predicate Pred = I.isSigned()
2742 return new ICmpInst(Pred, BO0->getOperand(0),
2762 return new ICmpInst(I.getPredicate(), And1, And2);
2775 return new ICmpInst(I.getPredicate(), BO0->getOperand(0),
2784 return new ICmpInst(I.getPredicate(), BO0->getOperand(0),
2797 return new ICmpInst(I.getInversePredicate(),
2805 return new ICmpInst(I.getPredicate(), B, A);
2807 return new ICmpInst(I.getPredicate(), ConstantExpr::getNot(RHSC), A);
2812 if (I.getPredicate() == ICmpInst::ICMP_ULT &&
2820 if (I.getPredicate() == ICmpInst::ICMP_UGT &&
2833 return new ICmpInst(I.getPredicate(), OtherVal,
2844 return new ICmpInst(I.getPredicate(), A, Xor);
2848 if (A == C) return new ICmpInst(I.getPredicate(), B, D);
2849 if (A == D) return new ICmpInst(I.getPredicate(), B, C);
2850 if (B == C) return new ICmpInst(I.getPredicate(), A, D);
2851 if (B == D) return new ICmpInst(I.getPredicate(), A, C);
2859 return new ICmpInst(I.getPredicate(), OtherVal,
2899 return new ICmpInst(I.getPredicate(), A,
2924 return new ICmpInst(I.getPredicate(), Mask, Builder->getInt(CmpV));
2979 ICmpInst::Predicate Pred;
2984 Pred = ICmpInst::ICMP_EQ;
2988 Pred = LHSUnsigned ? ICmpInst::ICMP_UGT : ICmpInst::ICMP_SGT;
2992 Pred = LHSUnsigned ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_SGE;
2996 Pred = LHSUnsigned ? ICmpInst::ICMP_ULT : ICmpInst::ICMP_SLT;
3000 Pred = LHSUnsigned ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_SLE;
3004 Pred = ICmpInst::ICMP_NE;
3027 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SLT ||
3028 Pred == ICmpInst::ICMP_SLE)
3039 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_ULT ||
3040 Pred == ICmpInst::ICMP_ULE)
3052 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SGT ||
3053 Pred == ICmpInst::ICMP_SGE)
3063 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_UGT ||
3064 Pred == ICmpInst::ICMP_UGE)
3087 case ICmpInst::ICMP_NE: // (float)int != 4.4 --> true
3089 case ICmpInst::ICMP_EQ: // (float)int == 4.4 --> false
3091 case ICmpInst::ICMP_ULE:
3097 case ICmpInst::ICMP_SLE:
3101 Pred = ICmpInst::ICMP_SLT;
3103 case ICmpInst::ICMP_ULT:
3108 Pred = ICmpInst::ICMP_ULE;
3110 case ICmpInst::ICMP_SLT:
3114 Pred = ICmpInst::ICMP_SLE;
3116 case ICmpInst::ICMP_UGT:
3122 case ICmpInst::ICMP_SGT:
3126 Pred = ICmpInst::ICMP_SGE;
3128 case ICmpInst::ICMP_UGE:
3133 Pred = ICmpInst::ICMP_UGT;
3135 case ICmpInst::ICMP_SGE:
3139 Pred = ICmpInst::ICMP_SGT;
3147 return new ICmpInst(Pred, LHSI->getOperand(0), RHSInt);