Lines Matching defs:Op0

255   BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS);
259 if (Op0 && Op0->getOpcode() == Opcode) {
260 Value *A = Op0->getOperand(0);
261 Value *B = Op0->getOperand(1);
303 if (Op0 && Op0->getOpcode() == Opcode) {
304 Value *A = Op0->getOperand(0);
305 Value *B = Op0->getOperand(1);
562 Value *&Op0, Value *&Op1,
564 if (auto *CLHS = dyn_cast<Constant>(Op0)) {
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))
604 return Op0;
607 if (isKnownNegation(Op0, Op1))
608 return Constant::getNullValue(Op0->getType());
614 if (match(Op1, m_Sub(m_Value(Y), m_Specific(Op0))) ||
615 match(Op0, m_Sub(m_Value(Y), m_Specific(Op1))))
619 Type *Ty = Op0->getType();
620 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
627 match(Op0, m_Xor(m_Value(Y), m_SignMask())))
635 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(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);
716 Type *Ty = Op0->getType();
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))
749 return PoisonValue::get(Op0->getType());
753 if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
754 return UndefValue::get(Op0->getType());
758 return Op0;
761 if (Op0 == Op1)
762 return Constant::getNullValue(Op0->getType());
765 if (match(Op0, m_Zero())) {
768 return Constant::getNullValue(Op0->getType());
775 return Constant::getNullValue(Op0->getType());
785 if (MaxRecurse && match(Op0, m_Add(m_Value(X), m_Value(Y)))) { // (X + Y) - Z
806 X = Op0;
828 Z = Op0;
840 if (MaxRecurse && match(Op0, m_Trunc(m_Value(X))) &&
846 if (Value *W = simplifyCastInst(Instruction::Trunc, V, Op0->getType(),
852 if (match(Op0, m_PtrToInt(m_Value(X))) && match(Op1, m_PtrToInt(m_Value(Y))))
854 return ConstantFoldIntegerCast(Result, Op0->getType(), /*IsSigned*/ true,
858 if (MaxRecurse && Op0->getType()->isIntOrIntVectorTy(1))
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))) &&
878 match(Op0, m_LowBitMask()))
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))
904 return Constant::getNullValue(Op0->getType());
908 return Op0;
913 (match(Op0,
915 match(Op1, m_Exact(m_IDiv(m_Value(X), m_Specific(Op0)))))) // Y * (X / Y)
918 if (Op0->getType()->isIntOrIntVectorTy(1)) {
922 return ConstantInt::getNullValue(Op0->getType());
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);
1040 static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
1046 Type *Ty = Op0->getType();
1061 if (isa<PoisonValue>(Op0))
1062 return Op0;
1066 if (Q.isUndefValue(Op0))
1071 if (match(Op0, m_Zero()))
1072 return Constant::getNullValue(Op0->getType());
1076 if (Op0 == Op1)
1094 return IsDiv ? Op0 : Constant::getNullValue(Ty);
1100 if (match(Op0, m_c_Mul(m_Value(X), m_Specific(Op1)))) {
1101 auto *Mul = cast<OverflowingBinaryOperator>(Op0);
1108 return IsDiv ? X : Constant::getNullValue(Op0->getType());
1112 if (isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
1113 return IsDiv ? Constant::getNullValue(Op0->getType()) : Op0;
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))
1145 // If this is an exact divide by a constant, then the dividend (Op0) must
1149 KnownBits KnownOp0 = computeKnownBits(Op0, /* Depth */ 0, Q);
1151 return PoisonValue::get(Op0->getType());
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()))))
1183 return Constant::getNullValue(Op0->getType());
1190 ? match(Op0,
1194 : match(Op0,
1198 return Constant::getNullValue(Op0->getType());
1206 static Value *simplifySDivInst(Value *Op0, Value *Op1, bool IsExact,
1209 if (isKnownNegation(Op0, Op1, /*NeedNSW=*/true))
1210 return Constant::getAllOnesValue(Op0->getType());
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,
1237 // srem Op0, (sext i1 X) --> srem Op0, -1 --> 0
1240 return ConstantInt::getNullValue(Op0->getType());
1243 if (isKnownNegation(Op0, Op1))
1244 return ConstantInt::getNullValue(Op0->getType());
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);
1296 static Value *simplifyShift(Instruction::BinaryOps Opcode, Value *Op0,
1299 if (Constant *C = foldOrCommuteConstant(Opcode, Op0, Op1, Q))
1303 if (isa<PoisonValue>(Op0))
1304 return Op0;
1307 if (match(Op0, m_Zero()))
1308 return Constant::getNullValue(Op0->getType());
1316 return Op0;
1320 return PoisonValue::get(Op0->getType());
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))
1338 return PoisonValue::get(Op0->getType());
1344 return Op0;
1349 KnownBits KnownVal = computeKnownBits(Op0, /* Depth */ 0, Q);
1358 return PoisonValue::get(Op0->getType());
1366 static Value *simplifyRightShift(Instruction::BinaryOps Opcode, Value *Op0,
1370 simplifyShift(Opcode, Op0, Op1, /*IsNSW*/ false, Q, MaxRecurse))
1374 if (Op0 == Op1)
1375 return Constant::getNullValue(Op0->getType());
1379 if (Q.isUndefValue(Op0))
1380 return IsExact ? Op0 : Constant::getNullValue(Op0->getType());
1385 KnownBits Op0Known = computeKnownBits(Op0, /* Depth */ 0, Q);
1387 return Op0;
1395 static Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
1398 simplifyShift(Instruction::Shl, Op0, Op1, IsNSW, Q, MaxRecurse))
1401 Type *Ty = Op0->getType();
1404 if (Q.isUndefValue(Op0))
1405 return IsNSW || IsNUW ? Op0 : Constant::getNullValue(Ty);
1410 match(Op0, m_Exact(m_Shr(m_Value(X), m_Specific(Op1)))))
1414 if (IsNUW && match(Op0, m_Negative()))
1415 return Op0;
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))))
1455 match(Op0, m_c_Or(m_NUWShl(m_Value(X), m_APInt(ShLAmt)), m_Value(Y))) &&
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,
1482 if (match(Op0, m_AllOnes()) ||
1483 match(Op0, m_Shl(m_AllOnes(), m_Specific(Op1))))
1484 return Constant::getAllOnesValue(Op0->getType());
1488 if (Q.IIQ.UseInstrInfo && match(Op0, m_NSWShl(m_Value(X), m_Specific(Op1))))
1492 unsigned NumSignBits = ComputeNumSignBits(Op0, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
1493 if (NumSignBits == Op0->getType()->getScalarSizeInBits())
1494 return Op0;
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,
1658 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
1664 auto *AddInst = cast<OverflowingBinaryOperator>(Op0->getOperand(0));
1668 Type *ITy = Op0->getType();
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,
1749 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
1755 auto *AddInst = cast<BinaryOperator>(Op0->getOperand(0));
1759 Type *ITy = Op0->getType();
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))
1854 static Value *simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0,
1857 auto *Cast0 = dyn_cast<CastInst>(Op0);
1861 Op0 = Cast0->getOperand(0);
1866 auto *ICmp0 = dyn_cast<ICmpInst>(Op0);
1872 auto *FCmp0 = dyn_cast<FCmpInst>(Op0);
1897 static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1,
1904 if (!match(Op0, m_ICmp(Pred, m_Value(A), m_Value(B))) ||
1919 return Op0;
1948 static Value *simplifyLogicOfAddSub(Value *Op0, Value *Op1,
1950 assert(Op0->getType() == Op1->getType() && "Mismatched binop types");
1954 if ((match(Op0, m_Add(m_Value(X), m_Constant(C1))) &&
1957 match(Op0, m_Sub(m_Constant(C2), m_Specific(X))))) {
1962 Type *Ty = Op0->getType();
1971 static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
1975 if (match(Op0, m_Not(m_Specific(Op1))))
1976 return Constant::getNullValue(Op0->getType());
1979 if (match(Op0, m_c_Or(m_Specific(Op1), m_Value())))
1984 if (match(Op0, m_c_Or(m_Value(X), m_Not(m_Value(Y)))) &&
1991 if (isCheckForZeroAndMulWithOverflow(Op0, Op1, true))
1995 if (match(Op0, m_Neg(m_Specific(Op1))) &&
2001 if (match(Op0, m_Add(m_Specific(Op1), m_AllOnes())) &&
2008 if (match(Op0, m_Shl(m_Value(X), m_APInt(Shift1))) &&
2013 return Constant::getNullValue(Op0->getType());
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))
2035 return Constant::getNullValue(Op0->getType());
2038 if (Op0 == Op1)
2039 return Op0;
2043 return Constant::getNullValue(Op0->getType());
2047 return Op0;
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))
2064 if (match(Op0, m_Shl(m_Value(X), m_APInt(ShAmt))) &&
2066 return Op0;
2070 if (match(Op0, m_LShr(m_Value(X), m_APInt(ShAmt))) &&
2072 return Op0;
2079 match(Op0, m_Add(m_Value(Shift), m_AllOnes())) &&
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)) {
2107 if (Op0->getType()->isIntOrIntVectorTy(1)) {
2109 if (match(Op1, m_Select(m_Specific(Op0), m_Value(), m_Zero())))
2111 else if (match(Op0, m_Select(m_Specific(Op1), m_Value(), m_Zero())))
2112 return Op0;
2118 threadBinOpOverSelect(Instruction::And, Op0, Op1, Q, MaxRecurse))
2124 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2126 threadBinOpOverPHI(Instruction::And, Op0, Op1, Q, MaxRecurse))
2141 match(Op0, m_c_Or(m_CombineAnd(m_NUWShl(m_Value(X), m_APInt(ShAmt)),
2144 const unsigned Width = Op0->getType()->getScalarSizeInBits();
2165 if (match(Op0, m_c_Xor(m_Value(X),
2169 return Constant::getNullValue(Op0->getType());
2174 if (match(Op0, m_Xor(m_Value(A), m_APInt(C1))) &&
2176 return Constant::getNullValue(Op0->getType());
2178 if (Op0->getType()->isIntOrIntVectorTy(1)) {
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.
2182 return Op0;
2183 // If Op0 is true implies Op1 is false, then they are not true together.
2185 return ConstantInt::getFalse(Op0->getType());
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.
2191 // If Op1 is true implies Op0 is false, then they are not true together.
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))
2312 return Constant::getAllOnesValue(Op0->getType());
2316 if (Op0 == Op1 || match(Op1, m_Zero()))
2317 return Op0;
2319 if (Value *R = simplifyOrLogic(Op0, Op1))
2321 if (Value *R = simplifyOrLogic(Op1, Op0))
2324 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Or))
2332 if ((match(Op0, m_Shl(m_AllOnes(), m_Value(X))) &&
2335 match(Op0, m_LShr(m_AllOnes(), m_Value(Y))))) {
2349 if (match(Op0,
2352 return Op0;
2355 match(Op0, m_Shl(m_Specific(X), m_Specific(Y))))
2360 if (match(Op0,
2363 return Op0;
2366 match(Op0, m_LShr(m_Specific(X), m_Specific(Y))))
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))
2384 if (isCheckForZeroAndMulWithOverflow(Op1, Op0, false))
2385 return Op0;
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)) {
2398 if (Op0->getType()->isIntOrIntVectorTy(1)) {
2400 if (match(Op1, m_Select(m_Specific(Op0), m_One(), m_Value())))
2402 else if (match(Op0, m_Select(m_Specific(Op1), m_One(), m_Value())))
2403 return Op0;
2409 threadBinOpOverSelect(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2416 if (match(Op0, m_And(m_Value(A), m_APInt(C1))) &&
2441 if (isa<PHINode>(Op0) || isa<PHINode>(Op1))
2442 if (Value *V = threadBinOpOverPHI(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2446 if (match(Op0, m_Xor(m_Value(A), m_APInt(C1))) &&
2448 return Constant::getAllOnesValue(Op0->getType());
2450 if (Op0->getType()->isIntOrIntVectorTy(1)) {
2452 isImpliedCondition(Op0, Op1, Q.DL, false)) {
2453 // If Op0 is false implies Op1 is false, then Op1 is a subset of Op0.
2455 return Op0;
2456 // If Op0 is false implies Op1 is true, then at least one is always true.
2458 return ConstantInt::getTrue(Op0->getType());
2461 isImpliedCondition(Op1, Op0, Q.DL, false)) {
2462 // If Op1 is false implies Op0 is false, then Op0 is a subset of Op1.
2465 // If Op1 is false implies Op0 is true, then at least one is always true.
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))
2498 return Op0;
2501 if (Op0 == Op1)
2502 return Constant::getNullValue(Op0->getType());
2505 if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
2506 return Constant::getAllOnesValue(Op0->getType());
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))) &&
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,
5419 int InVecNumElts = cast<FixedVectorType>(Op0->getType())->getNumElements();
5421 Value *SourceOp = Op0;
5452 static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
5459 auto *InVecTy = cast<VectorType>(Op0->getType());
5482 Op0 = PoisonValue::get(InVecTy);
5487 auto *Op0Const = dyn_cast<Constant>(Op0);
5500 std::swap(Op0, Op1);
5513 if (!Scalable && match(Op0, m_InsertElt(m_Value(), m_Constant(C),
5533 if (auto *OpShuf = dyn_cast<ShuffleVectorInst>(Op0))
5536 return Op0;
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))
5700 // not simplify to Op0:
5707 return Op0;
5712 (FMF.noSignedZeros() || cannotBeNegativeZero(Op0, /*Depth=*/0, Q)))
5713 return Op0;
5730 if (match(Op0, m_FSub(m_AnyZeroFP(), m_Specific(Op1))) ||
5731 match(Op1, m_FSub(m_AnyZeroFP(), m_Specific(Op0))))
5732 return ConstantFP::getZero(Op0->getType());
5734 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
5735 match(Op1, m_FNeg(m_Specific(Op0))))
5736 return ConstantFP::getZero(Op0->getType());
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))
5769 return Op0;
5774 (FMF.noSignedZeros() || cannotBeNegativeZero(Op0, /*Depth=*/0, Q)))
5775 return Op0;
5781 if (match(Op0, m_NegZeroFP()) && match(Op1, m_FNeg(m_Value(X))))
5787 if (FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()) &&
5797 if (Op0 == Op1)
5798 return Constant::getNullValue(Op0->getType());
5801 if (match(Op0, m_Inf()))
5802 return Op0;
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))
5830 if (match(Op0, m_FPOne()) || match(Op0, m_AnyZeroFP()))
5831 std::swap(Op0, Op1);
5835 return Op0;
5840 return ConstantFP::getZero(Op0->getType());
5843 computeKnownFPClass(Op0, FMF, fcInf | fcNan, /*Depth=*/0, 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))
5929 return Op0;
5934 if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()))
5935 return ConstantFP::getZero(Op0->getType());
5940 if (Op0 == Op1)
5941 return ConstantFP::get(Op0->getType(), 1.0);
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))))
5953 return ConstantFP::get(Op0->getType(), -1.0);
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))
5991 if (match(Op0, m_PosZeroFP()))
5992 return ConstantFP::getZero(Op0->getType());
5994 if (match(Op0, m_NegZeroFP()))
5995 return ConstantFP::getNegativeZero(Op0->getType());
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))
6235 return Op0;
6238 if (Q.isUndefValue(Op0))
6239 return ConstantFP::getNaN(Op0->getType());
6246 return Op0;
6250 match(Op0, PatternMatch::m_APFloat(C));
6258 return Op0;
6267 return ConstantFP::get(Op0->getType(), C->makeQuiet());
6274 return Op0;
6279 static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
6285 if (auto *II = dyn_cast<IntrinsicInst>(Op0))
6295 auto *II = dyn_cast<IntrinsicInst>(Op0);
6297 match(Op0, m_SIToFP(m_Value())) || match(Op0, m_UIToFP(m_Value())))
6298 return Op0;
6304 if (computeKnownFPSignBit(Op0, /*Depth=*/0, Q) == false)
6305 return Op0;
6309 if (match(Op0, m_BSwap(m_Value(X))))
6314 if (match(Op0, m_BitReverse(m_Value(X))))
6319 if (isKnownToBeAPowerOfTwo(Op0, Q.DL, /*OrZero*/ false, 0, Q.AC, Q.CxtI,
6321 return ConstantInt::get(Op0->getType(), 1);
6324 unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
6325 if (MaskedValueIsZero(Op0, APInt::getHighBitsSet(BitWidth, BitWidth - 1),
6327 return Op0;
6333 match(Op0, m_Intrinsic<Intrinsic::log>(m_Value(X))))
6339 match(Op0, m_Intrinsic<Intrinsic::log2>(m_Value(X))))
6345 match(Op0, m_Intrinsic<Intrinsic::log10>(m_Value(X))))
6351 match(Op0, m_Intrinsic<Intrinsic::exp>(m_Value(X))))
6357 (match(Op0, m_Intrinsic<Intrinsic::exp2>(m_Value(X))) ||
6358 match(Op0,
6366 (match(Op0, m_Intrinsic<Intrinsic::exp10>(m_Value(X))) ||
6367 match(Op0,
6373 if (match(Op0, m_VecReverse(m_Value(X))))
6376 if (isSplatValue(Op0))
6377 return Op0;
6381 if (match(Op0, m_ExtractValue<0>(m_Value(X)))) {
6398 static Value *foldMinMaxSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1) {
6400 if (!match(Op0, m_MaxOrMin(m_Value(X), m_Value(Y))))
6403 auto *MM0 = dyn_cast<IntrinsicInst>(Op0);
6423 static Value *foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0,
6429 auto *M0 = dyn_cast<IntrinsicInst>(Op0);
6430 // If Op0 is not the same intrinsic as IID, do not process.
6466 Value *Op0, Value *Op1,
6475 if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(), m_Value())))
6476 return Op0;
6481 if (match(Op0, m_Shl(m_One(), m_Value(X))))
6487 if (match(Op0, m_LShr(m_Negative(), m_Value(X))))
6489 if (match(Op0, m_AShr(m_Negative(), m_Value())))
6494 if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
6495 return PoisonValue::get(Op0->getType());
6499 if (Q.isUndefValue(Op0) || match(Op0, m_Zero()))
6500 return Constant::getNullValue(Op0->getType());
6503 Q.DL.getIndexTypeSizeInBits(Op0->getType()) &&
6507 if (match(Op1, m_PtrToInt(m_Specific(Op0))))
6508 return Op0;
6514 return Op0;
6518 KnownBits PtrKnown = computeKnownBits(Op0, /*Depth=*/0, Q);
6527 return Op0;
6536 if (Op0 == Op1)
6537 return Op0;
6540 if (match(Op0, m_ImmConstant()))
6541 std::swap(Op0, Op1);
6560 return Op0;
6564 auto *MinMax0 = dyn_cast<IntrinsicInst>(Op0);
6573 return Op0;
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))
6585 return Op0;
6586 if (isICmpTrue(Pred, Op1, Op0, Q.getWithoutUndef(), RecursionLimit))
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))
6656 return Op0;
6658 if (match(Op0, m_Zero()))
6663 if (match(Op0, m_Zero()) || match(Op1, m_AllOnes()))
6668 if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
6672 return Op0;
6675 if (auto *C0 = dyn_cast<Constant>(Op0))
6683 return ConstantFP::get(Op0->getType(), 1.0);
6686 return Op0;
6690 return simplifyLdexp(Op0, Op1, Q, false);
6693 if (Op0 == Op1)
6694 return Op0;
6697 if (match(Op0, m_FNeg(m_Specific(Op1))) ||
6698 match(Op1, m_FNeg(m_Specific(Op0))))
6702 if (isa<PoisonValue>(Op0))
6711 if (Q.isUndefValue(Op0))
6720 if (Op0 == Op1)
6721 return Op0;
6724 if (isa<Constant>(Op0))
6725 std::swap(Op0, Op1);
6729 return Op0;
6739 return PropagateNaN ? propagateNaN(cast<Constant>(Op1)) : Op0;
6760 return Op0;
6765 if (Value *V = foldMinimumMaximumSharedOp(IID, Op0, Op1))
6767 if (Value *V = foldMinimumMaximumSharedOp(IID, Op1, Op0))
6776 if (match(Op0, m_Intrinsic<Intrinsic::vector_insert>(m_Value(), m_Value(X),
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()))
6879 Value *Op0 = Args[0];
6885 // when both Op0 and Op1 are constant so we do not care about that special
6887 if (isa<Constant>(Op0))
6888 std::swap(Op0, Op1);
6903 return Op0;
7042 static Value *simplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
7044 if (llvm::isGuaranteedNotToBeUndefOrPoison(Op0, Q.AC, Q.CxtI, Q.DT))
7045 return Op0;
7050 Value *llvm::simplifyFreezeInst(Value *Op0, const SimplifyQuery &Q) {
7051 return ::simplifyFreezeInst(Op0, Q);