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:
386 return new ICmpInst(ICmpInst::ICMP_EQ, Idx, FirstTrueIdx);
406 return new ICmpInst(ICmpInst::ICMP_NE, Idx, FirstFalseIdx);
428 return new ICmpInst(ICmpInst::ICMP_ULT, Idx, End);
442 return new ICmpInst(ICmpInst::ICMP_UGT, Idx, End);
459 return new ICmpInst(ICmpInst::ICMP_NE, V, ConstantInt::get(Ty, 0));
573 ICmpInst::Predicate Cond,
580 if (ICmpInst::isSigned(Cond))
598 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), Offset,
616 return new ICmpInst(ICmpInst::getSignedPredicate(Cond),
627 Value *Cmp = Builder->CreateICmp(ICmpInst::getSignedPredicate(Cond),
648 ICmpInst::getSwappedPredicate(Cond), I);
682 ICmpInst::isTrueWhenEqual(Cond)));
688 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), LHSV, RHSV);
701 return new ICmpInst(ICmpInst::getSignedPredicate(Cond), L, R);
708 Instruction *InstCombiner::FoldICmpAddOpCst(ICmpInst &ICI,
710 ICmpInst::Predicate Pred,
715 bool isTrue = ICmpInst::isTrueWhenEqual(Pred);
720 if (Pred == ICmpInst::ICMP_EQ)
724 if (Pred == ICmpInst::ICMP_NE)
734 if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_ULE) {
737 return new ICmpInst(ICmpInst::ICMP_UGT, X, R);
743 if (Pred == ICmpInst::ICMP_UGT || Pred == ICmpInst::ICMP_UGE)
744 return new ICmpInst(ICmpInst::ICMP_ULT, X, ConstantExpr::getNeg(CI));
756 if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SLE)
757 return new ICmpInst(ICmpInst::ICMP_SGT, X, ConstantExpr::getSub(SMax, CI));
766 assert(Pred == ICmpInst::ICMP_SGT || Pred == ICmpInst::ICMP_SGE);
768 return new ICmpInst(ICmpInst::ICMP_SLT, X, ConstantExpr::getSub(SMax, C));
773 Instruction *InstCombiner::FoldICmpDivCst(ICmpInst &ICI, BinaryOperator *DivI,
812 ICmpInst::Predicate Pred = ICI.getPredicate();
882 Pred = ICmpInst::getSwappedPredicate(Pred);
888 case ICmpInst::ICMP_EQ:
892 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
893 ICmpInst::ICMP_UGE, X, LoBound);
895 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
896 ICmpInst::ICMP_ULT, X, HiBound);
899 case ICmpInst::ICMP_NE:
903 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
904 ICmpInst::ICMP_ULT, X, LoBound);
906 return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
907 ICmpInst::ICMP_UGE, X, HiBound);
910 case ICmpInst::ICMP_ULT:
911 case ICmpInst::ICMP_SLT:
916 return new ICmpInst(Pred, X, LoBound);
917 case ICmpInst::ICMP_UGT:
918 case ICmpInst::ICMP_SGT:
923 if (Pred == ICmpInst::ICMP_UGT)
924 return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
925 return new ICmpInst(ICmpInst::ICMP_SGE, X, HiBound);
930 Instruction *InstCombiner::FoldICmpShrCst(ICmpInst &ICI, BinaryOperator *Shr,
993 bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1003 return new ICmpInst(ICI.getPredicate(), Shr->getOperand(0), ShiftedCmpRHS);
1012 return new ICmpInst(ICI.getPredicate(), And, ShiftedCmpRHS);
1020 Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
1040 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
1050 if ((ICI.getPredicate() == ICmpInst::ICMP_SLT && RHSV == 0) ||
1051 (ICI.getPredicate() == ICmpInst::ICMP_SGT && RHSV.isAllOnesValue())) {
1063 bool isTrueIfPositive = ICI.getPredicate() == ICmpInst::ICMP_SGT;
1069 return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal,
1072 return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal,
1080 ICmpInst::Predicate Pred = ICI.isSigned()
1083 return new ICmpInst(Pred, LHSI->getOperand(0),
1091 ICmpInst::Predicate Pred = ICI.isSigned()
1095 return new ICmpInst(Pred, LHSI->getOperand(0),
1121 return new ICmpInst(ICI.getPredicate(), NewAnd,
1137 return new ICmpInst(ICI.getPredicate(), NewAnd,
1186 if (ICI.getPredicate() == ICmpInst::ICMP_EQ)
1189 if (ICI.getPredicate() == ICmpInst::ICMP_NE)
1232 if (ICI.getPredicate() == ICmpInst::ICMP_UGT) {
1236 return new ICmpInst(ICmpInst::ICMP_NE, LHSI,
1267 if (ICI.getPredicate() == ICmpInst::ICMP_EQ)
1295 bool IsICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1304 return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
1316 return new ICmpInst(ICI.getPredicate(), And,
1331 return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
1349 return new ICmpInst(ICI.getPredicate(),
1369 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0), RHS);
1400 return new ICmpInst(ICmpInst::ICMP_SLT, LHSI->getOperand(0),
1403 return new ICmpInst(ICmpInst::ICMP_SGE, LHSI->getOperand(0),
1408 return new ICmpInst(ICmpInst::ICMP_ULT, LHSI->getOperand(0),
1411 return new ICmpInst(ICmpInst::ICMP_UGE, LHSI->getOperand(0),
1421 bool isICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
1435 return new ICmpInst(ICI.getPredicate(), NewRem,
1444 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1452 return new ICmpInst(ICI.getPredicate(), BOp0, NegVal);
1454 return new ICmpInst(ICI.getPredicate(), NegVal, BOp1);
1458 return new ICmpInst(ICI.getPredicate(), BOp0, Neg);
1466 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1470 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1478 return new ICmpInst(ICI.getPredicate(), BO->getOperand(1),
1482 return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
1509 return new ICmpInst(isICMP_NE ? ICmpInst::ICMP_EQ :
1510 ICmpInst::ICMP_NE, LHSI,
1521 ICmpInst::Predicate pred = isICMP_NE ?
1522 ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
1523 return new ICmpInst(pred, X, Zero);
1530 ICmpInst::Predicate pred = isICMP_NE ?
1531 ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
1532 return new ICmpInst(pred, X, NegX);
1575 Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
1598 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSOp);
1623 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
1628 return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSCIOp);
1631 return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, RHSCIOp);
1649 return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
1654 return new ICmpInst(ICI.getPredicate(), LHSCIOp, Res1);
1657 return new ICmpInst(ICI.getUnsignedPredicate(), LHSCIOp, Res1);
1677 if (ICI.getPredicate() == ICmpInst::ICMP_ULT)
1680 assert(ICI.getPredicate() == ICmpInst::ICMP_UGT && "ICmp should be folded!");
1691 static Instruction *ProcessUGT_ADDCST_ADD(ICmpInst &I, Value *A, Value *B,
1805 static APInt DemandedBitsLHSMask(ICmpInst &I,
1819 case ICmpInst::ICMP_UGT: {
1827 case ICmpInst::ICMP_ULT: {
1839 Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
1857 if (I.getPredicate() == ICmpInst::ICMP_NE && match(Op1, m_Zero()))
1879 case ICmpInst::ICMP_EQ: { // icmp eq i1 A, B -> ~(A^B)
1883 case ICmpInst::ICMP_NE: // icmp eq i1 A, B -> A^B
1886 case ICmpInst::ICMP_UGT:
1889 case ICmpInst::ICMP_ULT:{ // icmp ult i1 A, B -> ~A & B
1893 case ICmpInst::ICMP_SGT:
1896 case ICmpInst::ICMP_SLT: { // icmp slt i1 A, B -> A & ~B
1900 case ICmpInst::ICMP_UGE:
1903 case ICmpInst::ICMP_ULE: { // icmp ule i1 A, B -> ~A | B
1907 case ICmpInst::ICMP_SGE:
1910 case ICmpInst::ICMP_SLE: { // icmp sle i1 A, B -> A | ~B
1943 if (I.getPredicate() == ICmpInst::ICMP_UGT &&
1953 return new ICmpInst(I.getPredicate(), A, B);
1962 case ICmpInst::ICMP_ULE:
1964 return new ICmpInst(ICmpInst::ICMP_ULT, Op0,
1966 case ICmpInst::ICMP_SLE:
1968 return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
1970 case ICmpInst::ICMP_UGE:
1972 return new ICmpInst(ICmpInst::ICMP_UGT, Op0,
1974 case ICmpInst::ICMP_SGE:
1976 return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
2022 return new ICmpInst(I.getPredicate(),
2025 return new ICmpInst(I.getPredicate(), Op0,
2032 case ICmpInst::ICMP_EQ: {
2053 return new ICmpInst(ICmpInst::ICMP_NE, X,
2062 return new ICmpInst(ICmpInst::ICMP_NE, X,
2069 case ICmpInst::ICMP_NE: {
2090 return new ICmpInst(ICmpInst::ICMP_EQ, X,
2099 return new ICmpInst(ICmpInst::ICMP_EQ, X,
2106 case ICmpInst::ICMP_ULT:
2112 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2115 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2120 return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
2124 case ICmpInst::ICMP_UGT:
2131 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2134 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2139 return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
2143 case ICmpInst::ICMP_SLT:
2149 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2152 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2156 case ICmpInst::ICMP_SGT:
2163 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
2166 return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
2170 case ICmpInst::ICMP_SGE:
2177 case ICmpInst::ICMP_SLE:
2184 case ICmpInst::ICMP_UGE:
2191 case ICmpInst::ICMP_ULE:
2205 return new ICmpInst(I.getUnsignedPredicate(), Op0, Op1);
2208 // Test if the ICmpInst instruction is used exclusively by a select as
2240 return new ICmpInst(I.getPredicate(), LHSI->getOperand(0),
2283 return new ICmpInst(I.getPredicate(), LHSI->getOperand(0),
2307 ICmpInst::getSwappedPredicate(I.getPredicate()), I))
2334 return new ICmpInst(I.getPredicate(), Op0, Op1);
2357 NoOp0WrapProblem = ICmpInst::isEquality(Pred) ||
2361 NoOp1WrapProblem = ICmpInst::isEquality(Pred) ||
2375 return new ICmpInst(Pred, A == Op1 ? B : A,
2380 return new ICmpInst(Pred, Constant::getNullValue(Op0->getType()),
2408 return new ICmpInst(Pred, Y, Z);
2421 return new ICmpInst(Pred, Constant::getNullValue(Op1->getType()), B);
2425 return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType()));
2431 return new ICmpInst(Pred, A, C);
2437 return new ICmpInst(Pred, D, B);
2451 switch (SRem == BO0 ? ICmpInst::getSwappedPredicate(Pred) : Pred) {
2453 case ICmpInst::ICMP_EQ:
2455 case ICmpInst::ICMP_NE:
2457 case ICmpInst::ICMP_SGT:
2458 case ICmpInst::ICMP_SGE:
2459 return new ICmpInst(ICmpInst::ICMP_SGT, SRem->getOperand(1),
2461 case ICmpInst::ICMP_SLT:
2462 case ICmpInst::ICMP_SLE:
2463 return new ICmpInst(ICmpInst::ICMP_SLT, SRem->getOperand(1),
2477 return new ICmpInst(I.getPredicate(), BO0->getOperand(0),
2482 ICmpInst::Predicate Pred = I.isSigned()
2485 return new ICmpInst(Pred, BO0->getOperand(0),
2490 ICmpInst::Predicate Pred = I.isSigned()
2494 return new ICmpInst(Pred, BO0->getOperand(0),
2514 return new ICmpInst(I.getPredicate(), And1, And2);
2527 return new ICmpInst(I.getPredicate(), BO0->getOperand(0),
2536 return new ICmpInst(I.getPredicate(), BO0->getOperand(0),
2548 return new ICmpInst(I.getPredicate(), B, A);
2550 return new ICmpInst(I.getPredicate(), ConstantExpr::getNot(RHSC), A);
2555 if (I.getPredicate() == ICmpInst::ICMP_ULT &&
2563 if (I.getPredicate() == ICmpInst::ICMP_UGT &&
2576 return new ICmpInst(I.getPredicate(), OtherVal,
2588 return new ICmpInst(I.getPredicate(), A, Xor);
2592 if (A == C) return new ICmpInst(I.getPredicate(), B, D);
2593 if (A == D) return new ICmpInst(I.getPredicate(), B, C);
2594 if (B == C) return new ICmpInst(I.getPredicate(), A, D);
2595 if (B == D) return new ICmpInst(I.getPredicate(), A, C);
2603 return new ICmpInst(I.getPredicate(), OtherVal,
2643 return new ICmpInst(I.getPredicate(), A,
2668 return new ICmpInst(I.getPredicate(), Mask, Builder->getInt(CmpV));
2723 ICmpInst::Predicate Pred;
2728 Pred = ICmpInst::ICMP_EQ;
2732 Pred = LHSUnsigned ? ICmpInst::ICMP_UGT : ICmpInst::ICMP_SGT;
2736 Pred = LHSUnsigned ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_SGE;
2740 Pred = LHSUnsigned ? ICmpInst::ICMP_ULT : ICmpInst::ICMP_SLT;
2744 Pred = LHSUnsigned ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_SLE;
2748 Pred = ICmpInst::ICMP_NE;
2771 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SLT ||
2772 Pred == ICmpInst::ICMP_SLE)
2783 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_ULT ||
2784 Pred == ICmpInst::ICMP_ULE)
2796 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SGT ||
2797 Pred == ICmpInst::ICMP_SGE)
2807 if (Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_UGT ||
2808 Pred == ICmpInst::ICMP_UGE)
2831 case ICmpInst::ICMP_NE: // (float)int != 4.4 --> true
2833 case ICmpInst::ICMP_EQ: // (float)int == 4.4 --> false
2835 case ICmpInst::ICMP_ULE:
2841 case ICmpInst::ICMP_SLE:
2845 Pred = ICmpInst::ICMP_SLT;
2847 case ICmpInst::ICMP_ULT:
2852 Pred = ICmpInst::ICMP_ULE;
2854 case ICmpInst::ICMP_SLT:
2858 Pred = ICmpInst::ICMP_SLE;
2860 case ICmpInst::ICMP_UGT:
2866 case ICmpInst::ICMP_SGT:
2870 Pred = ICmpInst::ICMP_SGE;
2872 case ICmpInst::ICMP_UGE:
2877 Pred = ICmpInst::ICMP_UGT;
2879 case ICmpInst::ICMP_SGE:
2883 Pred = ICmpInst::ICMP_SGT;
2891 return new ICmpInst(Pred, LHSI->getOperand(0), RHSInt);