Lines Matching refs:LHS
78 /// isSameCompare - Is V equivalent to the comparison "LHS Pred RHS"?
79 static bool isSameCompare(Value *V, CmpInst::Predicate Pred, Value *LHS,
86 if (CPred == Pred && CLHS == LHS && CRHS == RHS)
89 CRHS == LHS;
125 /// given by OpcodeToExpand, while "A" corresponds to LHS and "B op' C" to RHS.
128 static Value *ExpandBinOp(unsigned Opcode, Value *LHS, Value *RHS,
137 if (BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS))
145 // If "L op' R" equals "A op' B" then "L op' R" is just the LHS.
149 return LHS;
163 Value *A = LHS, *B = Op1->getOperand(0), *C = Op1->getOperand(1);
185 /// FactorizeBinOp - Simplify "LHS Opcode RHS" by factorizing out a common term
189 static Value *FactorizeBinOp(unsigned Opcode, Value *LHS, Value *RHS,
197 BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS);
217 // If V equals B then "A op' V" is just the LHS. If V equals DD then
221 return V == B ? LHS : RHS;
240 // If V equals A then "V op' B" is just the LHS. If V equals CC then
244 return V == A ? LHS : RHS;
259 static Value *SimplifyAssociativeBinOp(unsigned Opc, Value *LHS, Value *RHS,
268 BinaryOperator *Op0 = dyn_cast<BinaryOperator>(LHS);
280 // If V equals B then "A op V" is just the LHS.
281 if (V == B) return LHS;
292 Value *A = LHS;
322 // If V equals A then "V op B" is just the LHS.
323 if (V == A) return LHS;
334 Value *A = LHS;
358 static Value *ThreadBinOpOverSelect(unsigned Opcode, Value *LHS, Value *RHS,
365 if (isa<SelectInst>(LHS)) {
366 SI = cast<SelectInst>(LHS);
375 if (SI == LHS) {
379 TV = SimplifyBinOp(Opcode, LHS, SI->getTrueValue(), Q, MaxRecurse);
380 FV = SimplifyBinOp(Opcode, LHS, SI->getFalseValue(), Q, MaxRecurse);
411 Value *UnsimplifiedLHS = SI == LHS ? UnsimplifiedBranch : LHS;
412 Value *UnsimplifiedRHS = SI == LHS ? RHS : UnsimplifiedBranch;
430 static Value *ThreadCmpOverSelect(CmpInst::Predicate Pred, Value *LHS,
437 // Make sure the select is on the LHS.
438 if (!isa<SelectInst>(LHS)) {
439 std::swap(LHS, RHS);
442 assert(isa<SelectInst>(LHS) && "Not comparing with a select instruction!");
443 SelectInst *SI = cast<SelectInst>(LHS);
512 static Value *ThreadBinOpOverPHI(unsigned Opcode, Value *LHS, Value *RHS,
519 if (isa<PHINode>(LHS)) {
520 PI = cast<PHINode>(LHS);
527 // Bail out if LHS and the phi may be mutually interdependent due to a loop.
528 if (!ValueDominatesPHI(LHS, PI, Q.DT))
538 Value *V = PI == LHS ?
540 SimplifyBinOp(Opcode, LHS, Incoming, Q, MaxRecurse);
555 static Value *ThreadCmpOverPHI(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
561 // Make sure the phi is on the LHS.
562 if (!isa<PHINode>(LHS)) {
563 std::swap(LHS, RHS);
566 assert(isa<PHINode>(LHS) && "Not comparing with a phi instruction!");
567 PHINode *PI = cast<PHINode>(LHS);
735 Value *LHS, Value *RHS) {
736 Constant *LHSOffset = stripAndComputeConstantOffsets(TD, LHS);
743 // If LHS and RHS are not related via constant offsets to the same base
745 if (LHS != RHS)
748 // Otherwise, the difference of LHS - RHS can be computed as:
749 // LHS - RHS
1575 /// equivalent to the comparison "LHS Pred RHS". Return such a value if found,
1578 Value *LHS, Value *RHS) {
1586 if (Pred == Cmp->getPredicate() && LHS == CmpLHS && RHS == CmpRHS)
1589 LHS == CmpRHS && RHS == CmpLHS)
1596 Value *LHS, Value *RHS) {
1619 Constant *LHSOffset = stripAndComputeConstantOffsets(TD, LHS);
1626 // If LHS and RHS are not related via constant offsets to the same base
1628 if (LHS != RHS)
1636 static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
1641 if (Constant *CLHS = dyn_cast<Constant>(LHS)) {
1646 std::swap(LHS, RHS);
1650 Type *ITy = GetCompareTy(LHS); // The return type.
1651 Type *OpTy = LHS->getType(); // The operand type.
1656 if (LHS == RHS || isa<UndefValue>(RHS))
1666 return LHS;
1671 return LHS;
1676 return LHS;
1681 return LHS;
1686 return LHS;
1691 return LHS;
1699 // Note that generalizing to the case where LHS is a global variable address
1700 // or null is pointless, since if both LHS and RHS are constants then we
1703 Value *LHSPtr = LHS->stripPointerCasts();
1757 if (isKnownNonZero(LHS, Q.TD))
1762 if (isKnownNonZero(LHS, Q.TD))
1766 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.TD);
1773 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.TD);
1776 if (LHSKnownNonNegative && isKnownNonZero(LHS, Q.TD))
1780 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.TD);
1787 ComputeSignBit(LHS, LHSKnownNonNegative, LHSKnownNegative, Q.TD);
1790 if (LHSKnownNonNegative && isKnownNonZero(LHS, Q.TD))
1811 if (match(LHS, m_URem(m_Value(), m_ConstantInt(CI2)))) {
1814 } else if (match(LHS, m_SRem(m_Value(), m_ConstantInt(CI2)))) {
1818 } else if (match(LHS, m_UDiv(m_ConstantInt(CI2), m_Value()))) {
1821 } else if (match(LHS, m_UDiv(m_Value(), m_ConstantInt(CI2)))) {
1826 } else if (match(LHS, m_SDiv(m_Value(), m_ConstantInt(CI2)))) {
1835 } else if (match(LHS, m_LShr(m_Value(), m_ConstantInt(CI2)))) {
1840 } else if (match(LHS, m_AShr(m_Value(), m_ConstantInt(CI2)))) {
1848 } else if (match(LHS, m_Or(m_Value(), m_ConstantInt(CI2)))) {
1851 } else if (match(LHS, m_And(m_Value(), m_ConstantInt(CI2)))) {
1865 if (isa<CastInst>(LHS) && (isa<Constant>(RHS) || isa<CastInst>(RHS))) {
1866 Instruction *LI = cast<CastInst>(LHS);
1890 if (isa<ZExtInst>(LHS)) {
1916 // Otherwise the upper bits of LHS are zero while RHS has a non-zero bit
1921 // LHS <u RHS.
1932 // LHS is non-negative. If RHS is negative then LHS >s LHS. If RHS
1933 // is non-negative then LHS <s RHS.
1950 if (isa<SExtInst>(LHS)) {
1974 // Otherwise the upper bits of LHS are all equal, while RHS has varying
1984 // If RHS is non-negative then LHS <s RHS. If RHS is negative then
1985 // LHS >s RHS.
1997 // If LHS is non-negative then LHS <u RHS. If LHS is negative then
1998 // LHS >u RHS.
2001 // Comparison is true iff the LHS <s 0.
2010 // Comparison is true iff the LHS >=s 0.
2024 BinaryOperator *LBO = dyn_cast<BinaryOperator>(LHS);
2027 // Analyze the case when either LHS or RHS is an add instruction.
2029 // LHS = A + B (or A and B are null); RHS = C + D (or C and D are null).
2052 if ((C == LHS || D == LHS) && NoRHSWrapProblem)
2054 Constant::getNullValue(LHS->getType()),
2055 C == LHS ? D : C, Q, MaxRecurse-1))
2076 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.TD);
2086 ComputeSignBit(LHS, KnownNonNegative, KnownNegative, Q.TD);
2096 if (RBO && match(RBO, m_URem(m_Value(), m_Specific(LHS)))) {
2171 if (match(LHS, m_SMax(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) {
2177 (A == LHS || B == LHS)) {
2178 if (A != LHS) std::swap(A, B); // A pred smax(A, B).
2182 } else if (match(LHS, m_SMin(m_Value(A), m_Value(B))) &&
2190 (A == LHS || B == LHS)) {
2191 if (A != LHS) std::swap(A, B); // A pred smin(A, B).
2206 if (Value *V = ExtractEquivalentCondition(LHS, EqP, A, B))
2220 if (Value *V = ExtractEquivalentCondition(LHS, InvEqP, A, B))
2241 if (match(LHS, m_UMax(m_Value(A), m_Value(B))) && (A == RHS || B == RHS)) {
2247 (A == LHS || B == LHS)) {
2248 if (A != LHS) std::swap(A, B); // A pred umax(A, B).
2252 } else if (match(LHS, m_UMin(m_Value(A), m_Value(B))) &&
2260 (A == LHS || B == LHS)) {
2261 if (A != LHS) std::swap(A, B); // A pred umin(A, B).
2276 if (Value *V = ExtractEquivalentCondition(LHS, EqP, A, B))
2290 if (Value *V = ExtractEquivalentCondition(LHS, InvEqP, A, B))
2311 if (match(LHS, m_SMax(m_Value(A), m_Value(B))) &&
2321 } else if (match(LHS, m_SMin(m_Value(A), m_Value(B))) &&
2331 } else if (match(LHS, m_UMax(m_Value(A), m_Value(B))) &&
2341 } else if (match(LHS, m_UMin(m_Value(A), m_Value(B))) &&
2355 if (Q.TD && LHS->getType()->isPointerTy() && RHS->getType()->isPointerTy())
2356 if (Constant *C = computePointerICmp(*Q.TD, Pred, LHS, RHS))
2359 if (GetElementPtrInst *GLHS = dyn_cast<GetElementPtrInst>(LHS)) {
2382 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
2383 if (Value *V = ThreadCmpOverSelect(Pred, LHS, RHS, Q, MaxRecurse))
2388 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
2389 if (Value *V = ThreadCmpOverPHI(Pred, LHS, RHS, Q, MaxRecurse))
2395 Value *llvm::SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2399 return ::SimplifyICmpInst(Predicate, LHS, RHS, Query (TD, TLI, DT),
2405 static Value *SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2410 if (Constant *CLHS = dyn_cast<Constant>(LHS)) {
2415 std::swap(LHS, RHS);
2421 return ConstantInt::get(GetCompareTy(LHS), 0);
2423 return ConstantInt::get(GetCompareTy(LHS), 1);
2426 return UndefValue::get(GetCompareTy(LHS));
2429 if (LHS == RHS) {
2431 return ConstantInt::get(GetCompareTy(LHS), 1);
2433 return ConstantInt::get(GetCompareTy(LHS), 0);
2479 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
2480 if (Value *V = ThreadCmpOverSelect(Pred, LHS, RHS, Q, MaxRecurse))
2485 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
2486 if (Value *V = ThreadCmpOverPHI(Pred, LHS, RHS, Q, MaxRecurse))
2492 Value *llvm::SimplifyFCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2496 return ::SimplifyFCmpInst(Predicate, LHS, RHS, Query (TD, TLI, DT),
2671 static Value *SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
2675 return SimplifyAddInst(LHS, RHS, /*isNSW*/false, /*isNUW*/false,
2678 return SimplifySubInst(LHS, RHS, /*isNSW*/false, /*isNUW*/false,
2680 case Instruction::Mul: return SimplifyMulInst (LHS, RHS, Q, MaxRecurse);
2681 case Instruction::SDiv: return SimplifySDivInst(LHS, RHS, Q, MaxRecurse);
2682 case Instruction::UDiv: return SimplifyUDivInst(LHS, RHS, Q, MaxRecurse);
2683 case Instruction::FDiv: return SimplifyFDivInst(LHS, RHS, Q, MaxRecurse);
2684 case Instruction::SRem: return SimplifySRemInst(LHS, RHS, Q, MaxRecurse);
2685 case Instruction::URem: return SimplifyURemInst(LHS, RHS, Q, MaxRecurse);
2686 case Instruction::FRem: return SimplifyFRemInst(LHS, RHS, Q, MaxRecurse);
2688 return SimplifyShlInst(LHS, RHS, /*isNSW*/false, /*isNUW*/false,
2691 return SimplifyLShrInst(LHS, RHS, /*isExact*/false, Q, MaxRecurse);
2693 return SimplifyAShrInst(LHS, RHS, /*isExact*/false, Q, MaxRecurse);
2694 case Instruction::And: return SimplifyAndInst(LHS, RHS, Q, MaxRecurse);
2695 case Instruction::Or: return SimplifyOrInst (LHS, RHS, Q, MaxRecurse);
2696 case Instruction::Xor: return SimplifyXorInst(LHS, RHS, Q, MaxRecurse);
2698 if (Constant *CLHS = dyn_cast<Constant>(LHS))
2701 return ConstantFoldInstOperands(Opcode, LHS->getType(), COps, Q.TD,
2707 if (Value *V = SimplifyAssociativeBinOp(Opcode, LHS, RHS, Q, MaxRecurse))
2712 if (isa<SelectInst>(LHS) || isa<SelectInst>(RHS))
2713 if (Value *V = ThreadBinOpOverSelect(Opcode, LHS, RHS, Q, MaxRecurse))
2718 if (isa<PHINode>(LHS) || isa<PHINode>(RHS))
2719 if (Value *V = ThreadBinOpOverPHI(Opcode, LHS, RHS, Q, MaxRecurse))
2726 Value *llvm::SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS,
2729 return ::SimplifyBinOp(Opcode, LHS, RHS, Query (TD, TLI, DT), RecursionLimit);
2734 static Value *SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2737 return SimplifyICmpInst(Predicate, LHS, RHS, Q, MaxRecurse);
2738 return SimplifyFCmpInst(Predicate, LHS, RHS, Q, MaxRecurse);
2741 Value *llvm::SimplifyCmpInst(unsigned Predicate, Value *LHS, Value *RHS,
2744 return ::SimplifyCmpInst(Predicate, LHS, RHS, Query (TD, TLI, DT),