Lines Matching defs:Op0

300   BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS);
304 if (Op0 && Op0->getOpcode() == Opcode) {
305 Value *A = Op0->getOperand(0);
306 Value *B = Op0->getOperand(1);
348 if (Op0 && Op0->getOpcode() == Opcode) {
349 Value *A = Op0->getOperand(0);
350 Value *B = Op0->getOperand(1);
608 Value *&Op0, Value *&Op1,
610 if (auto *CLHS = dyn_cast<Constant>(Op0)) {
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))
650 return Op0;
653 if (isKnownNegation(Op0, Op1))
654 return Constant::getNullValue(Op0->getType());
660 if (match(Op1, m_Sub(m_Value(Y), m_Specific(Op0))) ||
661 match(Op0, m_Sub(m_Value(Y), m_Specific(Op1))))
665 Type *Ty = Op0->getType();
666 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
673 match(Op0, m_Xor(m_Value(Y), m_SignMask())))
681 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(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);
762 Type *Ty = Op0->getType();
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))
795 return PoisonValue::get(Op0->getType());
799 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
800 return UndefValue::get(Op0->getType());
804 return Op0;
807 if (Op0 == Op1)
808 return Constant::getNullValue(Op0->getType());
811 if (match(Op0, m_Zero())) {
814 return Constant::getNullValue(Op0->getType());
821 return Constant::getNullValue(Op0->getType());
831 if (MaxRecurse && match(Op0, m_Add(m_Value(X), m_Value(Y)))) { // (X + Y) - Z
852 X = Op0;
874 Z = Op0;
886 if (MaxRecurse && match(Op0, m_Trunc(m_Value(X))) &&
892 if (Value *W = simplifyCastInst(Instruction::Trunc, V, Op0->getType(),
898 if (match(Op0, m_PtrToInt(m_Value(X))) && match(Op1, m_PtrToInt(m_Value(Y))))
900 return ConstantFoldIntegerCast(Result, Op0->getType(), /*IsSigned*/ true,
904 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
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))
942 return Constant::getNullValue(Op0->getType());
946 return Op0;
951 (match(Op0,
953 match(Op1, m_Exact(m_IDiv(m_Value(X), m_Specific(Op0)))))) // Y * (X / Y)
956 if (Op0->getType()->isIntOrIntVectorTy(1)) {
960 return ConstantInt::getNullValue(Op0->getType());
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);
1078 static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
1084 Type *Ty = Op0->getType();
1112 if (isa<PoisonValue>(Op0))
1113 return Op0;
1117 if (Q.isUndefValue(Op0))
1122 if (match(Op0, m_Zero()))
1123 return Constant::getNullValue(Op0->getType());
1127 if (Op0 == Op1)
1145 return IsDiv ? Op0 : Constant::getNullValue(Ty);
1151 if (match(Op0, m_c_Mul(m_Value(X), m_Specific(Op1)))) {
1152 auto *Mul = cast<OverflowingBinaryOperator>(Op0);
1159 return IsDiv ? X : Constant::getNullValue(Op0->getType());
1163 if (isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1164 return IsDiv ? Constant::getNullValue(Op0->getType()) : Op0;
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))
1196 // If this is an exact divide by a constant, then the dividend (Op0) must
1200 KnownBits KnownOp0 = computeKnownBits(Op0, /* Depth */ 0, Q);
1202 return PoisonValue::get(Op0->getType());
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()))))
1234 return Constant::getNullValue(Op0->getType());
1241 ? match(Op0,
1245 : match(Op0,
1249 return Constant::getNullValue(Op0->getType());
1257 static Value *simplifySDivInst(Value *Op0, Value *Op1, bool IsExact,
1260 if (isKnownNegation(Op0, Op1, /*NeedNSW=*/true))
1261 return Constant::getAllOnesValue(Op0->getType());
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,
1288 // srem Op0, (sext i1 X) --> srem Op0, -1 --> 0
1291 return ConstantInt::getNullValue(Op0->getType());
1294 if (isKnownNegation(Op0, Op1))
1295 return ConstantInt::getNullValue(Op0->getType());
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);
1347 static Value *simplifyShift(Instruction::BinaryOps Opcode, Value *Op0,
1350 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1354 if (isa<PoisonValue>(Op0))
1355 return Op0;
1358 if (match(Op0, m_Zero()))
1359 return Constant::getNullValue(Op0->getType());
1367 return Op0;
1371 return PoisonValue::get(Op0->getType());
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))
1389 return PoisonValue::get(Op0->getType());
1395 return Op0;
1400 KnownBits KnownVal = computeKnownBits(Op0, /* Depth */ 0, Q);
1409 return PoisonValue::get(Op0->getType());
1417 static Value *simplifyRightShift(Instruction::BinaryOps Opcode, Value *Op0,
1421 simplifyShift(Opcode, Op0, Op1, /*IsNSW*/ false, Q, MaxRecurse))
1425 if (Op0 == Op1)
1426 return Constant::getNullValue(Op0->getType());
1430 if (Q.isUndefValue(Op0))
1431 return IsExact ? Op0 : Constant::getNullValue(Op0->getType());
1436 KnownBits Op0Known = computeKnownBits(Op0, /* Depth */ 0, Q);
1438 return Op0;
1446 static Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
1449 simplifyShift(Instruction::Shl, Op0, Op1, IsNSW, Q, MaxRecurse))
1452 Type *Ty = Op0->getType();
1455 if (Q.isUndefValue(Op0))
1456 return IsNSW || IsNUW ? Op0 : Constant::getNullValue(Ty);
1461 match(Op0, m_Exact(m_Shr(m_Value(X), m_Specific(Op1)))))
1465 if (IsNUW && match(Op0, m_Negative()))
1466 return Op0;
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))))
1506 match(Op0, m_c_Or(m_NUWShl(m_Value(X), m_APInt(ShLAmt)), m_Value(Y))) &&
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,
1533 if (match(Op0, m_AllOnes()) ||
1534 match(Op0, m_Shl(m_AllOnes(), m_Specific(Op1))))
1535 return Constant::getAllOnesValue(Op0->getType());
1539 if (Q.IIQ.UseInstrInfo && match(Op0, m_NSWShl(m_Value(X), m_Specific(Op1))))
1543 unsigned NumSignBits = ComputeNumSignBits(Op0, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
1544 if (NumSignBits == Op0->getType()->getScalarSizeInBits())
1545 return Op0;
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,
1709 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
1715 auto *AddInst = cast<OverflowingBinaryOperator>(Op0->getOperand(0));
1719 Type *ITy = Op0->getType();
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,
1800 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
1806 auto *AddInst = cast<BinaryOperator>(Op0->getOperand(0));
1810 Type *ITy = Op0->getType();
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))
1901 static Value *simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0,
1904 auto *Cast0 = dyn_cast<CastInst>(Op0);
1908 Op0 = Cast0->getOperand(0);
1913 auto *ICmp0 = dyn_cast<ICmpInst>(Op0);
1919 auto *FCmp0 = dyn_cast<FCmpInst>(Op0);
1944 static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1,
1951 if (!match(Op0, m_ICmp(Pred, m_Value(A), m_Value(B))) ||
1966 return Op0;
1995 static Value *simplifyLogicOfAddSub(Value *Op0, Value *Op1,
1997 assert(Op0->getType() == Op1->getType() && "Mismatched binop types");
2001 if ((match(Op0, m_Add(m_Value(X), m_Constant(C1))) &&
2004 match(Op0, m_Sub(m_Constant(C2), m_Specific(X))))) {
2009 Type *Ty = Op0->getType();
2018 static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
2022 if (match(Op0, m_Not(m_Specific(Op1))))
2023 return Constant::getNullValue(Op0->getType());
2026 if (match(Op0, m_c_Or(m_Specific(Op1), m_Value())))
2031 if (match(Op0, m_c_Or(m_Value(X), m_Not(m_Value(Y)))) &&
2038 if (isCheckForZeroAndMulWithOverflow(Op0, Op1, true))
2042 if (match(Op0, m_Neg(m_Specific(Op1))) &&
2048 if (match(Op0, m_Add(m_Specific(Op1), m_AllOnes())) &&
2055 if (match(Op0, m_Shl(m_Value(X), m_APInt(Shift1))) &&
2060 return Constant::getNullValue(Op0->getType());
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))
2082 return Constant::getNullValue(Op0->getType());
2085 if (Op0 == Op1)
2086 return Op0;
2090 return Constant::getNullValue(Op0->getType());
2094 return Op0;
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))
2111 if (match(Op0, m_Shl(m_Value(X), m_APInt(ShAmt))) &&
2113 return Op0;
2117 if (match(Op0, m_LShr(m_Value(X), m_APInt(ShAmt))) &&
2119 return Op0;
2126 match(Op0, m_Add(m_Value(Shift), m_AllOnes())) &&
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)) {
2154 if (Op0->getType()->isIntOrIntVectorTy(1)) {
2156 if (match(Op1, m_Select(m_Specific(Op0), m_Value(), m_Zero())))
2158 else if (match(Op0, m_Select(m_Specific(Op1), m_Value(), m_Zero())))
2159 return Op0;
2165 threadBinOpOverSelect(Instruction::And, Op0, Op1, Q, MaxRecurse))
2171 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2173 threadBinOpOverPHI(Instruction::And, Op0, Op1, Q, MaxRecurse))
2188 match(Op0, m_c_Or(m_CombineAnd(m_NUWShl(m_Value(X), m_APInt(ShAmt)),
2191 const unsigned Width = Op0->getType()->getScalarSizeInBits();
2212 if (match(Op0, m_c_Xor(m_Value(X),
2216 return Constant::getNullValue(Op0->getType());
2221 if (match(Op0, m_Xor(m_Value(A), m_APInt(C1))) &&
2223 return Constant::getNullValue(Op0->getType());
2225 if (Op0->getType()->isIntOrIntVectorTy(1)) {
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.
2229 return Op0;
2230 // If Op0 is true implies Op1 is false, then they are not true together.
2232 return ConstantInt::getFalse(Op0->getType());
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.
2238 // If Op1 is true implies Op0 is false, then they are not true together.
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))
2359 return Constant::getAllOnesValue(Op0->getType());
2363 if (Op0 == Op1 || match(Op1, m_Zero()))
2364 return Op0;
2366 if (Value *R = simplifyOrLogic(Op0, Op1))
2368 if (Value *R = simplifyOrLogic(Op1, Op0))
2371 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Or))
2379 if ((match(Op0, m_Shl(m_AllOnes(), m_Value(X))) &&
2382 match(Op0, m_LShr(m_AllOnes(), m_Value(Y))))) {
2396 if (match(Op0,
2399 return Op0;
2402 match(Op0, m_Shl(m_Specific(X), m_Specific(Y))))
2407 if (match(Op0,
2410 return Op0;
2413 match(Op0, m_LShr(m_Specific(X), m_Specific(Y))))
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))
2431 if (isCheckForZeroAndMulWithOverflow(Op1, Op0, false))
2432 return Op0;
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)) {
2445 if (Op0->getType()->isIntOrIntVectorTy(1)) {
2447 if (match(Op1, m_Select(m_Specific(Op0), m_One(), m_Value())))
2449 else if (match(Op0, m_Select(m_Specific(Op1), m_One(), m_Value())))
2450 return Op0;
2456 threadBinOpOverSelect(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2463 if (match(Op0, m_And(m_Value(A), m_APInt(C1))) &&
2488 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2489 if (Value *V = threadBinOpOverPHI(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2493 if (match(Op0, m_Xor(m_Value(A), m_APInt(C1))) &&
2495 return Constant::getAllOnesValue(Op0->getType());
2497 if (Op0->getType()->isIntOrIntVectorTy(1)) {
2499 isImpliedCondition(Op0, Op1, Q.DL, false)) {
2500 // If Op0 is false implies Op1 is false, then Op1 is a subset of Op0.
2502 return Op0;
2503 // If Op0 is false implies Op1 is true, then at least one is always true.
2505 return ConstantInt::getTrue(Op0->getType());
2508 isImpliedCondition(Op1, Op0, Q.DL, false)) {
2509 // If Op1 is false implies Op0 is false, then Op0 is a subset of Op1.
2512 // If Op1 is false implies Op0 is true, then at least one is always true.
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))
2545 return Op0;
2548 if (Op0 == Op1)
2549 return Constant::getNullValue(Op0->getType());
2552 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
2553 return Constant::getAllOnesValue(Op0->getType());
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,
5383 int InVecNumElts = cast<FixedVectorType>(Op0->getType())->getNumElements();
5385 Value *SourceOp = Op0;
5416 static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
5423 auto *InVecTy = cast<VectorType>(Op0->getType());
5446 Op0 = PoisonValue::get(InVecTy);
5451 auto *Op0Const = dyn_cast<Constant>(Op0);
5464 std::swap(Op0, Op1);
5477 if (!Scalable && match(Op0, m_InsertElt(m_Value(), m_Constant(C),
5497 if (auto *OpShuf = dyn_cast<ShuffleVectorInst>(Op0))
5500 return Op0;
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))
5664 // not simplify to Op0:
5671 return Op0;
5676 (FMF.noSignedZeros() || cannotBeNegativeZero(Op0, /*Depth=*/0, Q)))
5677 return Op0;
5694 if (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
5695 match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0))))
5696 return ConstantFP::getZero(Op0->getType());
5698 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
5699 match(Op1, m_FNeg(m_Specific(Op0))))
5700 return ConstantFP::getZero(Op0->getType());
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))
5733 return Op0;
5738 (FMF.noSignedZeros() || cannotBeNegativeZero(Op0, /*Depth=*/0, Q)))
5739 return Op0;
5745 if (match(Op0, m_NegZeroFP()) && match(Op1, m_FNeg(m_Value(X))))
5751 if (FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()) &&
5761 if (Op0 == Op1)
5762 return Constant::getNullValue(Op0->getType());
5765 if (match(Op0, m_Inf()))
5766 return Op0;
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))
5794 if (match(Op0, m_FPOne()) || match(Op0, m_AnyZeroFP()))
5795 std::swap(Op0, Op1);
5799 return Op0;
5804 return ConstantFP::getZero(Op0->getType());
5807 computeKnownFPClass(Op0, FMF, fcInf | fcNan, /*Depth=*/0, 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))
5893 return Op0;
5898 if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()))
5899 return ConstantFP::getZero(Op0->getType());
5904 if (Op0 == Op1)
5905 return ConstantFP::get(Op0->getType(), 1.0);
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))))
5917 return ConstantFP::get(Op0->getType(), -1.0);
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))
5955 if (match(Op0, m_PosZeroFP()))
5956 return ConstantFP::getZero(Op0->getType());
5958 if (match(Op0, m_NegZeroFP()))
5959 return ConstantFP::getNegativeZero(Op0->getType());
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))
6199 return Op0;
6202 if (Q.isUndefValue(Op0))
6203 return ConstantFP::getNaN(Op0->getType());
6210 return Op0;
6214 match(Op0, PatternMatch::m_APFloat(C));
6222 return Op0;
6231 return ConstantFP::get(Op0->getType(), C->makeQuiet());
6238 return Op0;
6243 static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
6249 if (auto *II = dyn_cast<IntrinsicInst>(Op0))
6259 auto *II = dyn_cast<IntrinsicInst>(Op0);
6261 match(Op0, m_SIToFP(m_Value())) || match(Op0, m_UIToFP(m_Value())))
6262 return Op0;
6268 if (computeKnownFPSignBit(Op0, /*Depth=*/0, Q) == false)
6269 return Op0;
6273 if (match(Op0, m_BSwap(m_Value(X))))
6278 if (match(Op0, m_BitReverse(m_Value(X))))
6283 if (isKnownToBeAPowerOfTwo(Op0, Q.DL, /*OrZero*/ false, 0, Q.AC, Q.CxtI,
6285 return ConstantInt::get(Op0->getType(), 1);
6288 unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
6289 if (MaskedValueIsZero(Op0, APInt::getHighBitsSet(BitWidth, BitWidth - 1),
6291 return Op0;
6297 match(Op0, m_Intrinsic<Intrinsic::log>(m_Value(X))))
6303 match(Op0, m_Intrinsic<Intrinsic::log2>(m_Value(X))))
6309 match(Op0, m_Intrinsic<Intrinsic::log10>(m_Value(X))))
6315 match(Op0, m_Intrinsic<Intrinsic::exp>(m_Value(X))))
6321 (match(Op0, m_Intrinsic<Intrinsic::exp2>(m_Value(X))) ||
6322 match(Op0,
6330 (match(Op0, m_Intrinsic<Intrinsic::exp10>(m_Value(X))) ||
6331 match(Op0,
6337 if (match(Op0, m_VecReverse(m_Value(X))))
6340 if (isSplatValue(Op0))
6341 return Op0;
6345 if (match(Op0, m_ExtractValue<0>(m_Value(X)))) {
6362 static Value *foldMinMaxSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1) {
6364 if (!match(Op0, m_MaxOrMin(m_Value(X), m_Value(Y))))
6367 auto *MM0 = dyn_cast<IntrinsicInst>(Op0);
6387 static Value *foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0,
6393 auto *M0 = dyn_cast<IntrinsicInst>(Op0);
6394 // If Op0 is not the same intrinsic as IID, do not process.
6430 Value *Op0, Value *Op1,
6439 if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(), m_Value())))
6440 return Op0;
6445 if (match(Op0, m_Shl(m_One(), m_Value(X))))
6451 if (match(Op0, m_LShr(m_Negative(), m_Value(X))))
6453 if (match(Op0, m_AShr(m_Negative(), m_Value())))
6458 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
6459 return PoisonValue::get(Op0->getType());
6463 if (Q.isUndefValue(Op0) || match(Op0, m_Zero()))
6464 return Constant::getNullValue(Op0->getType());
6467 Q.DL.getIndexTypeSizeInBits(Op0->getType()) &&
6471 if (match(Op1, m_PtrToInt(m_Specific(Op0))))
6472 return Op0;
6478 return Op0;
6482 KnownBits PtrKnown = computeKnownBits(Op0, /*Depth=*/0, Q);
6491 return Op0;
6500 if (Op0 == Op1)
6501 return Op0;
6504 if (match(Op0, m_ImmConstant()))
6505 std::swap(Op0, Op1);
6524 return Op0;
6528 auto *MinMax0 = dyn_cast<IntrinsicInst>(Op0);
6537 return Op0;
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))
6549 return Op0;
6550 if (isICmpTrue(Pred, Op1, Op0, Q.getWithoutUndef(), RecursionLimit))
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))
6620 return Op0;
6622 if (match(Op0, m_Zero()))
6627 if (match(Op0, m_Zero()) || match(Op1, m_AllOnes()))
6632 if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6636 return Op0;
6639 if (auto *C0 = dyn_cast<Constant>(Op0))
6647 return ConstantFP::get(Op0->getType(), 1.0);
6650 return Op0;
6654 return simplifyLdexp(Op0, Op1, Q, false);
6657 if (Op0 == Op1)
6658 return Op0;
6661 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
6662 match(Op1, m_FNeg(m_Specific(Op0))))
6666 if (isa<PoisonValue>(Op0))
6675 if (Q.isUndefValue(Op0))
6684 if (Op0 == Op1)
6685 return Op0;
6688 if (isa<Constant>(Op0))
6689 std::swap(Op0, Op1);
6693 return Op0;
6703 return PropagateNaN ? propagateNaN(cast<Constant>(Op1)) : Op0;
6724 return Op0;
6729 if (Value *V = foldMinimumMaximumSharedOp(IID, Op0, Op1))
6731 if (Value *V = foldMinimumMaximumSharedOp(IID, Op1, Op0))
6740 if (match(Op0, m_Intrinsic<Intrinsic::vector_insert>(m_Value(), m_Value(X),
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()))
6843 Value *Op0 = Args[0];
6849 // when both Op0 and Op1 are constant so we do not care about that special
6851 if (isa<Constant>(Op0))
6852 std::swap(Op0, Op1);
6867 return Op0;
7006 static Value *simplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
7008 if (llvm::isGuaranteedNotToBeUndefOrPoison(Op0, Q.AC, Q.CxtI, Q.DT))
7009 return Op0;
7014 Value *llvm::simplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
7015 return ::simplifyFreezeInst(Op0, Q);