Lines Matching defs:Cmp

774         Value *Cmp = Builder.CreateICmp(ICmpInst::getSignedPredicate(Cond),
776 return replaceInstUsesWith(I, Cmp);
1202 Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
1203 CmpInst::Predicate Pred = Cmp.getPredicate();
1204 if (!match(Cmp.getOperand(1), m_Zero()))
1210 if (match(Cmp.getOperand(0), m_SMin(m_Value(A), m_Value(B)))) {
1211 if (isKnownPositive(A, SQ.getWithInstruction(&Cmp)))
1212 return new ICmpInst(Pred, B, Cmp.getOperand(1));
1213 if (isKnownPositive(B, SQ.getWithInstruction(&Cmp)))
1214 return new ICmpInst(Pred, A, Cmp.getOperand(1));
1218 if (Instruction *New = foldIRemByPowerOfTwoToBitTest(Cmp))
1226 if (match(Cmp.getOperand(0), m_URem(m_Value(X), m_Value(Y))) &&
1228 KnownBits XKnown = computeKnownBits(X, 0, &Cmp);
1229 KnownBits YKnown = computeKnownBits(Y, 0, &Cmp);
1231 return new ICmpInst(Pred, X, Cmp.getOperand(1));
1236 if (match(Cmp.getOperand(0), m_Mul(m_Value(X), m_Value(Y))) &&
1239 KnownBits XKnown = computeKnownBits(X, 0, &Cmp);
1243 return new ICmpInst(Pred, Y, Cmp.getOperand(1));
1245 KnownBits YKnown = computeKnownBits(Y, 0, &Cmp);
1249 return new ICmpInst(Pred, X, Cmp.getOperand(1));
1251 auto *BO0 = cast<OverflowingBinaryOperator>(Cmp.getOperand(0));
1253 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
1260 return new ICmpInst(Pred, Y, Cmp.getOperand(1));
1265 return new ICmpInst(Pred, X, Cmp.getOperand(1));
1284 Instruction *InstCombinerImpl::foldICmpWithConstant(ICmpInst &Cmp) {
1296 CmpInst::Predicate Pred = Cmp.getPredicate();
1297 Value *Op0 = Cmp.getOperand(0), *Op1 = Cmp.getOperand(1);
1302 if (Instruction *Res = processUGT_ADDCST_ADD(Cmp, A, B, CI2, CI, *this))
1321 PHINode *NewPhi = Builder.CreatePHI(Cmp.getType(), Phi->getNumOperands());
1324 return replaceInstUsesWith(Cmp, NewPhi);
1327 if (Instruction *R = tryFoldInstWithCtpopWithNot(&Cmp))
1334 Instruction *InstCombinerImpl::foldICmpWithDominatingICmp(ICmpInst &Cmp) {
1337 Value *X = Cmp.getOperand(0), *Y = Cmp.getOperand(1);
1342 CmpInst::Predicate Pred = Cmp.getPredicate();
1353 // Cmp = icmp Pred X, C
1359 return replaceInstUsesWith(Cmp, Builder.getFalse());
1361 return replaceInstUsesWith(Cmp, Builder.getTrue());
1370 if (Cmp.isEquality() || (IsSignBit && hasBranchUse(Cmp)))
1375 if (Cmp.hasOneUse() &&
1376 match(Cmp.user_back(), m_MaxOrMin(m_Value(), m_Value())))
1394 if (DT.dominates(Edge0, Cmp.getParent())) {
1399 if (DT.dominates(Edge1, Cmp.getParent()))
1410 Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp,
1413 ICmpInst::Predicate Pred = Cmp.getPredicate();
1424 if (!Cmp.isSigned() && Trunc->hasNoUnsignedWrap())
1439 if (Cmp.isEquality() && match(X, m_Shl(m_One(), m_Value(Y)))) {
1443 auto NewPred = (Pred == Cmp.ICMP_EQ) ? Cmp.ICMP_UGE : Cmp.ICMP_ULT;
1452 if (Cmp.isEquality() && Trunc->hasOneUse()) {
1465 KnownBits Known = computeKnownBits(X, 0, &Cmp);
1497 InstCombinerImpl::foldICmpTruncWithTruncOrExt(ICmpInst &Cmp,
1503 if (match(&Cmp, m_ICmp(Pred, m_Trunc(m_Value(X)), m_Trunc(m_Value(Y))))) {
1504 unsigned NoWrapFlags = cast<TruncInst>(Cmp.getOperand(0))->getNoWrapKind() &
1505 cast<TruncInst>(Cmp.getOperand(1))->getNoWrapKind();
1506 if (Cmp.isSigned()) {
1518 (!Cmp.getOperand(0)->hasOneUse() || !Cmp.getOperand(1)->hasOneUse()))
1523 Pred = Cmp.getSwappedPredicate(Pred);
1528 else if (!Cmp.isSigned() &&
1529 match(&Cmp, m_c_ICmp(Pred, m_NUWTrunc(m_Value(X)),
1534 else if (match(&Cmp, m_c_ICmp(Pred, m_NSWTrunc(m_Value(X)),
1538 isa<SExtInst>(Cmp.getOperand(0)) || isa<SExtInst>(Cmp.getOperand(1));
1542 Type *TruncTy = Cmp.getOperand(0)->getType();
1556 Instruction *InstCombinerImpl::foldICmpXorConstant(ICmpInst &Cmp,
1559 if (Instruction *I = foldICmpXorShiftConst(Cmp, Xor, C))
1570 ICmpInst::Predicate Pred = Cmp.getPredicate();
1572 if (isSignBitCheck(Cmp.getPredicate(), C, TrueIfSigned)) {
1577 return replaceOperand(Cmp, 0, X);
1590 if (!Cmp.isEquality() && XorC->isSignMask()) {
1591 Pred = Cmp.getFlippedSignednessPredicate();
1596 if (!Cmp.isEquality() && XorC->isMaxSignedValue()) {
1597 Pred = Cmp.getFlippedSignednessPredicate();
1598 Pred = Cmp.getSwappedPredicate(Pred);
1628 Instruction *InstCombinerImpl::foldICmpXorShiftConst(ICmpInst &Cmp,
1631 CmpInst::Predicate Pred = Cmp.getPredicate();
1657 Instruction *InstCombinerImpl::foldICmpAndShift(ICmpInst &Cmp,
1681 if (Cmp.isSigned() && (C2.isNegative() || C1.isNegative()))
1695 if (Cmp.isSigned() && (NewAndCst.isNegative() || NewCmpCst.isNegative()))
1712 if (Cmp.getPredicate() == ICmpInst::ICMP_EQ)
1713 return replaceInstUsesWith(Cmp, ConstantInt::getFalse(Cmp.getType()));
1714 if (Cmp.getPredicate() == ICmpInst::ICMP_NE)
1715 return replaceInstUsesWith(Cmp, ConstantInt::getTrue(Cmp.getType()));
1719 return new ICmpInst(Cmp.getPredicate(),
1727 if (Shift->hasOneUse() && C1.isZero() && Cmp.isEquality() &&
1736 return replaceOperand(Cmp, 0, NewAnd);
1743 Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
1746 bool isICMP_NE = Cmp.getPredicate() == ICmpInst::ICMP_NE;
1751 if (isICMP_NE && Cmp.getType()->isVectorTy() && C1.isZero() &&
1753 return new TruncInst(And->getOperand(0), Cmp.getType());
1764 if (Cmp.isEquality() && C1.isZero()) {
1798 (Cmp.isEquality() || (!C1.isNegative() && !C2->isNegative()))) {
1802 if (!Cmp.getType()->isVectorTy()) {
1808 return new ICmpInst(Cmp.getPredicate(), NewAnd, ZextC1);
1812 if (Instruction *I = foldICmpAndShift(Cmp, And, C1, *C2))
1819 if (!Cmp.isSigned() && C1.isZero() && And->getOperand(0)->hasOneUse() &&
1842 return replaceOperand(Cmp, 0, NewAnd);
1852 if (!Cmp.getParent()->getParent()->hasFnAttribute(
1854 Cmp.isEquality() &&
1864 return replaceInstUsesWith(Cmp, Builder.createIsFPClass(V, Mask));
1873 Instruction *InstCombinerImpl::foldICmpAndConstant(ICmpInst &Cmp,
1876 if (Instruction *I = foldICmpAndConstConst(Cmp, And, C))
1879 const ICmpInst::Predicate Pred = Cmp.getPredicate();
1911 foldCmpLoadFromIndexedGlobal(LI, GEP, GV, Cmp, C2))
1914 if (!Cmp.isEquality())
1920 if (Cmp.getOperand(1) == Y && C.isNegatedPowerOf2()) {
1923 return new ICmpInst(NewPred, X, SubOne(cast<Constant>(Cmp.getOperand(1))));
1936 assert(Cmp.isEquality() && "Not expecting non-equality predicates");
1946 return replaceInstUsesWith(Cmp, R);
1979 static Value *foldICmpOrXorSubChain(ICmpInst &Cmp, BinaryOperator *Or,
2024 ICmpInst::Predicate Pred = Cmp.getPredicate();
2038 Instruction *InstCombinerImpl::foldICmpOrConstant(ICmpInst &Cmp,
2041 ICmpInst::Predicate Pred = Cmp.getPredicate();
2054 if (Cmp.isEquality() && match(OrOp1, m_ImmConstant()) &&
2062 if (match(OrOp1, m_APInt(MaskC)) && Cmp.isEquality()) {
2117 if (!Cmp.isEquality() || !C.isZero() || !Or->hasOneUse())
2132 if (Value *V = foldICmpOrXorSubChain(Cmp, Or, Builder))
2133 return replaceInstUsesWith(Cmp, V);
2139 Instruction *InstCombinerImpl::foldICmpMulConstant(ICmpInst &Cmp,
2142 ICmpInst::Predicate Pred = Cmp.getPredicate();
2149 if (Cmp.isEquality() && C.isZero() && X == Mul->getOperand(1) &&
2172 if (Cmp.isEquality()) {
2230 static Instruction *foldICmpShlOne(ICmpInst &Cmp, Instruction *Shl,
2239 ICmpInst::Predicate Pred = Cmp.getPredicate();
2240 if (Cmp.isUnsigned()) {
2255 } else if (Cmp.isSigned()) {
2274 Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
2278 if (Cmp.isEquality() && match(Shl->getOperand(0), m_APInt(ShiftVal)))
2279 return foldICmpShlConstConst(Cmp, Shl->getOperand(1), C, *ShiftVal);
2281 ICmpInst::Predicate Pred = Cmp.getPredicate();
2288 return new ICmpInst(Pred, Shl->getOperand(0), Cmp.getOperand(1));
2294 return new ICmpInst(Pred, Shl->getOperand(0), Cmp.getOperand(1));
2305 return new ICmpInst(Pred, Shl->getOperand(0), Cmp.getOperand(1));
2309 return foldICmpShlOne(Cmp, Shl, C);
2370 if (Cmp.isEquality() && Shl->hasOneUse()) {
2393 if (Cmp.isUnsigned() && Shl->hasOneUse()) {
2455 Instruction *InstCombinerImpl::foldICmpShrConstant(ICmpInst &Cmp,
2461 CmpInst::Predicate Pred = Cmp.getPredicate();
2462 if (Cmp.isEquality() && Shr->isExact() && C.isZero())
2463 return new ICmpInst(Pred, X, Cmp.getOperand(1));
2468 if (Cmp.isEquality())
2469 return foldICmpShrConstConst(Cmp, Shr->getOperand(1), C, *ShiftValC);
2580 if (!Cmp.isEquality())
2619 Instruction *InstCombinerImpl::foldICmpSRemConstant(ICmpInst &Cmp,
2625 const ICmpInst::Predicate Pred = Cmp.getPredicate();
2670 Instruction *InstCombinerImpl::foldICmpUDivConstant(ICmpInst &Cmp,
2673 ICmpInst::Predicate Pred = Cmp.getPredicate();
2703 Instruction *InstCombinerImpl::foldICmpDivConstant(ICmpInst &Cmp,
2706 ICmpInst::Predicate Pred = Cmp.getPredicate();
2720 if (Cmp.isEquality() && Div->hasOneUse() && C.isSignBitSet() &&
2746 if (!Cmp.isEquality() && DivIsSigned != Cmp.isSigned())
2843 return replaceInstUsesWith(Cmp, Builder.getFalse());
2851 Cmp, insertRangeTest(X, LoBound, HiBound, DivIsSigned, true));
2854 return replaceInstUsesWith(Cmp, Builder.getTrue());
2862 Cmp, insertRangeTest(X, LoBound, HiBound, DivIsSigned, false));
2866 return replaceInstUsesWith(Cmp, Builder.getTrue());
2868 return replaceInstUsesWith(Cmp, Builder.getFalse());
2873 return replaceInstUsesWith(Cmp, Builder.getFalse());
2875 return replaceInstUsesWith(Cmp, Builder.getTrue());
2885 Instruction *InstCombinerImpl::foldICmpSubConstant(ICmpInst &Cmp,
2889 ICmpInst::Predicate Pred = Cmp.getPredicate();
2895 if (Cmp.isEquality() && match(X, m_ImmConstant(SubC))) {
2903 ICmpInst::Predicate SwappedPred = Cmp.getSwappedPredicate();
2907 ((Cmp.isUnsigned() && HasNUW) || (Cmp.isSigned() && HasNSW)) &&
2908 !subWithOverflow(SubResult, *C2, C, Cmp.isSigned()))
2917 if (Cmp.isEquality() && C.isZero() &&
3020 Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
3028 const CmpInst::Predicate Pred = Cmp.getPredicate();
3052 return replaceInstUsesWith(Cmp, Cond);
3055 if (Cmp.isEquality() || !match(Y, m_APInt(C2)))
3070 Cmp.isSigned() ? C.ssub_ov(*C2, Overflow) : C.usub_ov(*C2, Overflow);
3082 if (Cmp.isSigned()) {
3118 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
3212 Instruction *InstCombinerImpl::foldICmpSelectConstant(ICmpInst &Cmp,
3216 assert(C && "Cmp RHS should be a constant int!");
3224 if (Cmp.hasOneUse() &&
3230 C1LessThan->getValue(), C->getValue(), Cmp.getPredicate());
3232 Cmp.getPredicate());
3234 C3GreaterThan->getValue(), C->getValue(), Cmp.getPredicate());
3236 // This generates the new instruction that will replace the original Cmp
3243 // the entire original Cmp can be simplified to a false.
3255 return replaceInstUsesWith(Cmp, Cond);
3260 Instruction *InstCombinerImpl::foldICmpBitCast(ICmpInst &Cmp) {
3261 auto *Bitcast = dyn_cast<BitCastInst>(Cmp.getOperand(0));
3265 ICmpInst::Predicate Pred = Cmp.getPredicate();
3266 Value *Op1 = Cmp.getOperand(1);
3301 if (Cmp.isEquality() && match(Op1, m_Zero()))
3335 if (!Cmp.getParent()->getParent()->hasFnAttribute(
3337 Cmp.isEquality() && FPType->isIEEELikeFPTy()) {
3342 return replaceInstUsesWith(Cmp,
3350 if (!match(Cmp.getOperand(1), m_APInt(C)) || !DstType->isIntegerTy() ||
3361 if (Cmp.isEquality() && C->isAllOnes() && Bitcast->hasOneUse()) {
3373 if (Cmp.isEquality() && C->isZero() && Bitcast->hasOneUse() &&
3414 Instruction *InstCombinerImpl::foldICmpInstWithConstant(ICmpInst &Cmp) {
3417 if (match(Cmp.getOperand(1), m_APInt(C))) {
3418 if (auto *BO = dyn_cast<BinaryOperator>(Cmp.getOperand(0)))
3419 if (Instruction *I = foldICmpBinOpWithConstant(Cmp, BO, *C))
3422 if (auto *SI = dyn_cast<SelectInst>(Cmp.getOperand(0)))
3426 if (auto *ConstRHS = dyn_cast<ConstantInt>(Cmp.getOperand(1)))
3427 if (Instruction *I = foldICmpSelectConstant(Cmp, SI, ConstRHS))
3430 if (auto *TI = dyn_cast<TruncInst>(Cmp.getOperand(0)))
3431 if (Instruction *I = foldICmpTruncConstant(Cmp, TI, *C))
3434 if (auto *II = dyn_cast<IntrinsicInst>(Cmp.getOperand(0)))
3435 if (Instruction *I = foldICmpIntrinsicWithConstant(Cmp, II, *C))
3441 Value *Cmp0 = Cmp.getOperand(0);
3443 if (C->isZero() && Cmp.isEquality() && Cmp0->hasOneUse() &&
3450 return new ICmpInst(Cmp.getPredicate(), X, Y);
3453 if (match(Cmp.getOperand(1), m_APIntAllowPoison(C)))
3454 return foldICmpInstWithConstantAllowPoison(Cmp, *C);
3462 ICmpInst &Cmp, BinaryOperator *BO, const APInt &C) {
3465 if (!Cmp.isEquality())
3468 ICmpInst::Predicate Pred = Cmp.getPredicate();
3470 Constant *RHS = cast<Constant>(Cmp.getOperand(1));
3549 Cmp.getOperand(1), BO);
3609 ICmpInst &Cmp, IntrinsicInst *II, const APInt &C) {
3612 const ICmpInst::Predicate Pred = Cmp.getPredicate();
3716 foldICmpIntrinsicWithIntrinsic(ICmpInst &Cmp,
3718 assert(Cmp.isEquality());
3720 ICmpInst::Predicate Pred = Cmp.getPredicate();
3721 Value *Op0 = Cmp.getOperand(0);
3722 Value *Op1 = Cmp.getOperand(1);
3772 InstCombinerImpl::foldICmpInstWithConstantAllowPoison(ICmpInst &Cmp,
3774 const ICmpInst::Predicate Pred = Cmp.getPredicate();
3775 if (auto *II = dyn_cast<IntrinsicInst>(Cmp.getOperand(0))) {
3781 if (Cmp.isEquality() && II->getArgOperand(0) == II->getArgOperand(1)) {
3784 return new ICmpInst(Pred, II->getArgOperand(0), Cmp.getOperand(1));
3794 Instruction *InstCombinerImpl::foldICmpBinOpWithConstant(ICmpInst &Cmp,
3799 if (Instruction *I = foldICmpXorConstant(Cmp, BO, C))
3803 if (Instruction *I = foldICmpAndConstant(Cmp, BO, C))
3807 if (Instruction *I = foldICmpOrConstant(Cmp, BO, C))
3811 if (Instruction *I = foldICmpMulConstant(Cmp, BO, C))
3815 if (Instruction *I = foldICmpShlConstant(Cmp, BO, C))
3820 if (Instruction *I = foldICmpShrConstant(Cmp, BO, C))
3824 if (Instruction *I = foldICmpSRemConstant(Cmp, BO, C))
3828 if (Instruction *I = foldICmpUDivConstant(Cmp, BO, C))
3832 if (Instruction *I = foldICmpDivConstant(Cmp, BO, C))
3836 if (Instruction *I = foldICmpSubConstant(Cmp, BO, C))
3840 if (Instruction *I = foldICmpAddConstant(Cmp, BO, C))
3848 return foldICmpBinOpEqualityWithConstant(Cmp, BO, C);
3983 Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
3986 ICmpInst::Predicate Pred = Cmp.getPredicate();
3999 const SimplifyQuery Q = SQ.getWithInstruction(&Cmp);
4000 if (Instruction *R = foldCtpopPow2Test(Cmp, II, C, Builder, Q))
4010 if (Cmp.isEquality())
4011 return foldICmpEqIntrinsicWithConstant(Cmp, II, C);
6493 auto isMinMaxCmp = [&](Instruction &Cmp) {
6494 if (!Cmp.hasOneUse())
6497 SelectPatternFlavor SPF = matchSelectPattern(Cmp.user_back(), A, B).Flavor;
6979 static Instruction *foldICmpWithHighBitMask(ICmpInst &Cmp,
6983 if (match(&Cmp,
6995 } else if (match(&Cmp, m_c_ICmp(Pred,
7022 static Instruction *foldVectorCmp(CmpInst &Cmp,
7024 const CmpInst::Predicate Pred = Cmp.getPredicate();
7025 Value *LHS = Cmp.getOperand(0), *RHS = Cmp.getOperand(1);
7029 Value *V = Builder.CreateCmp(Pred, X, Y, Cmp.getName());
7031 I->copyIRFlags(&Cmp);
7032 Module *M = Cmp.getModule();
7554 Value *Cmp = Builder.CreateICmp(Pred, SLTZero, Y, I.getName());
7555 return replaceInstUsesWith(I, Cmp);