Lines Matching defs:Op1

301   BinaryOperator *Op1 = dyn_cast<BinaryOperator>(RHS);
324 if (Op1 && Op1->getOpcode() == Opcode) {
326 Value *B = Op1->getOperand(0);
327 Value *C = Op1->getOperand(1);
368 if (Op1 && Op1->getOpcode() == Opcode) {
370 Value *B = Op1->getOperand(0);
371 Value *C = Op1->getOperand(1);
608 Value *&Op0, Value *&Op1,
611 if (auto *CRHS = dyn_cast<Constant>(Op1)) {
628 std::swap(Op0, Op1);
635 static Value *simplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
637 if (Constant *C = foldOrCommuteConstant(Instruction::Add, Op0, Op1, Q))
641 if (isa<PoisonValue>(Op1))
642 return Op1;
645 if (Q.isUndefValue(Op1))
646 return Op1;
649 if (match(Op1, m_Zero()))
653 if (isKnownNegation(Op0, Op1))
660 if (match(Op1, m_Sub(m_Value(Y), m_Specific(Op0))) ||
661 match(Op0, m_Sub(m_Value(Y), m_Specific(Op1))))
666 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
672 if ((IsNSW || IsNUW) && match(Op1, m_SignMask()) &&
677 if (IsNUW && match(Op1, m_AllOnes()))
678 return Op1; // Which is -1.
682 if (Value *V = simplifyXorInst(Op0, Op1, Q, MaxRecurse - 1))
687 simplifyAssociativeBinOp(Instruction::Add, Op0, Op1, Q, MaxRecurse))
702 Value *llvm::simplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
704 return ::simplifyAddInst(Op0, Op1, IsNSW, IsNUW, Query, RecursionLimit);
752 /// Example: Op0 - Op1 --> 0 when Op0 == Op1
753 static Value *simplifyByDomEq(unsigned Opcode, Value *Op0, Value *Op1,
760 isImpliedByDomCondition(CmpInst::ICMP_EQ, Op0, Op1, Q.CxtI, Q.DL);
776 // Could be either one - choose Op1 since that's more likely a constant.
777 return Op1;
787 static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
789 if (Constant *C = foldOrCommuteConstant(Instruction::Sub, Op0, Op1, Q))
794 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
799 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
803 if (match(Op1, m_Zero()))
807 if (Op0 == Op1)
816 KnownBits Known = computeKnownBits(Op1, /* Depth */ 0, Q);
818 // Op1 is either 0 or the minimum signed value. If the sub is NSW, then
819 // Op1 must be 0 because negating the minimum signed value is undefined.
824 return Op1;
830 Value *X = nullptr, *Y = nullptr, *Z = Op1;
853 if (MaxRecurse && match(Op1, m_Add(m_Value(Y), m_Value(Z)))) { // X - (Y + Z)
875 if (MaxRecurse && match(Op1, m_Sub(m_Value(X), m_Value(Y)))) // Z - (X - Y)
887 match(Op1, m_Trunc(m_Value(Y))))
898 if (match(Op0, m_PtrToInt(m_Value(X))) && match(Op1, m_PtrToInt(m_Value(Y))))
905 if (Value *V = simplifyXorInst(Op0, Op1, Q, MaxRecurse - 1))
917 if (Value *V = simplifyByDomEq(Instruction::Sub, Op0, Op1, Q, MaxRecurse))
923 Value *llvm::simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
925 return ::simplifySubInst(Op0, Op1, IsNSW, IsNUW, Q, RecursionLimit);
930 static Value *simplifyMulInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
932 if (Constant *C = foldOrCommuteConstant(Instruction::Mul, Op0, Op1, Q))
936 if (isa<PoisonValue>(Op1))
937 return Op1;
941 if (Q.isUndefValue(Op1) || match(Op1, m_Zero()))
945 if (match(Op1, m_One()))
952 m_Exact(m_IDiv(m_Value(X), m_Specific(Op1)))) || // (X / Y) * Y
953 match(Op1, m_Exact(m_IDiv(m_Value(X), m_Specific(Op0)))))) // Y * (X / Y)
964 if (Value *V = simplifyAndInst(Op0, Op1, Q, MaxRecurse - 1))
970 simplifyAssociativeBinOp(Instruction::Mul, Op0, Op1, Q, MaxRecurse))
974 if (Value *V = expandCommutativeBinOp(Instruction::Mul, Op0, Op1,
980 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
982 threadBinOpOverSelect(Instruction::Mul, Op0, Op1, Q, MaxRecurse))
987 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
989 threadBinOpOverPHI(Instruction::Mul, Op0, Op1, Q, MaxRecurse))
995 Value *llvm::simplifyMulInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
997 return ::simplifyMulInst(Op0, Op1, IsNSW, IsNUW, Q, RecursionLimit);
1079 Value *Op1, const SimplifyQuery &Q,
1088 if (Q.isUndefValue(Op1) || isa<PoisonValue>(Op1))
1094 if (match(Op1, m_Zero()))
1099 auto *Op1C = dyn_cast<Constant>(Op1);
1127 if (Op0 == Op1)
1130 KnownBits Known = computeKnownBits(Op1, /* Depth */ 0, Q);
1151 if (match(Op0, m_c_Mul(m_Value(X), m_Specific(Op1)))) {
1157 (IsSigned && match(X, m_SDiv(m_Value(), m_Specific(Op1)))) ||
1158 (!IsSigned && match(X, m_UDiv(m_Value(), m_Specific(Op1))))) {
1163 if (isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1166 if (Value *V = simplifyByDomEq(Opcode, Op0, Op1, Q, MaxRecurse))
1171 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1172 if (Value *V = threadBinOpOverSelect(Opcode, Op0, Op1, Q, MaxRecurse))
1177 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1178 if (Value *V = threadBinOpOverPHI(Opcode, Op0, Op1, Q, MaxRecurse))
1185 static Value *simplifyDiv(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
1188 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1191 if (Value *V = simplifyDivRem(Opcode, Op0, Op1, Q, MaxRecurse))
1195 if (IsExact && match(Op1, m_APInt(DivC))) {
1211 ? match(Op0, m_NSWMul(m_Value(X), m_Specific(Op1)))
1212 : match(Op0, m_NUWMul(m_Value(X), m_Specific(Op1)))))
1220 static Value *simplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
1222 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1225 if (Value *V = simplifyDivRem(Opcode, Op0, Op1, Q, MaxRecurse))
1231 match(Op0, m_NSWShl(m_Specific(Op1), m_Value()))) ||
1233 match(Op0, m_NUWShl(m_Specific(Op1), m_Value()))))
1237 if (match(Op1, m_APInt(C0))) {
1257 static Value *simplifySDivInst(Value *Op0, Value *Op1, bool IsExact,
1260 if (isKnownNegation(Op0, Op1, /*NeedNSW=*/true))
1263 return simplifyDiv(Instruction::SDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1266 Value *llvm::simplifySDivInst(Value *Op0, Value *Op1, bool IsExact,
1268 return ::simplifySDivInst(Op0, Op1, IsExact, Q, RecursionLimit);
1273 static Value *simplifyUDivInst(Value *Op0, Value *Op1, bool IsExact,
1275 return simplifyDiv(Instruction::UDiv, Op0, Op1, IsExact, Q, MaxRecurse);
1278 Value *llvm::simplifyUDivInst(Value *Op0, Value *Op1, bool IsExact,
1280 return ::simplifyUDivInst(Op0, Op1, IsExact, Q, RecursionLimit);
1285 static Value *simplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
1290 if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))
1294 if (isKnownNegation(Op0, Op1))
1297 return simplifyRem(Instruction::SRem, Op0, Op1, Q, MaxRecurse);
1300 Value *llvm::simplifySRemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
1301 return ::simplifySRemInst(Op0, Op1, Q, RecursionLimit);
1306 static Value *simplifyURemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
1308 return simplifyRem(Instruction::URem, Op0, Op1, Q, MaxRecurse);
1311 Value *llvm::simplifyURemInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
1312 return ::simplifyURemInst(Op0, Op1, Q, RecursionLimit);
1348 Value *Op1, bool IsNSW, const SimplifyQuery &Q,
1350 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1365 if (match(Op1, m_Zero()) ||
1366 (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)))
1370 if (isPoisonShift(Op1, Q))
1375 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1))
1376 if (Value *V = threadBinOpOverSelect(Opcode, Op0, Op1, Q, MaxRecurse))
1381 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
1382 if (Value *V = threadBinOpOverPHI(Opcode, Op0, Op1, Q, MaxRecurse))
1387 KnownBits KnownAmt = computeKnownBits(Op1, /* Depth */ 0, Q);
1418 Value *Op1, bool IsExact,
1421 simplifyShift(Opcode, Op0, Op1, /*IsNSW*/ false, Q, MaxRecurse))
1425 if (Op0 == Op1)
1446 static Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
1449 simplifyShift(Instruction::Shl, Op0, Op1, IsNSW, Q, MaxRecurse))
1461 match(Op0, m_Exact(m_Shr(m_Value(X), m_Specific(Op1)))))
1474 match(Op1, m_SpecificInt(Ty->getScalarSizeInBits() - 1)))
1480 Value *llvm::simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
1482 return ::simplifyShlInst(Op0, Op1, IsNSW, IsNUW, Q, RecursionLimit);
1487 static Value *simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact,
1489 if (Value *V = simplifyRightShift(Instruction::LShr, Op0, Op1, IsExact, Q,
1495 if (Q.IIQ.UseInstrInfo && match(Op0, m_NUWShl(m_Value(X), m_Specific(Op1))))
1505 if (Q.IIQ.UseInstrInfo && match(Op1, m_APInt(ShRAmt)) &&
1517 Value *llvm::simplifyLShrInst(Value *Op0, Value *Op1, bool IsExact,
1519 return ::simplifyLShrInst(Op0, Op1, IsExact, Q, RecursionLimit);
1524 static Value *simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact,
1526 if (Value *V = simplifyRightShift(Instruction::AShr, Op0, Op1, IsExact, Q,
1534 match(Op0, m_Shl(m_AllOnes(), m_Specific(Op1))))
1539 if (Q.IIQ.UseInstrInfo && match(Op0, m_NSWShl(m_Value(X), m_Specific(Op1))))
1550 Value *llvm::simplifyAShrInst(Value *Op0, Value *Op1, bool IsExact,
1552 return ::simplifyAShrInst(Op0, Op1, IsExact, Q, RecursionLimit);
1703 static Value *simplifyAndOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
1712 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
1716 if (AddInst->getOperand(1) != Op1->getOperand(1))
1771 static Value *simplifyAndOfICmps(ICmpInst *Op0, ICmpInst *Op1,
1773 if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/true, Q))
1775 if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/true, Q))
1778 if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, true))
1781 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op0, Op1, true))
1783 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op1, Op0, true))
1786 if (Value *X = simplifyAndOfICmpsWithAdd(Op0, Op1, Q.IIQ))
1788 if (Value *X = simplifyAndOfICmpsWithAdd(Op1, Op0, Q.IIQ))
1794 static Value *simplifyOrOfICmpsWithAdd(ICmpInst *Op0, ICmpInst *Op1,
1803 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
1807 if (AddInst->getOperand(1) != Op1->getOperand(1))
1841 static Value *simplifyOrOfICmps(ICmpInst *Op0, ICmpInst *Op1,
1843 if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/false, Q))
1845 if (Value *X = simplifyUnsignedRangeCheck(Op1, Op0, /*IsAnd=*/false, Q))
1848 if (Value *X = simplifyAndOrOfICmpsWithConstants(Op0, Op1, false))
1851 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op0, Op1, false))
1853 if (Value *X = simplifyAndOrOfICmpsWithCtpop(Op1, Op0, false))
1856 if (Value *X = simplifyOrOfICmpsWithAdd(Op0, Op1, Q.IIQ))
1858 if (Value *X = simplifyOrOfICmpsWithAdd(Op1, Op0, Q.IIQ))
1902 Value *Op1, bool IsAnd) {
1905 auto *Cast1 = dyn_cast<CastInst>(Op1);
1909 Op1 = Cast1->getOperand(0);
1914 auto *ICmp1 = dyn_cast<ICmpInst>(Op1);
1920 auto *FCmp1 = dyn_cast<FCmpInst>(Op1);
1944 static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1,
1974 return Op1;
1981 if (Value *Res = simplifyWithOpReplaced(Op1, A, B, Q.getWithoutUndef(),
1985 if (Value *Res = simplifyWithOpReplaced(Op1, B, A, Q.getWithoutUndef(),
1995 static Value *simplifyLogicOfAddSub(Value *Op0, Value *Op1,
1997 assert(Op0->getType() == Op1->getType() && "Mismatched binop types");
2002 match(Op1, m_Sub(m_Constant(C2), m_Specific(X)))) ||
2003 (match(Op1, m_Add(m_Value(X), m_Constant(C1))) &&
2018 static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
2022 if (match(Op0, m_Not(m_Specific(Op1))))
2026 if (match(Op0, m_c_Or(m_Specific(Op1), m_Value())))
2027 return Op1;
2032 match(Op1, m_c_Or(m_Specific(X), m_Specific(Y))))
2038 if (isCheckForZeroAndMulWithOverflow(Op0, Op1, true))
2039 return Op1;
2042 if (match(Op0, m_Neg(m_Specific(Op1))) &&
2043 isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, 0, Q.AC, Q.CxtI, Q.DT))
2044 return Op1;
2048 if (match(Op0, m_Add(m_Specific(Op1), m_AllOnes())) &&
2049 isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, 0, Q.AC, Q.CxtI, Q.DT))
2050 return Constant::getNullValue(Op1->getType());
2056 match(Op1, m_Add(m_Shl(m_Specific(X), m_APInt(Shift2)), m_AllOnes())) &&
2063 simplifyAndOrWithICmpEq(Instruction::And, Op0, Op1, Q, MaxRecurse))
2071 static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
2073 if (Constant *C = foldOrCommuteConstant(Instruction::And, Op0, Op1, Q))
2077 if (isa<PoisonValue>(Op1))
2078 return Op1;
2081 if (Q.isUndefValue(Op1))
2085 if (Op0 == Op1)
2089 if (match(Op1, m_Zero()))
2093 if (match(Op1, m_AllOnes()))
2096 if (Value *Res = simplifyAndCommutative(Op0, Op1, Q, MaxRecurse))
2098 if (Value *Res = simplifyAndCommutative(Op1, Op0, Q, MaxRecurse))
2101 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::And))
2108 if (match(Op1, m_APInt(Mask))) {
2125 if (match(Op1, m_Power2(PowerC)) &&
2132 return ConstantInt::getNullValue(Op1->getType());
2135 if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, true))
2140 simplifyAssociativeBinOp(Instruction::And, Op0, Op1, Q, MaxRecurse))
2144 if (Value *V = expandCommutativeBinOp(Instruction::And, Op0, Op1,
2149 if (Value *V = expandCommutativeBinOp(Instruction::And, Op0, Op1,
2153 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1)) {
2156 if (match(Op1, m_Select(m_Specific(Op0), m_Value(), m_Zero())))
2157 return Op1;
2158 else if (match(Op0, m_Select(m_Specific(Op1), m_Value(), m_Zero())))
2165 threadBinOpOverSelect(Instruction::And, Op0, Op1, Q, MaxRecurse))
2171 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2173 threadBinOpOverPHI(Instruction::And, Op0, Op1, Q, MaxRecurse))
2187 if (Q.IIQ.UseInstrInfo && match(Op1, m_APInt(Mask)) &&
2215 match(Op1, m_c_Xor(m_Specific(Or), m_Specific(Y))))
2222 match(Op1, m_Xor(m_Specific(A), m_SpecificInt(~*C1))))
2226 if (std::optional<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL)) {
2227 // If Op0 is true implies Op1 is true, then Op0 is a subset of Op1.
2230 // If Op0 is true implies Op1 is false, then they are not true together.
2234 if (std::optional<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL)) {
2235 // If Op1 is true implies Op0 is true, then Op1 is a subset of Op0.
2237 return Op1;
2238 // If Op1 is true implies Op0 is false, then they are not true together.
2240 return ConstantInt::getFalse(Op1->getType());
2244 if (Value *V = simplifyByDomEq(Instruction::And, Op0, Op1, Q, MaxRecurse))
2250 Value *llvm::simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
2251 return ::simplifyAndInst(Op0, Op1, Q, RecursionLimit);
2346 static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
2348 if (Constant *C = foldOrCommuteConstant(Instruction::Or, Op0, Op1, Q))
2352 if (isa<PoisonValue>(Op1))
2353 return Op1;
2357 // Do not return Op1 because it may contain undef elements if it's a vector.
2358 if (Q.isUndefValue(Op1) || match(Op1, m_AllOnes()))
2363 if (Op0 == Op1 || match(Op1, m_Zero()))
2366 if (Value *R = simplifyOrLogic(Op0, Op1))
2368 if (Value *R = simplifyOrLogic(Op1, Op0))
2371 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Or))
2380 match(Op1, m_LShr(m_AllOnes(), m_Value(Y)))) ||
2381 (match(Op1, m_Shl(m_AllOnes(), m_Value(X))) &&
2398 match(Op1, m_Shl(m_Specific(X), m_Specific(Y))))
2400 if (match(Op1,
2403 return Op1;
2409 match(Op1, m_LShr(m_Specific(X), m_Specific(Y))))
2411 if (match(Op1,
2414 return Op1;
2417 simplifyAndOrWithICmpEq(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2420 simplifyAndOrWithICmpEq(Instruction::Or, Op1, Op0, Q, MaxRecurse))
2423 if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, false))
2429 if (isCheckForZeroAndMulWithOverflow(Op0, Op1, false))
2430 return Op1;
2431 if (isCheckForZeroAndMulWithOverflow(Op1, Op0, false))
2436 simplifyAssociativeBinOp(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2440 if (Value *V = expandCommutativeBinOp(Instruction::Or, Op0, Op1,
2444 if (isa<SelectInst>(Op0) || isa<SelectInst>(Op1)) {
2447 if (match(Op1, m_Select(m_Specific(Op0), m_One(), m_Value())))
2448 return Op1;
2449 else if (match(Op0, m_Select(m_Specific(Op1), m_One(), m_Value())))
2456 threadBinOpOverSelect(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2464 match(Op1, m_And(m_Value(B), m_APInt(C2)))) {
2488 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2489 if (Value *V = threadBinOpOverPHI(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2494 match(Op1, m_Xor(m_Specific(A), m_SpecificInt(~*C1))))
2499 isImpliedCondition(Op0, Op1, Q.DL, false)) {
2500 // If Op0 is false implies Op1 is false, then Op1 is a subset of Op0.
2503 // If Op0 is false implies Op1 is true, then at least one is always true.
2508 isImpliedCondition(Op1, Op0, Q.DL, false)) {
2509 // If Op1 is false implies Op0 is false, then Op0 is a subset of Op1.
2511 return Op1;
2512 // If Op1 is false implies Op0 is true, then at least one is always true.
2514 return ConstantInt::getTrue(Op1->getType());
2518 if (Value *V = simplifyByDomEq(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2524 Value *llvm::simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
2525 return ::simplifyOrInst(Op0, Op1, Q, RecursionLimit);
2530 static Value *simplifyXorInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
2532 if (Constant *C = foldOrCommuteConstant(Instruction::Xor, Op0, Op1, Q))
2536 if (isa<PoisonValue>(Op1))
2537 return Op1;
2540 if (Q.isUndefValue(Op1))
2541 return Op1;
2544 if (match(Op1, m_Zero()))
2548 if (Op0 == Op1)
2552 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
2573 if (Value *R = foldAndOrNot(Op0, Op1))
2575 if (Value *R = foldAndOrNot(Op1, Op0))
2578 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Xor))
2583 simplifyAssociativeBinOp(Instruction::Xor, Op0, Op1, Q, MaxRecurse))
2595 if (Value *V = simplifyByDomEq(Instruction::Xor, Op0, Op1, Q, MaxRecurse))
2601 Value *llvm::simplifyXorInst(Value *Op0, Value *Op1, const SimplifyQuery &Q) {
2602 return ::simplifyXorInst(Op0, Op1, Q, RecursionLimit);
5371 static Value *foldIdentityShuffles(int DestElt, Value *Op0, Value *Op1,
5388 SourceOp = Op1;
5416 static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
5448 Op1 = PoisonValue::get(InVecTy);
5452 auto *Op1Const = dyn_cast<Constant>(Op1);
5464 std::swap(Op0, Op1);
5484 assert(isa<UndefValue>(Op1) && "Expected undef operand 1 for splat");
5498 if (Q.isUndefValue(Op1) && RetTy == InVecTy &&
5522 foldIdentityShuffles(i, Op0, Op1, Indices[i], RootVec, MaxRecurse);
5532 Value *llvm::simplifyShuffleVectorInst(Value *Op0, Value *Op1,
5535 return ::simplifyShuffleVectorInst(Op0, Op1, Mask, RetTy, Q, RecursionLimit);
5651 simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5656 if (Constant *C = foldOrCommuteConstant(Instruction::FAdd, Op0, Op1, Q))
5659 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5670 if (match(Op1, m_NegZeroFP()))
5675 if (match(Op1, m_PosZeroFP()) &&
5684 if (match(Op1, m_Inf()))
5685 return Op1;
5694 if (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
5695 match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0))))
5698 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
5699 match(Op1, m_FNeg(m_Specific(Op0))))
5707 (match(Op0, m_FSub(m_Value(X), m_Specific(Op1))) ||
5708 match(Op1, m_FSub(m_Value(X), m_Specific(Op0)))))
5717 simplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5722 if (Constant *C = foldOrCommuteConstant(Instruction::FSub, Op0, Op1, Q))
5725 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5732 if (match(Op1, m_PosZeroFP()))
5737 if (match(Op1, m_NegZeroFP()) &&
5745 if (match(Op0, m_NegZeroFP()) && match(Op1, m_FNeg(m_Value(X))))
5752 (match(Op1, m_FSub(m_AnyZeroFP(), m_Value(X))) ||
5753 match(Op1, m_FNeg(m_Value(X)))))
5761 if (Op0 == Op1)
5769 if (match(Op1, m_Inf()))
5770 return foldConstant(Instruction::FNeg, Op1, Q);
5776 (match(Op1, m_FSub(m_Specific(Op0), m_Value(X))) ||
5777 match(Op0, m_c_FAdd(m_Specific(Op1), m_Value(X)))))
5783 static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
5787 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5795 std::swap(Op0, Op1);
5798 if (match(Op1, m_FPOne()))
5801 if (match(Op1, m_AnyZeroFP())) {
5811 return Op1;
5814 return foldConstant(Instruction::FNeg, Op1, Q);
5823 if (Op0 == Op1 && match(Op0, m_Sqrt(m_Value(X))) && FMF.allowReassoc() &&
5832 simplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5837 if (Constant *C = foldOrCommuteConstant(Instruction::FMul, Op0, Op1, Q))
5841 return simplifyFMAFMul(Op0, Op1, FMF, Q, MaxRecurse, ExBehavior, Rounding);
5844 Value *llvm::simplifyFAddInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5848 return ::simplifyFAddInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5852 Value *llvm::simplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5856 return ::simplifyFSubInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5860 Value *llvm::simplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5864 return ::simplifyFMulInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5868 Value *llvm::simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
5872 return ::simplifyFMAFMul(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5877 simplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5882 if (Constant *C = foldOrCommuteConstant(Instruction::FDiv, Op0, Op1, Q))
5885 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5892 if (match(Op1, m_FPOne()))
5904 if (Op0 == Op1)
5909 if (FMF.allowReassoc() && match(Op0, m_c_FMul(m_Value(X), m_Specific(Op1))))
5915 if (match(Op0, m_FNegNSZ(m_Specific(Op1))) ||
5916 match(Op1, m_FNegNSZ(m_Specific(Op0))))
5920 if (FMF.noInfs() && match(Op1, m_AnyZeroFP()))
5921 return PoisonValue::get(Op1->getType());
5927 Value *llvm::simplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5931 return ::simplifyFDivInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
5936 simplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5941 if (Constant *C = foldOrCommuteConstant(Instruction::FRem, Op0, Op1, Q))
5944 if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
5965 Value *llvm::simplifyFRemInst(Value *Op0, Value *Op1, FastMathFlags FMF,
5969 return ::simplifyFRemInst(Op0, Op1, FMF, Q, RecursionLimit, ExBehavior,
6194 static Value *simplifyLdexp(Value *Op0, Value *Op1, const SimplifyQuery &Q,
6198 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
6209 if (Q.isUndefValue(Op1))
6237 if (match(Op1, PatternMatch::m_ZeroInt()))
6362 static Value *foldMinMaxSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1) {
6372 if (Op1 == X || Op1 == Y ||
6373 match(Op1, m_c_MaxOrMin(m_Specific(X), m_Specific(Y)))) {
6379 return Op1;
6388 Value *Op1) {
6407 if (X0 == Op1 || Y0 == Op1)
6410 auto *M1 = dyn_cast<IntrinsicInst>(Op1);
6430 Value *Op0, Value *Op1,
6458 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
6461 // NOTE: We can't apply this simplifications based on the value of Op1
6466 assert(Op1->getType()->getScalarSizeInBits() ==
6471 if (match(Op1, m_PtrToInt(m_Specific(Op0))))
6477 if (match(Op1, m_AllOnes()) || Q.isUndefValue(Op1))
6481 if (match(Op1, m_ImmConstant(C))) {
6500 if (Op0 == Op1)
6503 // Canonicalize immediate constant operand as Op1.
6505 std::swap(Op0, Op1);
6508 if (Q.isUndefValue(Op1))
6513 if (match(Op1, m_APIntAllowPoison(C))) {
6541 if (Value *V = foldMinMaxSharedOp(IID, Op0, Op1))
6543 if (Value *V = foldMinMaxSharedOp(IID, Op1, Op0))
6548 if (isICmpTrue(Pred, Op0, Op1, Q.getWithoutUndef(), RecursionLimit))
6550 if (isICmpTrue(Pred, Op1, Op0, Q.getWithoutUndef(), RecursionLimit))
6551 return Op1;
6559 if (isICmpTrue(CmpInst::ICMP_EQ, Op0, Op1, Q, RecursionLimit))
6564 if (isICmpTrue(PredGT, Op0, Op1, Q, RecursionLimit))
6569 if (isICmpTrue(PredLT, Op0, Op1, Q, RecursionLimit))
6579 if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6586 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1)) {
6597 if (match(Op0, m_Zero()) || match(Op1, m_Zero()))
6601 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6607 if (match(Op0, m_AllOnes()) || match(Op1, m_AllOnes()))
6615 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6619 if (match(Op1, m_Zero()))
6623 return Op1;
6627 if (match(Op0, m_Zero()) || match(Op1, m_AllOnes()))
6632 if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6635 if (match(Op1, m_Zero()))
6640 if (auto *C1 = dyn_cast<Constant>(Op1))
6644 if (auto *Power = dyn_cast<ConstantInt>(Op1)) {
6654 return simplifyLdexp(Op0, Op1, Q, false);
6657 if (Op0 == Op1)
6661 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
6662 match(Op1, m_FNeg(m_Specific(Op0))))
6663 return Op1;
6669 uint64_t Mask = cast<ConstantInt>(Op1)->getZExtValue();
6684 if (Op0 == Op1)
6687 // Canonicalize constant operand as Op1.
6689 std::swap(Op0, Op1);
6692 if (Q.isUndefValue(Op1))
6702 if (match(Op1, m_NaN()))
6703 return PropagateNaN ? propagateNaN(cast<Constant>(Op1)) : Op0;
6708 if (match(Op1, m_APFloat(C)) &&
6729 if (Value *V = foldMinimumMaximumSharedOp(IID, Op0, Op1))
6731 if (Value *V = foldMinimumMaximumSharedOp(IID, Op1, Op0))
6738 unsigned IdxN = cast<ConstantInt>(Op1)->getZExtValue();
6799 Value *Op0 = Args[0], *Op1 = Args[1], *ShAmtArg = Args[2];
6802 if (Q.isUndefValue(Op0) && Q.isUndefValue(Op1))
6818 if (match(Op0, m_Zero()) && match(Op1, m_Zero()))
6822 if (match(Op0, m_AllOnes()) && match(Op1, m_AllOnes()))
6844 Value *Op1 = Args[1];
6848 // Canonicalize constant operand as Op1 (ConstantFolding handles the case
6849 // when both Op0 and Op1 are constant so we do not care about that special
6852 std::swap(Op0, Op1);
6855 if (match(Op1, m_Zero()))
6859 if (Q.isUndefValue(Op1))
6866 if (ScaledOne.isNonNegative() && match(Op1, m_SpecificInt(ScaledOne)))