Lines Matching defs:Cmp

799         Value *Cmp = Builder.CreateICmp(ICmpInst::getSignedPredicate(Cond),
801 return replaceInstUsesWith(I, Cmp);
1224 Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
1225 CmpInst::Predicate Pred = Cmp.getPredicate();
1226 if (!match(Cmp.getOperand(1), m_Zero()))
1232 if (match(Cmp.getOperand(0), m_SMin(m_Value(A), m_Value(B)))) {
1233 if (isKnownPositive(A, SQ.getWithInstruction(&Cmp)))
1234 return new ICmpInst(Pred, B, Cmp.getOperand(1));
1235 if (isKnownPositive(B, SQ.getWithInstruction(&Cmp)))
1236 return new ICmpInst(Pred, A, Cmp.getOperand(1));
1240 if (Instruction *New = foldIRemByPowerOfTwoToBitTest(Cmp))
1248 if (match(Cmp.getOperand(0), m_URem(m_Value(X), m_Value(Y))) &&
1250 KnownBits XKnown = computeKnownBits(X, 0, &Cmp);
1251 KnownBits YKnown = computeKnownBits(Y, 0, &Cmp);
1253 return new ICmpInst(Pred, X, Cmp.getOperand(1));
1258 if (match(Cmp.getOperand(0), m_Mul(m_Value(X), m_Value(Y))) &&
1261 KnownBits XKnown = computeKnownBits(X, 0, &Cmp);
1265 return new ICmpInst(Pred, Y, Cmp.getOperand(1));
1267 KnownBits YKnown = computeKnownBits(Y, 0, &Cmp);
1271 return new ICmpInst(Pred, X, Cmp.getOperand(1));
1273 auto *BO0 = cast<OverflowingBinaryOperator>(Cmp.getOperand(0));
1275 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
1282 return new ICmpInst(Pred, Y, Cmp.getOperand(1));
1287 return new ICmpInst(Pred, X, Cmp.getOperand(1));
1306 Instruction *InstCombinerImpl::foldICmpWithConstant(ICmpInst &Cmp) {
1318 CmpInst::Predicate Pred = Cmp.getPredicate();
1319 Value *Op0 = Cmp.getOperand(0), *Op1 = Cmp.getOperand(1);
1324 if (Instruction *Res = processUGT_ADDCST_ADD(Cmp, A, B, CI2, CI, *this))
1343 PHINode *NewPhi = Builder.CreatePHI(Cmp.getType(), Phi->getNumOperands());
1346 return replaceInstUsesWith(Cmp, NewPhi);
1349 if (Instruction *R = tryFoldInstWithCtpopWithNot(&Cmp))
1356 Instruction *InstCombinerImpl::foldICmpWithDominatingICmp(ICmpInst &Cmp) {
1359 Value *X = Cmp.getOperand(0), *Y = Cmp.getOperand(1);
1364 CmpInst::Predicate Pred = Cmp.getPredicate();
1375 // Cmp = icmp Pred X, C
1381 return replaceInstUsesWith(Cmp, Builder.getFalse());
1383 return replaceInstUsesWith(Cmp, Builder.getTrue());
1392 if (Cmp.isEquality() || (IsSignBit && hasBranchUse(Cmp)))
1397 if (Cmp.hasOneUse() &&
1398 match(Cmp.user_back(), m_MaxOrMin(m_Value(), m_Value())))
1416 if (DT.dominates(Edge0, Cmp.getParent())) {
1421 if (DT.dominates(Edge1, Cmp.getParent()))
1432 Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp,
1435 ICmpInst::Predicate Pred = Cmp.getPredicate();
1446 if (!Cmp.isSigned() && Trunc->hasNoUnsignedWrap())
1461 if (Cmp.isEquality() && match(X, m_Shl(m_One(), m_Value(Y)))) {
1465 auto NewPred = (Pred == Cmp.ICMP_EQ) ? Cmp.ICMP_UGE : Cmp.ICMP_ULT;
1474 if (Cmp.isEquality() && Trunc->hasOneUse()) {
1487 KnownBits Known = computeKnownBits(X, 0, &Cmp);
1519 InstCombinerImpl::foldICmpTruncWithTruncOrExt(ICmpInst &Cmp,
1525 if (match(&Cmp, m_ICmp(Pred, m_Trunc(m_Value(X)), m_Trunc(m_Value(Y))))) {
1526 unsigned NoWrapFlags = cast<TruncInst>(Cmp.getOperand(0))->getNoWrapKind() &
1527 cast<TruncInst>(Cmp.getOperand(1))->getNoWrapKind();
1528 if (Cmp.isSigned()) {
1540 (!Cmp.getOperand(0)->hasOneUse() || !Cmp.getOperand(1)->hasOneUse()))
1545 Pred = Cmp.getSwappedPredicate(Pred);
1550 else if (!Cmp.isSigned() &&
1551 match(&Cmp, m_c_ICmp(Pred, m_NUWTrunc(m_Value(X)),
1556 else if (match(&Cmp, m_c_ICmp(Pred, m_NSWTrunc(m_Value(X)),
1560 isa<SExtInst>(Cmp.getOperand(0)) || isa<SExtInst>(Cmp.getOperand(1));
1564 Type *TruncTy = Cmp.getOperand(0)->getType();
1578 Instruction *InstCombinerImpl::foldICmpXorConstant(ICmpInst &Cmp,
1581 if (Instruction *I = foldICmpXorShiftConst(Cmp, Xor, C))
1592 ICmpInst::Predicate Pred = Cmp.getPredicate();
1594 if (isSignBitCheck(Cmp.getPredicate(), C, TrueIfSigned)) {
1599 return replaceOperand(Cmp, 0, X);
1612 if (!Cmp.isEquality() && XorC->isSignMask()) {
1613 Pred = Cmp.getFlippedSignednessPredicate();
1618 if (!Cmp.isEquality() && XorC->isMaxSignedValue()) {
1619 Pred = Cmp.getFlippedSignednessPredicate();
1620 Pred = Cmp.getSwappedPredicate(Pred);
1650 Instruction *InstCombinerImpl::foldICmpXorShiftConst(ICmpInst &Cmp,
1653 CmpInst::Predicate Pred = Cmp.getPredicate();
1679 Instruction *InstCombinerImpl::foldICmpAndShift(ICmpInst &Cmp,
1703 if (Cmp.isSigned() && (C2.isNegative() || C1.isNegative()))
1717 if (Cmp.isSigned() && (NewAndCst.isNegative() || NewCmpCst.isNegative()))
1734 if (Cmp.getPredicate() == ICmpInst::ICMP_EQ)
1735 return replaceInstUsesWith(Cmp, ConstantInt::getFalse(Cmp.getType()));
1736 if (Cmp.getPredicate() == ICmpInst::ICMP_NE)
1737 return replaceInstUsesWith(Cmp, ConstantInt::getTrue(Cmp.getType()));
1741 return new ICmpInst(Cmp.getPredicate(),
1749 if (Shift->hasOneUse() && C1.isZero() && Cmp.isEquality() &&
1759 return new ICmpInst(Cmp.getPredicate(), NewAnd, Cmp.getOperand(1));
1766 Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
1769 bool isICMP_NE = Cmp.getPredicate() == ICmpInst::ICMP_NE;
1774 if (isICMP_NE && Cmp.getType()->isVectorTy() && C1.isZero() &&
1776 return new TruncInst(And->getOperand(0), Cmp.getType());
1784 if (Cmp.getPredicate() == ICmpInst::ICMP_SGT && C1.ule(~*C2) &&
1789 if (Cmp.getPredicate() == ICmpInst::ICMP_SLT && !C1.isSignMask() &&
1798 if (Cmp.isEquality() && C1.isZero()) {
1832 (Cmp.isEquality() || (!C1.isNegative() && !C2->isNegative()))) {
1836 if (!Cmp.getType()->isVectorTy()) {
1842 return new ICmpInst(Cmp.getPredicate(), NewAnd, ZextC1);
1846 if (Instruction *I = foldICmpAndShift(Cmp, And, C1, *C2))
1853 if (!Cmp.isSigned() && C1.isZero() && And->getOperand(0)->hasOneUse() &&
1876 return new ICmpInst(Cmp.getPredicate(), NewAnd, Cmp.getOperand(1));
1886 if (!Cmp.getParent()->getParent()->hasFnAttribute(
1888 Cmp.isEquality() &&
1898 return replaceInstUsesWith(Cmp, Builder.createIsFPClass(V, Mask));
1907 Instruction *InstCombinerImpl::foldICmpAndConstant(ICmpInst &Cmp,
1910 if (Instruction *I = foldICmpAndConstConst(Cmp, And, C))
1913 const ICmpInst::Predicate Pred = Cmp.getPredicate();
1945 foldCmpLoadFromIndexedGlobal(LI, GEP, GV, Cmp, C2))
1948 if (!Cmp.isEquality())
1954 if (Cmp.getOperand(1) == Y && C.isNegatedPowerOf2()) {
1957 return new ICmpInst(NewPred, X, SubOne(cast<Constant>(Cmp.getOperand(1))));
1970 assert(Cmp.isEquality() && "Not expecting non-equality predicates");
1980 return replaceInstUsesWith(Cmp, R);
2029 static Value *foldICmpOrXorSubChain(ICmpInst &Cmp, BinaryOperator *Or,
2074 ICmpInst::Predicate Pred = Cmp.getPredicate();
2088 Instruction *InstCombinerImpl::foldICmpOrConstant(ICmpInst &Cmp,
2091 ICmpInst::Predicate Pred = Cmp.getPredicate();
2104 if (Cmp.isEquality() && match(OrOp1, m_ImmConstant()) &&
2112 if (match(OrOp1, m_APInt(MaskC)) && Cmp.isEquality()) {
2167 if (!Cmp.isEquality() || !C.isZero() || !Or->hasOneUse())
2182 if (Value *V = foldICmpOrXorSubChain(Cmp, Or, Builder))
2183 return replaceInstUsesWith(Cmp, V);
2189 Instruction *InstCombinerImpl::foldICmpMulConstant(ICmpInst &Cmp,
2192 ICmpInst::Predicate Pred = Cmp.getPredicate();
2199 if (Cmp.isEquality() && C.isZero() && X == Mul->getOperand(1) &&
2222 if (Cmp.isEquality()) {
2280 static Instruction *foldICmpShlLHSC(ICmpInst &Cmp, Instruction *Shl,
2289 ICmpInst::Predicate Pred = Cmp.getPredicate();
2290 if (Cmp.isUnsigned()) {
2311 } else if (Cmp.isSigned() && C2->isOne()) {
2330 Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
2334 if (Cmp.isEquality() && match(Shl->getOperand(0), m_APInt(ShiftVal)))
2335 return foldICmpShlConstConst(Cmp, Shl->getOperand(1), C, *ShiftVal);
2337 ICmpInst::Predicate Pred = Cmp.getPredicate();
2344 return new ICmpInst(Pred, Shl->getOperand(0), Cmp.getOperand(1));
2350 return new ICmpInst(Pred, Shl->getOperand(0), Cmp.getOperand(1));
2361 return new ICmpInst(Pred, Shl->getOperand(0), Cmp.getOperand(1));
2365 return foldICmpShlLHSC(Cmp, Shl, C);
2426 if (Cmp.isEquality() && Shl->hasOneUse()) {
2449 if (Cmp.isUnsigned() && Shl->hasOneUse()) {
2510 Instruction *InstCombinerImpl::foldICmpShrConstant(ICmpInst &Cmp,
2516 CmpInst::Predicate Pred = Cmp.getPredicate();
2517 if (Cmp.isEquality() && Shr->isExact() && C.isZero())
2518 return new ICmpInst(Pred, X, Cmp.getOperand(1));
2523 if (Cmp.isEquality())
2524 return foldICmpShrConstConst(Cmp, Shr->getOperand(1), C, *ShiftValC);
2635 if (!Cmp.isEquality())
2674 Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
2677 const ICmpInst::Predicate Pred = Cmp.getPredicate();
2756 Instruction *InstCombinerImpl::foldICmpUDivConstant(ICmpInst &Cmp,
2759 ICmpInst::Predicate Pred = Cmp.getPredicate();
2789 Instruction *InstCombinerImpl::foldICmpDivConstant(ICmpInst &Cmp,
2792 ICmpInst::Predicate Pred = Cmp.getPredicate();
2806 if (Cmp.isEquality() && Div->hasOneUse() && C.isSignBitSet() &&
2832 if (!Cmp.isEquality() && DivIsSigned != Cmp.isSigned())
2929 return replaceInstUsesWith(Cmp, Builder.getFalse());
2937 Cmp, insertRangeTest(X, LoBound, HiBound, DivIsSigned, true));
2940 return replaceInstUsesWith(Cmp, Builder.getTrue());
2948 Cmp, insertRangeTest(X, LoBound, HiBound, DivIsSigned, false));
2952 return replaceInstUsesWith(Cmp, Builder.getTrue());
2954 return replaceInstUsesWith(Cmp, Builder.getFalse());
2959 return replaceInstUsesWith(Cmp, Builder.getFalse());
2961 return replaceInstUsesWith(Cmp, Builder.getTrue());
2971 Instruction *InstCombinerImpl::foldICmpSubConstant(ICmpInst &Cmp,
2975 ICmpInst::Predicate Pred = Cmp.getPredicate();
2981 if (Cmp.isEquality() && match(X, m_ImmConstant(SubC))) {
2989 ICmpInst::Predicate SwappedPred = Cmp.getSwappedPredicate();
2993 ((Cmp.isUnsigned() && HasNUW) || (Cmp.isSigned() && HasNSW)) &&
2994 !subWithOverflow(SubResult, *C2, C, Cmp.isSigned()))
3003 if (Cmp.isEquality() && C.isZero() &&
3106 Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
3114 const CmpInst::Predicate Pred = Cmp.getPredicate();
3138 return replaceInstUsesWith(Cmp, Cond);
3141 if (Cmp.isEquality() || !match(Y, m_APInt(C2)))
3156 Cmp.isSigned() ? C.ssub_ov(*C2, Overflow) : C.usub_ov(*C2, Overflow);
3174 if (Cmp.isSigned()) {
3210 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
3326 Instruction *InstCombinerImpl::foldICmpSelectConstant(ICmpInst &Cmp,
3330 assert(C && "Cmp RHS should be a constant int!");
3338 if (Cmp.hasOneUse() &&
3344 C1LessThan->getValue(), C->getValue(), Cmp.getPredicate());
3346 Cmp.getPredicate());
3348 C3GreaterThan->getValue(), C->getValue(), Cmp.getPredicate());
3350 // This generates the new instruction that will replace the original Cmp
3357 // the entire original Cmp can be simplified to a false.
3369 return replaceInstUsesWith(Cmp, Cond);
3374 Instruction *InstCombinerImpl::foldICmpBitCast(ICmpInst &Cmp) {
3375 auto *Bitcast = dyn_cast<BitCastInst>(Cmp.getOperand(0));
3379 ICmpInst::Predicate Pred = Cmp.getPredicate();
3380 Value *Op1 = Cmp.getOperand(1);
3415 if (Cmp.isEquality() && match(Op1, m_Zero()))
3449 if (!Cmp.getParent()->getParent()->hasFnAttribute(
3451 Cmp.isEquality() && FPType->isIEEELikeFPTy()) {
3456 return replaceInstUsesWith(Cmp,
3464 if (!match(Cmp.getOperand(1), m_APInt(C)) || !DstType->isIntegerTy() ||
3475 if (Cmp.isEquality() && C->isAllOnes() && Bitcast->hasOneUse()) {
3487 if (Cmp.isEquality() && C->isZero() && Bitcast->hasOneUse() &&
3528 Instruction *InstCombinerImpl::foldICmpInstWithConstant(ICmpInst &Cmp) {
3531 if (match(Cmp.getOperand(1), m_APInt(C))) {
3532 if (auto *BO = dyn_cast<BinaryOperator>(Cmp.getOperand(0)))
3533 if (Instruction *I = foldICmpBinOpWithConstant(Cmp, BO, *C))
3536 if (auto *SI = dyn_cast<SelectInst>(Cmp.getOperand(0)))
3540 if (auto *ConstRHS = dyn_cast<ConstantInt>(Cmp.getOperand(1)))
3541 if (Instruction *I = foldICmpSelectConstant(Cmp, SI, ConstRHS))
3544 if (auto *TI = dyn_cast<TruncInst>(Cmp.getOperand(0)))
3545 if (Instruction *I = foldICmpTruncConstant(Cmp, TI, *C))
3548 if (auto *II = dyn_cast<IntrinsicInst>(Cmp.getOperand(0)))
3549 if (Instruction *I = foldICmpIntrinsicWithConstant(Cmp, II, *C))
3555 Value *Cmp0 = Cmp.getOperand(0);
3557 if (C->isZero() && Cmp.isEquality() && Cmp0->hasOneUse() &&
3564 return new ICmpInst(Cmp.getPredicate(), X, Y);
3567 if (match(Cmp.getOperand(1), m_APIntAllowPoison(C)))
3568 return foldICmpInstWithConstantAllowPoison(Cmp, *C);
3576 ICmpInst &Cmp, BinaryOperator *BO, const APInt &C) {
3579 if (!Cmp.isEquality())
3582 ICmpInst::Predicate Pred = Cmp.getPredicate();
3584 Constant *RHS = cast<Constant>(Cmp.getOperand(1));
3657 Cond->getType() == Cmp.getType()) {
3658 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
3663 Value *Cmp = Builder.CreateICmp(
3666 Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,
3686 Value *Cmp = Builder.CreateICmp(
3689 Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,
3710 Cmp.getOperand(1), BO);
3770 ICmpInst &Cmp, IntrinsicInst *II, const APInt &C) {
3773 const ICmpInst::Predicate Pred = Cmp.getPredicate();
3877 foldICmpIntrinsicWithIntrinsic(ICmpInst &Cmp,
3879 assert(Cmp.isEquality());
3881 ICmpInst::Predicate Pred = Cmp.getPredicate();
3882 Value *Op0 = Cmp.getOperand(0);
3883 Value *Op1 = Cmp.getOperand(1);
3933 InstCombinerImpl::foldICmpInstWithConstantAllowPoison(ICmpInst &Cmp,
3935 const ICmpInst::Predicate Pred = Cmp.getPredicate();
3936 if (auto *II = dyn_cast<IntrinsicInst>(Cmp.getOperand(0))) {
3942 if (Cmp.isEquality() && II->getArgOperand(0) == II->getArgOperand(1)) {
3945 return new ICmpInst(Pred, II->getArgOperand(0), Cmp.getOperand(1));
3955 Instruction *InstCombinerImpl::foldICmpBinOpWithConstant(ICmpInst &Cmp,
3960 if (Instruction *I = foldICmpXorConstant(Cmp, BO, C))
3964 if (Instruction *I = foldICmpAndConstant(Cmp, BO, C))
3968 if (Instruction *I = foldICmpOrConstant(Cmp, BO, C))
3972 if (Instruction *I = foldICmpMulConstant(Cmp, BO, C))
3976 if (Instruction *I = foldICmpShlConstant(Cmp, BO, C))
3981 if (Instruction *I = foldICmpShrConstant(Cmp, BO, C))
3985 if (Instruction *I = foldICmpSRemConstant(Cmp, BO, C))
3989 if (Instruction *I = foldICmpUDivConstant(Cmp, BO, C))
3993 if (Instruction *I = foldICmpDivConstant(Cmp, BO, C))
3997 if (Instruction *I = foldICmpSubConstant(Cmp, BO, C))
4001 if (Instruction *I = foldICmpAddConstant(Cmp, BO, C))
4009 return foldICmpBinOpEqualityWithConstant(Cmp, BO, C);
4154 Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
4157 ICmpInst::Predicate Pred = Cmp.getPredicate();
4170 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
4171 if (Instruction *R = foldCtpopPow2Test(Cmp, II, C, Builder, Q))
4181 if (Cmp.isEquality())
4182 return foldICmpEqIntrinsicWithConstant(Cmp, II, C);
6701 auto isMinMaxCmp = [&](Instruction &Cmp) {
6702 if (!Cmp.hasOneUse())
6705 SelectPatternFlavor SPF = matchSelectPattern(Cmp.user_back(), A, B).Flavor;
7065 static Instruction *foldICmpWithHighBitMask(ICmpInst &Cmp,
7069 if (match(&Cmp,
7081 } else if (match(&Cmp, m_c_ICmp(Pred,
7108 static Instruction *foldVectorCmp(CmpInst &Cmp,
7110 const CmpInst::Predicate Pred = Cmp.getPredicate();
7111 Value *LHS = Cmp.getOperand(0), *RHS = Cmp.getOperand(1);
7115 Value *V = Builder.CreateCmp(Pred, X, Y, Cmp.getName());
7117 I->copyIRFlags(&Cmp);
7118 Module *M = Cmp.getModule();
7640 Value *Cmp = Builder.CreateICmp(Pred, SLTZero, Y, I.getName());
7641 return replaceInstUsesWith(I, Cmp);