Lines Matching defs:V

133 /// isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
134 static bool isSameCompare(Value *V, CmpInst::Predicate Pred, Value *LHS,
136 CmpInst *Cmp = dyn_cast<CmpInst>(V);
199 if (Value *V = simplifyAndInst(Cond, TCmp, Q, MaxRecurse))
200 return V;
204 if (Value *V = simplifyOrInst(Cond, FCmp, Q, MaxRecurse))
205 return V;
209 if (Value *V = simplifyXorInst(
211 return V;
216 static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) {
217 Instruction *I = dyn_cast<Instruction>(V);
235 /// Try to simplify a binary operator of form "V op OtherOp" where V is
238 static Value *expandBinOp(Instruction::BinaryOps Opcode, Value *V,
241 auto *B = dyn_cast<BinaryOperator>(V);
281 if (Value *V = expandBinOp(Opcode, L, R, OpcodeToExpand, Q, MaxRecurse))
282 return V;
283 if (Value *V = expandBinOp(Opcode, R, L, OpcodeToExpand, Q, MaxRecurse))
284 return V;
310 if (Value *V = simplifyBinOp(Opcode, B, C, Q, MaxRecurse)) {
311 // It does! Return "A op V" if it simplifies or is already available.
312 // If V equals B then "A op V" is just the LHS.
313 if (V == B)
315 // Otherwise return "A op V" if it simplifies.
316 if (Value *W = simplifyBinOp(Opcode, A, V, Q, MaxRecurse)) {
330 if (Value *V = simplifyBinOp(Opcode, A, B, Q, MaxRecurse)) {
331 // It does! Return "V op C" if it simplifies or is already available.
332 // If V equals B then "V op C" is just the RHS.
333 if (V == B)
335 // Otherwise return "V op C" if it simplifies.
336 if (Value *W = simplifyBinOp(Opcode, V, C, Q, MaxRecurse)) {
354 if (Value *V = simplifyBinOp(Opcode, C, A, Q, MaxRecurse)) {
355 // It does! Return "V op B" if it simplifies or is already available.
356 // If V equals A then "V op B" is just the LHS.
357 if (V == A)
359 // Otherwise return "V op B" if it simplifies.
360 if (Value *W = simplifyBinOp(Opcode, V, B, Q, MaxRecurse)) {
374 if (Value *V = simplifyBinOp(Opcode, C, A, Q, MaxRecurse)) {
375 // It does! Return "B op V" if it simplifies or is already available.
376 // If V equals C then "B op V" is just the RHS.
377 if (V == C)
379 // Otherwise return "B op V" if it simplifies.
380 if (Value *W = simplifyBinOp(Opcode, B, V, Q, MaxRecurse)) {
547 Value *V = PI == LHS
554 if (!V || (CommonValue && V != CommonValue))
556 CommonValue = V;
595 Value *V = simplifyCmpInst(Pred, Incoming, RHS, Q.getWithInstruction(InTI),
599 if (!V || (CommonValue && V != CommonValue))
601 CommonValue = V;
682 if (Value *V = simplifyXorInst(Op0, Op1, Q, MaxRecurse - 1))
683 return V;
686 if (Value *V =
688 return V;
707 /// Compute the base pointer and cumulative constant offsets for V.
709 /// This strips all constant offsets off of V, leaving it the base pointer, and
716 static APInt stripAndComputeConstantOffsets(const DataLayout &DL, Value *&V,
718 assert(V->getType()->isPtrOrPtrVectorTy());
720 APInt Offset = APInt::getZero(DL.getIndexTypeSizeInBits(V->getType()));
721 V = V->stripAndAccumulateConstantOffsets(DL, Offset, AllowNonInbounds);
724 return Offset.sextOrTrunc(DL.getIndexTypeSizeInBits(V->getType()));
832 // See if "V === Y - Z" simplifies.
833 if (Value *V = simplifyBinOp(Instruction::Sub, Y, Z, Q, MaxRecurse - 1))
834 // It does! Now see if "X + V" simplifies.
835 if (Value *W = simplifyBinOp(Instruction::Add, X, V, Q, MaxRecurse - 1)) {
840 // See if "V === X - Z" simplifies.
841 if (Value *V = simplifyBinOp(Instruction::Sub, X, Z, Q, MaxRecurse - 1))
842 // It does! Now see if "Y + V" simplifies.
843 if (Value *W = simplifyBinOp(Instruction::Add, Y, V, Q, MaxRecurse - 1)) {
854 // See if "V === X - Y" simplifies.
855 if (Value *V = simplifyBinOp(Instruction::Sub, X, Y, Q, MaxRecurse - 1))
856 // It does! Now see if "V - Z" simplifies.
857 if (Value *W = simplifyBinOp(Instruction::Sub, V, Z, Q, MaxRecurse - 1)) {
862 // See if "V === X - Z" simplifies.
863 if (Value *V = simplifyBinOp(Instruction::Sub, X, Z, Q, MaxRecurse - 1))
864 // It does! Now see if "V - Y" simplifies.
865 if (Value *W = simplifyBinOp(Instruction::Sub, V, Y, Q, MaxRecurse - 1)) {
876 // See if "V === Z - X" simplifies.
877 if (Value *V = simplifyBinOp(Instruction::Sub, Z, X, Q, MaxRecurse - 1))
878 // It does! Now see if "V + Y" simplifies.
879 if (Value *W = simplifyBinOp(Instruction::Add, V, Y, Q, MaxRecurse - 1)) {
889 // See if "V === X - Y" simplifies.
890 if (Value *V = simplifyBinOp(Instruction::Sub, X, Y, Q, MaxRecurse - 1))
891 // It does! Now see if "trunc V" simplifies.
892 if (Value *W = simplifyCastInst(Instruction::Trunc, V, Op0->getType(),
894 // It does, return the simplified "trunc V".
905 if (Value *V = simplifyXorInst(Op0, Op1, Q, MaxRecurse - 1))
906 return V;
917 if (Value *V = simplifyByDomEq(Instruction::Sub, Op0, Op1, Q, MaxRecurse))
918 return V;
964 if (Value *V = simplifyAndInst(Op0, Op1, Q, MaxRecurse - 1))
965 return V;
969 if (Value *V =
971 return V;
974 if (Value *V = expandCommutativeBinOp(Instruction::Mul, Op0, Op1,
976 return V;
981 if (Value *V =
983 return V;
988 if (Value *V =
990 return V;
1005 Value *V = simplifyICmpInst(Pred, LHS, RHS, Q, MaxRecurse);
1006 Constant *C = dyn_cast_or_null<Constant>(V);
1166 if (Value *V = simplifyByDomEq(Opcode, Op0, Op1, Q, MaxRecurse))
1167 return V;
1172 if (Value *V = threadBinOpOverSelect(Opcode, Op0, Op1, Q, MaxRecurse))
1173 return V;
1178 if (Value *V = threadBinOpOverPHI(Opcode, Op0, Op1, Q, MaxRecurse))
1179 return V;
1191 if (Value *V = simplifyDivRem(Opcode, Op0, Op1, Q, MaxRecurse))
1192 return V;
1225 if (Value *V = simplifyDivRem(Opcode, Op0, Op1, Q, MaxRecurse))
1226 return V;
1376 if (Value *V = threadBinOpOverSelect(Opcode, Op0, Op1, Q, MaxRecurse))
1377 return V;
1382 if (Value *V = threadBinOpOverPHI(Opcode, Op0, Op1, Q, MaxRecurse))
1383 return V;
1420 if (Value *V =
1422 return V;
1448 if (Value *V =
1450 return V;
1489 if (Value *V = simplifyRightShift(Instruction::LShr, Op0, Op1, IsExact, Q,
1491 return V;
1526 if (Value *V = simplifyRightShift(Instruction::AShr, Op0, Op1, IsExact, Q,
1528 return V;
1705 // (icmp (add V, C0), C1) & (icmp V, C0)
1708 Value *V;
1709 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
1712 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
1796 // (icmp (add V, C0), C1) | (icmp V, C0)
1799 Value *V;
1800 if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
1803 if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
1912 Value *V = nullptr;
1916 V = IsAnd ? simplifyAndOfICmps(ICmp0, ICmp1, Q)
1922 V = simplifyAndOrOfFCmps(Q, FCmp0, FCmp1, IsAnd);
1924 if (!V)
1927 return V;
1931 if (auto *C = dyn_cast<Constant>(V))
1938 static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
2062 if (Value *V =
2064 return V;
2101 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::And))
2102 return V;
2135 if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, true))
2136 return V;
2139 if (Value *V =
2141 return V;
2144 if (Value *V = expandCommutativeBinOp(Instruction::And, Op0, Op1,
2146 return V;
2149 if (Value *V = expandCommutativeBinOp(Instruction::And, Op0, Op1,
2151 return V;
2164 if (Value *V =
2166 return V;
2172 if (Value *V =
2174 return V;
2244 if (Value *V = simplifyByDomEq(Instruction::And, Op0, Op1, Q, MaxRecurse))
2245 return V;
2371 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Or))
2372 return V;
2416 if (Value *V =
2418 return V;
2419 if (Value *V =
2421 return V;
2423 if (Value *V = simplifyAndOrOfCmps(Q, Op0, Op1, false))
2424 return V;
2435 if (Value *V =
2437 return V;
2440 if (Value *V = expandCommutativeBinOp(Instruction::Or, Op0, Op1,
2442 return V;
2455 if (Value *V =
2457 return V;
2467 // If we have: ((V + N) & C1) | (V & C2)
2469 // replace with V+N.
2489 if (Value *V = threadBinOpOverPHI(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2490 return V;
2518 if (Value *V = simplifyByDomEq(Instruction::Or, Op0, Op1, Q, MaxRecurse))
2519 return V;
2578 if (Value *V = simplifyLogicOfAddSub(Op0, Op1, Instruction::Xor))
2579 return V;
2582 if (Value *V =
2584 return V;
2595 if (Value *V = simplifyByDomEq(Instruction::Xor, Op0, Op1, Q, MaxRecurse))
2596 return V;
2609 /// Rummage around inside V looking for something equivalent to the comparison
2612 static Value *extractEquivalentCondition(Value *V, CmpInst::Predicate Pred,
2614 SelectInst *SI = dyn_cast<SelectInst>(V);
2631 static bool isAllocDisjoint(const Value *V) {
2637 if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2639 if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
2643 if (const Argument *A = dyn_cast<Argument>(V))
2649 /// [V, object_size(V)] which do not overlap. Note that zero sized regions
2677 auto isByValArg = [](const Value *V) {
2678 const Argument *A = dyn_cast<Argument>(V);
2781 auto *F = [](Value *V) -> Function * {
2782 if (auto *I = dyn_cast<Instruction>(V))
2784 if (auto *A = dyn_cast<Argument>(V))
2881 auto ExtractNotLHS = [](Value *V) -> Value * {
2883 if (match(V, m_Not(m_Value(X))))
3296 if (Value *V = simplifyICmpInst(Pred, A == RHS ? B : A,
3299 return V;
3303 if (Value *V =
3306 return V;
3332 if (Value *V = simplifyICmpInst(Pred, Y, Z, Q, MaxRecurse - 1))
3333 return V;
3338 if (Value *V = simplifyICmpWithBinOpOnLHS(Pred, LBO, RHS, Q, MaxRecurse))
3339 return V;
3342 if (Value *V = simplifyICmpWithBinOpOnLHS(
3344 return V;
3412 if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(1),
3414 return V;
3459 if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(0),
3461 return V;
3467 if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(0),
3469 return V;
3474 if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(0),
3476 return V;
3485 if (Value *V = simplifyICmpInst(Pred, LBO->getOperand(0),
3487 return V;
3545 if (Value *V = extractEquivalentCondition(LHS, EqP, A, B))
3546 return V;
3547 if (Value *V = extractEquivalentCondition(RHS, EqP, A, B))
3548 return V;
3551 if (Value *V = simplifyICmpInst(EqP, A, B, Q, MaxRecurse - 1))
3552 return V;
3559 if (Value *V = extractEquivalentCondition(LHS, InvEqP, A, B))
3560 return V;
3561 if (Value *V = extractEquivalentCondition(RHS, InvEqP, A, B))
3562 return V;
3565 if (Value *V = simplifyICmpInst(InvEqP, A, B, Q, MaxRecurse - 1))
3566 return V;
3619 if (Value *V = extractEquivalentCondition(LHS, EqP, A, B))
3620 return V;
3621 if (Value *V = extractEquivalentCondition(RHS, EqP, A, B))
3622 return V;
3625 if (Value *V = simplifyICmpInst(EqP, A, B, Q, MaxRecurse - 1))
3626 return V;
3633 if (Value *V = extractEquivalentCondition(LHS, InvEqP, A, B))
3634 return V;
3635 if (Value *V = extractEquivalentCondition(RHS, InvEqP, A, B))
3636 return V;
3639 if (Value *V = simplifyICmpInst(InvEqP, A, B, Q, MaxRecurse - 1))
3640 return V;
3736 static std::optional<ConstantRange> getRange(Value *V,
3738 if (Instruction *I = dyn_cast<Instruction>(V))
3742 if (const Argument *A = dyn_cast<Argument>(V))
3744 else if (const CallBase *CB = dyn_cast<CallBase>(V))
3784 if (Value *V = simplifyICmpOfBools(Pred, LHS, RHS, Q))
3785 return V;
3789 if (Value *V = simplifyICmpWithZero(Pred, LHS, RHS, Q))
3790 return V;
3792 if (Value *V = simplifyICmpWithConstant(Pred, LHS, RHS, Q.IIQ))
3793 return V;
3819 if (Value *V = simplifyICmpInst(Pred, SrcOp,
3822 return V;
3826 if (Value *V = simplifyICmpInst(Pred, SrcOp, RI->getOperand(0), Q,
3828 return V;
3838 if (Value *V =
3841 return V;
3874 if (Value *V = simplifyICmpInst(ICmpInst::getUnsignedPredicate(Pred),
3876 return V;
3918 if (Value *V = simplifyICmpInst(Pred, SrcOp, RI->getOperand(0), Q,
3920 return V;
3951 if (Value *V =
3953 return V;
3985 if (Value *V = simplifyICmpInst(ICmpInst::ICMP_SLT, SrcOp,
3988 return V;
3994 if (Value *V = simplifyICmpInst(ICmpInst::ICMP_SGE, SrcOp,
3997 return V;
4013 if (Value *V = simplifyICmpWithBinOp(Pred, LHS, RHS, Q, MaxRecurse))
4014 return V;
4016 if (Value *V = simplifyICmpWithMinMax(Pred, LHS, RHS, Q, MaxRecurse))
4017 return V;
4019 if (Value *V = simplifyICmpWithIntrinsicOnLHS(Pred, LHS, RHS))
4020 return V;
4021 if (Value *V = simplifyICmpWithIntrinsicOnLHS(
4023 return V;
4025 if (Value *V = simplifyICmpWithDominatingAssume(Pred, LHS, RHS, Q))
4026 return V;
4049 if (Value *V = threadCmpOverSelect(Pred, LHS, RHS, Q, MaxRecurse))
4050 return V;
4055 if (Value *V = threadCmpOverPHI(Pred, LHS, RHS, Q, MaxRecurse))
4056 return V;
4284 if (Value *V = threadCmpOverSelect(Pred, LHS, RHS, Q, MaxRecurse))
4285 return V;
4290 if (Value *V = threadCmpOverPHI(Pred, LHS, RHS, Q, MaxRecurse))
4291 return V;
4301 static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
4310 if (V == Op)
4320 auto *I = dyn_cast<Instruction>(V);
4431 auto PreventSelfSimplify = [V](Value *Simplified) {
4432 return Simplified != V ? Simplified : nullptr;
4477 Value *llvm::simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
4484 return ::simplifyWithOpReplaced(V, Op, RepOp, Q.getWithoutUndef(),
4486 return ::simplifyWithOpReplaced(V, Op, RepOp, Q, AllowRefinement, DropFlags,
4648 if (Value *V = simplifyCmpSelOfMaxMin(CmpLHS, CmpRHS, Pred, TrueVal, FalseVal))
4649 return V;
4678 if (Value *V = simplifySelectBitTest(TrueVal, FalseVal, X, Y,
4680 return V;
4717 if (Value *V =
4719 return V;
4725 if (Value *V = simplifySelectWithICmpEq(CmpLHS, CmpRHS, TrueVal, FalseVal,
4727 return V;
4728 if (Value *V = simplifySelectWithICmpEq(CmpRHS, CmpLHS, TrueVal, FalseVal,
4730 return V;
4738 if (Value *V = simplifySelectWithICmpEq(X, CmpRHS, TrueVal, FalseVal, Q,
4740 return V;
4741 if (Value *V = simplifySelectWithICmpEq(Y, CmpRHS, TrueVal, FalseVal, Q,
4743 return V;
4750 if (Value *V = simplifySelectWithICmpEq(X, CmpRHS, TrueVal, FalseVal, Q,
4752 return V;
4753 if (Value *V = simplifySelectWithICmpEq(Y, CmpRHS, TrueVal, FalseVal, Q,
4755 return V;
4955 if (Value *V =
4957 return V;
4959 if (Value *V = simplifySelectWithFCmp(Cond, TrueVal, FalseVal, Q))
4960 return V;
4962 if (Value *V = foldSelectWithBinaryOp(Cond, TrueVal, FalseVal))
4963 return V;
5006 all_of(Indices, [](const auto *V) { return match(V, m_Zero()); }))
5012 any_of(Indices, [](const auto *V) { return isa<PoisonValue>(V); }))
5020 SrcTy->isScalableTy() || any_of(Indices, [](const Value *V) {
5021 return isa<ScalableVectorType>(V->getType());
5042 // getelementptr V, (sub P, V) -> P if P points to a type of size 1.
5049 // getelementptr V, (ashr (sub P, V), C) -> P if P points to a type of
5057 // getelementptr V, (sdiv (sub P, V), C) -> P if P points to a type of
5082 // gep (gep V, C), (sub 0, V) -> C
5089 // gep (gep V, C), (xor V, -1) -> C-1
5101 !all_of(Indices, [](Value *V) { return isa<Constant>(V); }))
5615 if (any_of(Ops, [](Value *V) { return match(V, m_Poison()); }))
5618 for (Value *V : Ops) {
5619 bool IsNan = match(V, m_NaN());
5620 bool IsInf = match(V, m_Inf());
5621 bool IsUndef = Q.isUndefValue(V);
5627 return PoisonValue::get(V->getType());
5629 return PoisonValue::get(V->getType());
5637 return ConstantFP::getNaN(V->getType());
5639 return propagateNaN(cast<Constant>(V));
5642 return propagateNaN(cast<Constant>(V));
6541 if (Value *V = foldMinMaxSharedOp(IID, Op0, Op1))
6542 return V;
6543 if (Value *V = foldMinMaxSharedOp(IID, Op1, Op0))
6544 return V;
6729 if (Value *V = foldMinimumMaximumSharedOp(IID, Op0, Op1))
6730 return V;
6731 if (Value *V = foldMinimumMaximumSharedOp(IID, Op1, Op0))
6732 return V;
6829 if (Value *V = simplifyFPOp(Args, {}, Q, *FPI->getExceptionBehavior(),
6831 return V;
6836 if (Value *V = simplifyFPOp(Args, {}, Q, fp::ebIgnore,
6838 return V;
6984 if (Value *V = tryConstantFoldCall(Call, Callee, Args, Q))
6985 return V;
6998 if (Value *V = tryConstantFoldCall(Call, Call->getCalledOperand(), Args, Q))
6999 return V;
7069 if (llvm::all_of(NewOps, [](Value *V) { return isa<Constant>(V); })) {
7072 [](Value *V) { return cast<Constant>(V); });
7312 bool SimplifyQuery::isUndefValue(Value *V) const {
7316 return match(V, m_Undef());