Lines Matching defs:Op1

256   BinaryOperator *Op1 = dyn_cast<BinaryOperator>(RHS);
279 if (Op1 && Op1->getOpcode() == Opcode) {
281 Value *B = Op1->getOperand(0);
282 Value *C = Op1->getOperand(1);
323 if (Op1 && Op1->getOpcode() == Opcode) {
325 Value *B = Op1->getOperand(0);
326 Value *C = Op1->getOperand(1);
562 Value *&Op0, Value *&Op1,
565 if (auto *CRHS = dyn_cast<Constant>(Op1)) {
582 std::swap(Op0, Op1);
589 static Value *simplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
591 if (Constant *C = foldOrCommuteConstant(Instruction::Add, Op0, Op1, Q))
595 if (isa<PoisonValue>(Op1))
596 return Op1;
599 if (Q.isUndefValue(Op1))
600 return Op1;
603 if (match(Op1, m_Zero()))
607 if (isKnownNegation(Op0, Op1))
614 if (match(Op1, m_Sub(m_Value(Y), m_Specific(Op0))) ||
615 match(Op0, m_Sub(m_Value(Y), m_Specific(Op1))))
620 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
626 if ((IsNSW || IsNUW) && match(Op1, m_SignMask()) &&
631 if (IsNUW && match(Op1, m_AllOnes()))
632 return Op1; // Which is -1.
636 if (Value *V = simplifyXorInst(Op0, Op1, Q, MaxRecurse - 1))
641 simplifyAssociativeBinOp(Instruction::Add, Op0, Op1, Q, MaxRecurse))
656 Value *llvm::simplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
658 return ::simplifyAddInst(Op0, Op1, IsNSW, IsNUW, Query, RecursionLimit);
706 /// Example: Op0 - Op1 --> 0 when Op0 == Op1
707 static Value *simplifyByDomEq(unsigned Opcode, Value *Op0, Value *Op1,
714 isImpliedByDomCondition(CmpInst::ICMP_EQ, Op0, Op1, Q.CxtI, Q.DL);
730 // Could be either one - choose Op1 since that's more likely a constant.
731 return Op1;
741 static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
743 if (Constant *C = foldOrCommuteConstant(Instruction::Sub, Op0, Op1, Q))
748 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
753 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
757 if (match(Op1, m_Zero()))
761 if (Op0 == Op1)
770 KnownBits Known = computeKnownBits(Op1, /* Depth */ 0, Q);
772 // Op1 is either 0 or the minimum signed value. If the sub is NSW, then
773 // Op1 must be 0 because negating the minimum signed value is undefined.
778 return Op1;
784 Value *X = nullptr, *Y = nullptr, *Z = Op1;
807 if (MaxRecurse && match(Op1, m_Add(m_Value(Y), m_Value(Z)))) { // X - (Y + Z)
829 if (MaxRecurse && match(Op1, m_Sub(m_Value(X), m_Value(Y)))) // Z - (X - Y)
841 match(Op1, m_Trunc(m_Value(Y))))
852 if (match(Op0, m_PtrToInt(m_Value(X))) && match(Op1, m_PtrToInt(m_Value(Y))))
859 if (Value *V = simplifyXorInst(Op0, Op1, Q, MaxRecurse - 1))
871 if (Value *V = simplifyByDomEq(Instruction::Sub, Op0, Op1, Q, MaxRecurse))
877 if (match(Op1, m_Xor(m_Value(X), m_Specific(Op0))) &&
885 Value *llvm::simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
887 return ::simplifySubInst(Op0, Op1, IsNSW, IsNUW, Q, RecursionLimit);
892 static Value *simplifyMulInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
894 if (Constant *C = foldOrCommuteConstant(Instruction::Mul, Op0, Op1, Q))
898 if (isa<PoisonValue>(Op1))
899 return Op1;
903 if (Q.isUndefValue(Op1) || match(Op1, m_Zero()))
907 if (match(Op1, m_One()))
914 m_Exact(m_IDiv(m_Value(X), m_Specific(Op1)))) || // (X / Y) * Y
915 match(Op1, m_Exact(m_IDiv(m_Value(X), m_Specific(Op0)))))) // Y * (X / Y)
926 if (Value *V = simplifyAndInst(Op0, Op1, Q, MaxRecurse - 1))
932 simplifyAssociativeBinOp(Instruction::Mul, Op0, Op1, Q, MaxRecurse))
936 if (Value *V = expandCommutativeBinOp(Instruction::Mul, Op0, Op1,
942 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
944 threadBinOpOverSelect(Instruction::Mul, Op0, Op1, Q, MaxRecurse))
949 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
951 threadBinOpOverPHI(Instruction::Mul, Op0, Op1, Q, MaxRecurse))
957 Value *llvm::simplifyMulInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
959 return ::simplifyMulInst(Op0, Op1, IsNSW, IsNUW, Q, RecursionLimit);
1041 Value *Op1, const SimplifyQuery &Q,
1050 if (Q.isUndefValue(Op1) || isa<PoisonValue>(Op1))
1056 if (match(Op1, m_Zero()))
1076 if (Op0 == Op1)
1079 KnownBits Known = computeKnownBits(Op1, /* Depth */ 0, Q);
1100 if (match(Op0, m_c_Mul(m_Value(X), m_Specific(Op1)))) {
1106 (IsSigned && match(X, m_SDiv(m_Value(), m_Specific(Op1)))) ||
1107 (!IsSigned && match(X, m_UDiv(m_Value(), m_Specific(Op1))))) {
1112 if (isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1115 if (Value *V = simplifyByDomEq(Opcode, Op0, Op1, Q, MaxRecurse))
1120 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1121 if (Value *V = threadBinOpOverSelect(Opcode, Op0, Op1, Q, MaxRecurse))
1126 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1127 if (Value *V = threadBinOpOverPHI(Opcode, Op0, Op1, Q, MaxRecurse))
1134 static Value *simplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
1137 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1140 if (Value *V = simplifyDivRem(Opcode, Op0, Op1, Q, MaxRecurse))
1144 if (IsExact && match(Op1, m_APInt(DivC))) {
1160 ? match(Op0, m_NSWMul(m_Value(X), m_Specific(Op1)))
1161 : match(Op0, m_NUWMul(m_Value(X), m_Specific(Op1)))))
1169 static Value *simplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
1171 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1174 if (Value *V = simplifyDivRem(Opcode, Op0, Op1, Q, MaxRecurse))
1180 match(Op0, m_NSWShl(m_Specific(Op1), m_Value()))) ||
1182 match(Op0, m_NUWShl(m_Specific(Op1), m_Value()))))
1186 if (match(Op1, m_APInt(C0))) {
1206 static Value *simplifySDivInst(Value *Op0, Value *Op1, bool IsExact,
1209 if (isKnownNegation(Op0, Op1, /*NeedNSW=*/true))
1212 return simplifyDiv(Instruction::SDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1215 Value *llvm::simplifySDivInst(Value *Op0, Value *Op1, bool IsExact,
1217 return ::simplifySDivInst(Op0, Op1, IsExact, Q, RecursionLimit);
1222 static Value *simplifyUDivInst(Value *Op0, Value *Op1, bool IsExact,
1224 return simplifyDiv(Instruction::UDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1227 Value *llvm::simplifyUDivInst(Value *Op0, Value *Op1, bool IsExact,
1229 return ::simplifyUDivInst(Op0, Op1, IsExact, Q, RecursionLimit);
1234 static Value *simplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
1239 if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))
1243 if (isKnownNegation(Op0, Op1))
1246 return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
1249 Value *llvm::simplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
1250 return ::simplifySRemInst(Op0, Op1, Q, RecursionLimit);
1255 static Value *simplifyURemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
1257 return simplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse);
1260 Value *llvm::simplifyURemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
1261 return ::simplifyURemInst(Op0, Op1, Q, RecursionLimit);
1297 Value *Op1, bool IsNSW, const SimplifyQuery &Q,
1299 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1314 if (match(Op1, m_Zero()) ||
1315 (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)))
1319 if (isPoisonShift(Op1, Q))
1324 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1325 if (Value *V = threadBinOpOverSelect(Opcode, Op0, Op1, Q, MaxRecurse))
1330 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1331 if (Value *V = threadBinOpOverPHI(Opcode, Op0, Op1, Q, MaxRecurse))
1336 KnownBits KnownAmt = computeKnownBits(Op1, /* Depth */ 0, Q);
1367 Value *Op1, bool IsExact,
1370 simplifyShift(Opcode, Op0, Op1, /*IsNSW*/ false, Q, MaxRecurse))
1374 if (Op0 == Op1)
1395 static Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
1398 simplifyShift(Instruction::Shl, Op0, Op1, IsNSW, Q, MaxRecurse))
1410 match(Op0, m_Exact(m_Shr(m_Value(X), m_Specific(Op1)))))
1423 match(Op1, m_SpecificInt(Ty->getScalarSizeInBits() - 1)))
1429 Value *llvm::simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
1431 return ::simplifyShlInst(Op0, Op1, IsNSW, IsNUW, Q, RecursionLimit);
1436 static Value *simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact,
1438 if (Value *V = simplifyRightShift(Instruction::LShr, Op0, Op1, IsExact, Q,
1444 if (Q.IIQ.UseInstrInfo && match(Op0, m_NUWShl(m_Value(X), m_Specific(Op1))))
1454 if (Q.IIQ.UseInstrInfo && match(Op1, m_APInt(ShRAmt)) &&
1466 Value *llvm::simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact,
1468 return ::simplifyLShrInst(Op0, Op1, IsExact, Q, RecursionLimit);
1473 static Value *simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact,
1475 if (Value *V = simplifyRightShift(Instruction::AShr, Op0, Op1, IsExact, Q,
1483 match(Op0, m_Shl(m_AllOnes(), m_Specific(Op1))))
1488 if (Q.IIQ.UseInstrInfo && match(Op0, m_NSWShl(m_Value(X), m_Specific(Op1))))
1499 Value *llvm::simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact,
1501 return ::simplifyAShrInst(Op0, Op1, IsExact, Q, RecursionLimit);
1652 static Value *simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
1661 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
1665 if (AddInst->getOperand(1) != Op1->getOperand(1))
1720 static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,
1722 if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/true, Q))
1724 if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/true, Q))
1727 if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, true))
1730 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op0, Op1, true))
1732 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op1, Op0, true))
1735 if (Value *X = simplifyAndOfICmpsWithAdd(Op0, Op1, Q.IIQ))
1737 if (Value *X = simplifyAndOfICmpsWithAdd(Op1, Op0, Q.IIQ))
1743 static Value *simplifyOrOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
1752 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
1756 if (AddInst->getOperand(1) != Op1->getOperand(1))
1790 static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,
1792 if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/false, Q))
1794 if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/false, Q))
1797 if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, false))
1800 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op0, Op1, false))
1802 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op1, Op0, false))
1805 if (Value *X = simplifyOrOfICmpsWithAdd(Op0, Op1, Q.IIQ))
1807 if (Value *X = simplifyOrOfICmpsWithAdd(Op1, Op0, Q.IIQ))
1855 Value *Op1, bool IsAnd) {
1858 auto *Cast1 = dyn_cast<CastInst>(Op1);
1862 Op1 = Cast1->getOperand(0);
1867 auto *ICmp1 = dyn_cast<ICmpInst>(Op1);
1873 auto *FCmp1 = dyn_cast<FCmpInst>(Op1);
1897 static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1,
1927 return Op1;
1934 if (Value *Res = simplifyWithOpReplaced(Op1, A, B, Q.getWithoutUndef(),
1938 if (Value *Res = simplifyWithOpReplaced(Op1, B, A, Q.getWithoutUndef(),
1948 static Value *simplifyLogicOfAddSub(Value *Op0, Value *Op1,
1950 assert(Op0->getType() == Op1->getType() && "Mismatched binop types");
1955 match(Op1, m_Sub(m_Constant(C2), m_Specific(X)))) ||
1956 (match(Op1, m_Add(m_Value(X), m_Constant(C1))) &&
1971 static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
1975 if (match(Op0, m_Not(m_Specific(Op1))))
1979 if (match(Op0, m_c_Or(m_Specific(Op1), m_Value())))
1980 return Op1;
1985 match(Op1, m_c_Or(m_Specific(X), m_Specific(Y))))
1991 if (isCheckForZeroAndMulWithOverflow(Op0, Op1, true))
1992 return Op1;
1995 if (match(Op0, m_Neg(m_Specific(Op1))) &&
1996 isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, 0, Q.AC, Q.CxtI, Q.DT))
1997 return Op1;
2001 if (match(Op0, m_Add(m_Specific(Op1), m_AllOnes())) &&
2002 isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, 0, Q.AC, Q.CxtI, Q.DT))
2003 return Constant::getNullValue(Op1->getType());
2009 match(Op1, m_Add(m_Shl(m_Specific(X), m_APInt(Shift2)), m_AllOnes())) &&
2016 simplifyAndOrWithICmpEq(Instruction::And, Op0, Op1, Q, MaxRecurse))
2024 static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
2026 if (Constant *C = foldOrCommuteConstant(Instruction::And, Op0, Op1, Q))
2030 if (isa<PoisonValue>(Op1))
2031 return Op1;
2034 if (Q.isUndefValue(Op1))
2038 if (Op0 == Op1)
2042 if (match(Op1, m_Zero()))
2046 if (match(Op1, m_AllOnes()))
2049 if (Value *Res = simplifyAndCommutative(Op0, Op1, Q, MaxRecurse))
2051 if (Value *Res = simplifyAndCommutative(Op1, Op0, Q, MaxRecurse))
2054 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::And))
2061 if (match(Op1, m_APInt(Mask))) {
2078 if (match(Op1, m_Power2(PowerC)) &&
2085 return ConstantInt::getNullValue(Op1->getType());
2088 if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, true))
2093 simplifyAssociativeBinOp(Instruction::And, Op0, Op1, Q, MaxRecurse))
2097 if (Value *V = expandCommutativeBinOp(Instruction::And, Op0, Op1,
2102 if (Value *V = expandCommutativeBinOp(Instruction::And, Op0, Op1,
2106 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1)) {
2109 if (match(Op1, m_Select(m_Specific(Op0), m_Value(), m_Zero())))
2110 return Op1;
2111 else if (match(Op0, m_Select(m_Specific(Op1), m_Value(), m_Zero())))
2118 threadBinOpOverSelect(Instruction::And, Op0, Op1, Q, MaxRecurse))
2124 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2126 threadBinOpOverPHI(Instruction::And, Op0, Op1, Q, MaxRecurse))
2140 if (Q.IIQ.UseInstrInfo && match(Op1, m_APInt(Mask)) &&
2168 match(Op1, m_c_Xor(m_Specific(Or), m_Specific(Y))))
2175 match(Op1, m_Xor(m_Specific(A), m_SpecificInt(~*C1))))
2179 if (std::optional<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL)) {
2180 // If Op0 is true implies Op1 is true, then Op0 is a subset of Op1.
2183 // If Op0 is true implies Op1 is false, then they are not true together.
2187 if (std::optional<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL)) {
2188 // If Op1 is true implies Op0 is true, then Op1 is a subset of Op0.
2190 return Op1;
2191 // If Op1 is true implies Op0 is false, then they are not true together.
2193 return ConstantInt::getFalse(Op1->getType());
2197 if (Value *V = simplifyByDomEq(Instruction::And, Op0, Op1, Q, MaxRecurse))
2203 Value *llvm::simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
2204 return ::simplifyAndInst(Op0, Op1, Q, RecursionLimit);
2299 static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
2301 if (Constant *C = foldOrCommuteConstant(Instruction::Or, Op0, Op1, Q))
2305 if (isa<PoisonValue>(Op1))
2306 return Op1;
2310 // Do not return Op1 because it may contain undef elements if it's a vector.
2311 if (Q.isUndefValue(Op1) || match(Op1, m_AllOnes()))
2316 if (Op0 == Op1 || match(Op1, m_Zero()))
2319 if (Value *R = simplifyOrLogic(Op0, Op1))
2321 if (Value *R = simplifyOrLogic(Op1, Op0))
2324 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Or))
2333 match(Op1, m_LShr(m_AllOnes(), m_Value(Y)))) ||
2334 (match(Op1, m_Shl(m_AllOnes(), m_Value(X))) &&
2351 match(Op1, m_Shl(m_Specific(X), m_Specific(Y))))
2353 if (match(Op1,
2356 return Op1;
2362 match(Op1, m_LShr(m_Specific(X), m_Specific(Y))))
2364 if (match(Op1,
2367 return Op1;
2370 simplifyAndOrWithICmpEq(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2373 simplifyAndOrWithICmpEq(Instruction::Or, Op1, Op0, Q, MaxRecurse))
2376 if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, false))
2382 if (isCheckForZeroAndMulWithOverflow(Op0, Op1, false))
2383 return Op1;
2384 if (isCheckForZeroAndMulWithOverflow(Op1, Op0, false))
2389 simplifyAssociativeBinOp(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2393 if (Value *V = expandCommutativeBinOp(Instruction::Or, Op0, Op1,
2397 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1)) {
2400 if (match(Op1, m_Select(m_Specific(Op0), m_One(), m_Value())))
2401 return Op1;
2402 else if (match(Op0, m_Select(m_Specific(Op1), m_One(), m_Value())))
2409 threadBinOpOverSelect(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2417 match(Op1, m_And(m_Value(B), m_APInt(C2)))) {
2441 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2442 if (Value *V = threadBinOpOverPHI(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2447 match(Op1, m_Xor(m_Specific(A), m_SpecificInt(~*C1))))
2452 isImpliedCondition(Op0, Op1, Q.DL, false)) {
2453 // If Op0 is false implies Op1 is false, then Op1 is a subset of Op0.
2456 // If Op0 is false implies Op1 is true, then at least one is always true.
2461 isImpliedCondition(Op1, Op0, Q.DL, false)) {
2462 // If Op1 is false implies Op0 is false, then Op0 is a subset of Op1.
2464 return Op1;
2465 // If Op1 is false implies Op0 is true, then at least one is always true.
2467 return ConstantInt::getTrue(Op1->getType());
2471 if (Value *V = simplifyByDomEq(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2477 Value *llvm::simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
2478 return ::simplifyOrInst(Op0, Op1, Q, RecursionLimit);
2483 static Value *simplifyXorInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
2485 if (Constant *C = foldOrCommuteConstant(Instruction::Xor, Op0, Op1, Q))
2489 if (isa<PoisonValue>(Op1))
2490 return Op1;
2493 if (Q.isUndefValue(Op1))
2494 return Op1;
2497 if (match(Op1, m_Zero()))
2501 if (Op0 == Op1)
2505 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
2526 if (Value *R = foldAndOrNot(Op0, Op1))
2528 if (Value *R = foldAndOrNot(Op1, Op0))
2531 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Xor))
2536 simplifyAssociativeBinOp(Instruction::Xor, Op0, Op1, Q, MaxRecurse))
2548 if (Value *V = simplifyByDomEq(Instruction::Xor, Op0, Op1, Q, MaxRecurse))
2554 if (match(Op0, m_NUWSub(m_Specific(Op1), m_Value(X))) &&
2555 match(Op1, m_LowBitMask()))
2562 Value *llvm::simplifyXorInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
2563 return ::simplifyXorInst(Op0, Op1, Q, RecursionLimit);
5407 static Value *foldIdentityShuffles(int DestElt, Value *Op0, Value *Op1,
5424 SourceOp = Op1;
5452 static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
5484 Op1 = PoisonValue::get(InVecTy);
5488 auto *Op1Const = dyn_cast<Constant>(Op1);
5500 std::swap(Op0, Op1);
5520 assert(isa<UndefValue>(Op1) && "Expected undef operand 1 for splat");
5534 if (Q.isUndefValue(Op1) && RetTy == InVecTy &&
5558 foldIdentityShuffles(i, Op0, Op1, Indices[i], RootVec, MaxRecurse);
5568 Value *llvm::simplifyShuffleVectorInst(Value *Op0, Value *Op1,
5571 return ::simplifyShuffleVectorInst(Op0, Op1, Mask, RetTy, Q, RecursionLimit);
5687 simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5692 if (Constant *C = foldOrCommuteConstant(Instruction::FAdd, Op0, Op1, Q))
5695 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5706 if (match(Op1, m_NegZeroFP()))
5711 if (match(Op1, m_PosZeroFP()) &&
5720 if (match(Op1, m_Inf()))
5721 return Op1;
5730 if (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
5731 match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0))))
5734 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
5735 match(Op1, m_FNeg(m_Specific(Op0))))
5743 (match(Op0, m_FSub(m_Value(X), m_Specific(Op1))) ||
5744 match(Op1, m_FSub(m_Value(X), m_Specific(Op0)))))
5753 simplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5758 if (Constant *C = foldOrCommuteConstant(Instruction::FSub, Op0, Op1, Q))
5761 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5768 if (match(Op1, m_PosZeroFP()))
5773 if (match(Op1, m_NegZeroFP()) &&
5781 if (match(Op0, m_NegZeroFP()) && match(Op1, m_FNeg(m_Value(X))))
5788 (match(Op1, m_FSub(m_AnyZeroFP(), m_Value(X))) ||
5789 match(Op1, m_FNeg(m_Value(X)))))
5797 if (Op0 == Op1)
5805 if (match(Op1, m_Inf()))
5806 return foldConstant(Instruction::FNeg, Op1, Q);
5812 (match(Op1, m_FSub(m_Specific(Op0), m_Value(X))) ||
5813 match(Op0, m_c_FAdd(m_Specific(Op1), m_Value(X)))))
5819 static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
5823 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5831 std::swap(Op0, Op1);
5834 if (match(Op1, m_FPOne()))
5837 if (match(Op1, m_AnyZeroFP())) {
5847 return Op1;
5850 return foldConstant(Instruction::FNeg, Op1, Q);
5859 if (Op0 == Op1 && match(Op0, m_Sqrt(m_Value(X))) && FMF.allowReassoc() &&
5868 simplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5873 if (Constant *C = foldOrCommuteConstant(Instruction::FMul, Op0, Op1, Q))
5877 return simplifyFMAFMul(Op0, Op1, FMF, Q, MaxRecurse, ExBehavior, Rounding);
5880 Value *llvm::simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5884 return ::simplifyFAddInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5888 Value *llvm::simplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5892 return ::simplifyFSubInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5896 Value *llvm::simplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5900 return ::simplifyFMulInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5904 Value *llvm::simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
5908 return ::simplifyFMAFMul(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5913 simplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5918 if (Constant *C = foldOrCommuteConstant(Instruction::FDiv, Op0, Op1, Q))
5921 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5928 if (match(Op1, m_FPOne()))
5940 if (Op0 == Op1)
5945 if (FMF.allowReassoc() && match(Op0, m_c_FMul(m_Value(X), m_Specific(Op1))))
5951 if (match(Op0, m_FNegNSZ(m_Specific(Op1))) ||
5952 match(Op1, m_FNegNSZ(m_Specific(Op0))))
5956 if (FMF.noInfs() && match(Op1, m_AnyZeroFP()))
5957 return PoisonValue::get(Op1->getType());
5963 Value *llvm::simplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5967 return ::simplifyFDivInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5972 simplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5977 if (Constant *C = foldOrCommuteConstant(Instruction::FRem, Op0, Op1, Q))
5980 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
6001 Value *llvm::simplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
6005 return ::simplifyFRemInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
6230 static Value *simplifyLdexp(Value *Op0, Value *Op1, const SimplifyQuery &Q,
6234 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
6245 if (Q.isUndefValue(Op1))
6273 if (match(Op1, PatternMatch::m_ZeroInt()))
6398 static Value *foldMinMaxSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1) {
6408 if (Op1 == X || Op1 == Y ||
6409 match(Op1, m_c_MaxOrMin(m_Specific(X), m_Specific(Y)))) {
6415 return Op1;
6424 Value *Op1) {
6443 if (X0 == Op1 || Y0 == Op1)
6446 auto *M1 = dyn_cast<IntrinsicInst>(Op1);
6466 Value *Op0, Value *Op1,
6494 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
6497 // NOTE: We can't apply this simplifications based on the value of Op1
6502 assert(Op1->getType()->getScalarSizeInBits() ==
6507 if (match(Op1, m_PtrToInt(m_Specific(Op0))))
6513 if (match(Op1, m_AllOnes()) || Q.isUndefValue(Op1))
6517 if (match(Op1, m_ImmConstant(C))) {
6536 if (Op0 == Op1)
6539 // Canonicalize immediate constant operand as Op1.
6541 std::swap(Op0, Op1);
6544 if (Q.isUndefValue(Op1))
6549 if (match(Op1, m_APIntAllowPoison(C))) {
6577 if (Value *V = foldMinMaxSharedOp(IID, Op0, Op1))
6579 if (Value *V = foldMinMaxSharedOp(IID, Op1, Op0))
6584 if (isICmpTrue(Pred, Op0, Op1, Q.getWithoutUndef(), RecursionLimit))
6586 if (isICmpTrue(Pred, Op1, Op0, Q.getWithoutUndef(), RecursionLimit))
6587 return Op1;
6595 if (isICmpTrue(CmpInst::ICMP_EQ, Op0, Op1, Q, RecursionLimit))
6600 if (isICmpTrue(PredGT, Op0, Op1, Q, RecursionLimit))
6605 if (isICmpTrue(PredLT, Op0, Op1, Q, RecursionLimit))
6615 if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6622 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1)) {
6633 if (match(Op0, m_Zero()) || match(Op1, m_Zero()))
6637 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6643 if (match(Op0, m_AllOnes()) || match(Op1, m_AllOnes()))
6651 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6655 if (match(Op1, m_Zero()))
6659 return Op1;
6663 if (match(Op0, m_Zero()) || match(Op1, m_AllOnes()))
6668 if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6671 if (match(Op1, m_Zero()))
6676 if (auto *C1 = dyn_cast<Constant>(Op1))
6680 if (auto *Power = dyn_cast<ConstantInt>(Op1)) {
6690 return simplifyLdexp(Op0, Op1, Q, false);
6693 if (Op0 == Op1)
6697 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
6698 match(Op1, m_FNeg(m_Specific(Op0))))
6699 return Op1;
6705 uint64_t Mask = cast<ConstantInt>(Op1)->getZExtValue();
6720 if (Op0 == Op1)
6723 // Canonicalize constant operand as Op1.
6725 std::swap(Op0, Op1);
6728 if (Q.isUndefValue(Op1))
6738 if (match(Op1, m_NaN()))
6739 return PropagateNaN ? propagateNaN(cast<Constant>(Op1)) : Op0;
6744 if (match(Op1, m_APFloat(C)) &&
6765 if (Value *V = foldMinimumMaximumSharedOp(IID, Op0, Op1))
6767 if (Value *V = foldMinimumMaximumSharedOp(IID, Op1, Op0))
6774 unsigned IdxN = cast<ConstantInt>(Op1)->getZExtValue();
6835 Value *Op0 = Args[0], *Op1 = Args[1], *ShAmtArg = Args[2];
6838 if (Q.isUndefValue(Op0) && Q.isUndefValue(Op1))
6854 if (match(Op0, m_Zero()) && match(Op1, m_Zero()))
6858 if (match(Op0, m_AllOnes()) && match(Op1, m_AllOnes()))
6880 Value *Op1 = Args[1];
6884 // Canonicalize constant operand as Op1 (ConstantFolding handles the case
6885 // when both Op0 and Op1 are constant so we do not care about that special
6888 std::swap(Op0, Op1);
6891 if (match(Op1, m_Zero()))
6895 if (Q.isUndefValue(Op1))
6902 if (ScaledOne.isNonNegative() && match(Op1, m_SpecificInt(ScaledOne)))