Lines Matching refs:RHS
21 static KnownBits computeForAddCarry(const KnownBits &LHS, const KnownBits &RHS, in computeForAddCarry() argument
24 APInt PossibleSumZero = LHS.getMaxValue() + RHS.getMaxValue() + !CarryZero; in computeForAddCarry()
25 APInt PossibleSumOne = LHS.getMinValue() + RHS.getMinValue() + CarryOne; in computeForAddCarry()
28 APInt CarryKnownZero = ~(PossibleSumZero ^ LHS.Zero ^ RHS.Zero); in computeForAddCarry()
29 APInt CarryKnownOne = PossibleSumOne ^ LHS.One ^ RHS.One; in computeForAddCarry()
33 APInt RHSKnownUnion = RHS.Zero | RHS.One; in computeForAddCarry()
45 const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry) { in computeForAddCarry() argument
48 LHS, RHS, Carry.Zero.getBoolValue(), Carry.One.getBoolValue()); in computeForAddCarry()
53 const KnownBits &RHS) { in computeForAddSub() argument
58 if (LHS.isUnknown() && RHS.isUnknown()) in computeForAddSub()
61 if (!LHS.isUnknown() && !RHS.isUnknown()) { in computeForAddSub()
64 KnownOut = ::computeForAddCarry(LHS, RHS, /*CarryZero=*/true, in computeForAddSub()
68 KnownBits NotRHS = RHS; in computeForAddSub()
79 APInt MinVal = LHS.getMinValue().uadd_sat(RHS.getMinValue()); in computeForAddSub()
91 APInt MaxVal = LHS.getMaxValue().usub_sat(RHS.getMinValue()); in computeForAddSub()
109 MinVal = LHS.getSignedMinValue().sadd_sat(RHS.getSignedMinValue()); in computeForAddSub()
110 MaxVal = LHS.getSignedMaxValue().sadd_sat(RHS.getSignedMaxValue()); in computeForAddSub()
113 MinVal = LHS.getSignedMinValue().ssub_sat(RHS.getSignedMaxValue()); in computeForAddSub()
114 MaxVal = LHS.getSignedMaxValue().ssub_sat(RHS.getSignedMinValue()); in computeForAddSub()
137 KnownBits KnownBits::computeForSubBorrow(const KnownBits &LHS, KnownBits RHS, in computeForSubBorrow() argument
143 std::swap(RHS.Zero, RHS.One); in computeForSubBorrow()
144 return ::computeForAddCarry(LHS, RHS, in computeForSubBorrow()
178 KnownBits KnownBits::umax(const KnownBits &LHS, const KnownBits &RHS) { in umax() argument
183 if (LHS.getMinValue().uge(RHS.getMaxValue())) in umax()
185 if (RHS.getMinValue().uge(LHS.getMaxValue())) in umax()
186 return RHS; in umax()
191 KnownBits L = LHS.makeGE(RHS.getMinValue()); in umax()
192 KnownBits R = RHS.makeGE(LHS.getMinValue()); in umax()
196 KnownBits KnownBits::umin(const KnownBits &LHS, const KnownBits &RHS) { in umin() argument
199 return Flip(umax(Flip(LHS), Flip(RHS))); in umin()
202 KnownBits KnownBits::smax(const KnownBits &LHS, const KnownBits &RHS) { in smax() argument
212 return Flip(umax(Flip(LHS), Flip(RHS))); in smax()
215 KnownBits KnownBits::smin(const KnownBits &LHS, const KnownBits &RHS) { in smin() argument
225 return Flip(umax(Flip(LHS), Flip(RHS))); in smin()
228 KnownBits KnownBits::abdu(const KnownBits &LHS, const KnownBits &RHS) { in abdu() argument
231 if (LHS.getMinValue().uge(RHS.getMaxValue())) in abdu()
233 RHS); in abdu()
234 if (RHS.getMinValue().uge(LHS.getMaxValue())) in abdu()
235 return computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/false, RHS, in abdu()
241 computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/true, LHS, RHS); in abdu()
243 computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/true, RHS, LHS); in abdu()
247 KnownBits KnownBits::abds(KnownBits LHS, KnownBits RHS) { in abds() argument
250 if (LHS.getSignedMinValue().sge(RHS.getSignedMaxValue())) in abds()
252 RHS); in abds()
253 if (RHS.getSignedMinValue().sge(LHS.getSignedMaxValue())) in abds()
254 return computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/false, RHS, in abds()
264 for (auto Arg : {&LHS, &RHS}) { in abds()
272 computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/true, LHS, RHS); in abds()
274 computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/true, RHS, LHS); in abds()
285 KnownBits KnownBits::shl(const KnownBits &LHS, const KnownBits &RHS, bool NUW, in shl() argument
311 unsigned MinShiftAmount = RHS.getMinValue().getLimitedValue(BitWidth); in shl()
322 APInt MaxValue = RHS.getMaxValue(); in shl()
349 unsigned ShiftAmtZeroMask = RHS.Zero.zextOrTrunc(32).getZExtValue(); in shl()
350 unsigned ShiftAmtOneMask = RHS.One.zextOrTrunc(32).getZExtValue(); in shl()
370 KnownBits KnownBits::lshr(const KnownBits &LHS, const KnownBits &RHS, in lshr() argument
384 unsigned MinShiftAmount = RHS.getMinValue().getLimitedValue(BitWidth); in lshr()
393 APInt MaxValue = RHS.getMaxValue(); in lshr()
407 unsigned ShiftAmtZeroMask = RHS.Zero.zextOrTrunc(32).getZExtValue(); in lshr()
408 unsigned ShiftAmtOneMask = RHS.One.zextOrTrunc(32).getZExtValue(); in lshr()
428 KnownBits KnownBits::ashr(const KnownBits &LHS, const KnownBits &RHS, in ashr() argument
440 unsigned MinShiftAmount = RHS.getMinValue().getLimitedValue(BitWidth); in ashr()
453 APInt MaxValue = RHS.getMaxValue(); in ashr()
467 unsigned ShiftAmtZeroMask = RHS.Zero.zextOrTrunc(32).getZExtValue(); in ashr()
468 unsigned ShiftAmtOneMask = RHS.One.zextOrTrunc(32).getZExtValue(); in ashr()
488 std::optional<bool> KnownBits::eq(const KnownBits &LHS, const KnownBits &RHS) { in eq() argument
489 if (LHS.isConstant() && RHS.isConstant()) in eq()
490 return std::optional<bool>(LHS.getConstant() == RHS.getConstant()); in eq()
491 if (LHS.One.intersects(RHS.Zero) || RHS.One.intersects(LHS.Zero)) in eq()
496 std::optional<bool> KnownBits::ne(const KnownBits &LHS, const KnownBits &RHS) { in ne() argument
497 if (std::optional<bool> KnownEQ = eq(LHS, RHS)) in ne()
502 std::optional<bool> KnownBits::ugt(const KnownBits &LHS, const KnownBits &RHS) { in ugt() argument
504 if (LHS.getMaxValue().ule(RHS.getMinValue())) in ugt()
507 if (LHS.getMinValue().ugt(RHS.getMaxValue())) in ugt()
512 std::optional<bool> KnownBits::uge(const KnownBits &LHS, const KnownBits &RHS) { in uge() argument
513 if (std::optional<bool> IsUGT = ugt(RHS, LHS)) in uge()
518 std::optional<bool> KnownBits::ult(const KnownBits &LHS, const KnownBits &RHS) { in ult() argument
519 return ugt(RHS, LHS); in ult()
522 std::optional<bool> KnownBits::ule(const KnownBits &LHS, const KnownBits &RHS) { in ule() argument
523 return uge(RHS, LHS); in ule()
526 std::optional<bool> KnownBits::sgt(const KnownBits &LHS, const KnownBits &RHS) { in sgt() argument
528 if (LHS.getSignedMaxValue().sle(RHS.getSignedMinValue())) in sgt()
531 if (LHS.getSignedMinValue().sgt(RHS.getSignedMaxValue())) in sgt()
536 std::optional<bool> KnownBits::sge(const KnownBits &LHS, const KnownBits &RHS) { in sge() argument
537 if (std::optional<bool> KnownSGT = sgt(RHS, LHS)) in sge()
542 std::optional<bool> KnownBits::slt(const KnownBits &LHS, const KnownBits &RHS) { in slt() argument
543 return sgt(RHS, LHS); in slt()
546 std::optional<bool> KnownBits::sle(const KnownBits &LHS, const KnownBits &RHS) { in sle() argument
547 return sge(RHS, LHS); in sle()
610 const KnownBits &RHS) { in computeForSatAddSub() argument
614 KnownBits::computeForAddSub(Add, /*NSW=*/false, /*NUW=*/false, LHS, RHS); in computeForSatAddSub()
624 if (SignBitKnown(LHS) && SignBitKnown(RHS) && SignBitKnown(Res)) { in computeForSatAddSub()
627 Overflow = (LHS.isNonNegative() == RHS.isNonNegative() && in computeForSatAddSub()
631 Overflow = (LHS.isNonNegative() != RHS.isNonNegative() && in computeForSatAddSub()
638 (void)LHS.getMaxValue().uadd_ov(RHS.getMaxValue(), Of); in computeForSatAddSub()
642 (void)LHS.getMinValue().uadd_ov(RHS.getMinValue(), Of); in computeForSatAddSub()
649 (void)LHS.getMinValue().usub_ov(RHS.getMaxValue(), Of); in computeForSatAddSub()
653 (void)LHS.getMaxValue().usub_ov(RHS.getMinValue(), Of); in computeForSatAddSub()
661 if (LHS.isNonNegative() && RHS.isNonNegative()) { in computeForSatAddSub()
666 if (LHS.isNegative() && RHS.isNegative()) { in computeForSatAddSub()
672 if (LHS.isNegative() && RHS.isNonNegative()) { in computeForSatAddSub()
676 } else if (LHS.isNonNegative() && RHS.isNegative()) { in computeForSatAddSub()
689 std::max(LHS.countMinLeadingOnes(), RHS.countMinLeadingOnes()); in computeForSatAddSub()
692 std::max(LHS.countMinLeadingZeros(), RHS.countMinLeadingOnes()); in computeForSatAddSub()
753 KnownBits KnownBits::sadd_sat(const KnownBits &LHS, const KnownBits &RHS) { in sadd_sat() argument
754 return computeForSatAddSub(/*Add*/ true, /*Signed*/ true, LHS, RHS); in sadd_sat()
756 KnownBits KnownBits::ssub_sat(const KnownBits &LHS, const KnownBits &RHS) { in ssub_sat() argument
757 return computeForSatAddSub(/*Add*/ false, /*Signed*/ true, LHS, RHS); in ssub_sat()
759 KnownBits KnownBits::uadd_sat(const KnownBits &LHS, const KnownBits &RHS) { in uadd_sat() argument
760 return computeForSatAddSub(/*Add*/ true, /*Signed*/ false, LHS, RHS); in uadd_sat()
762 KnownBits KnownBits::usub_sat(const KnownBits &LHS, const KnownBits &RHS) { in usub_sat() argument
763 return computeForSatAddSub(/*Add*/ false, /*Signed*/ false, LHS, RHS); in usub_sat()
766 static KnownBits avgCompute(KnownBits LHS, KnownBits RHS, bool IsCeil, in avgCompute() argument
770 RHS = IsSigned ? RHS.sext(BitWidth + 1) : RHS.zext(BitWidth + 1); in avgCompute()
772 computeForAddCarry(LHS, RHS, /*CarryZero*/ !IsCeil, /*CarryOne*/ IsCeil); in avgCompute()
777 KnownBits KnownBits::avgFloorS(const KnownBits &LHS, const KnownBits &RHS) { in avgFloorS() argument
778 return avgCompute(LHS, RHS, /* IsCeil */ false, in avgFloorS()
782 KnownBits KnownBits::avgFloorU(const KnownBits &LHS, const KnownBits &RHS) { in avgFloorU() argument
783 return avgCompute(LHS, RHS, /* IsCeil */ false, in avgFloorU()
787 KnownBits KnownBits::avgCeilS(const KnownBits &LHS, const KnownBits &RHS) { in avgCeilS() argument
788 return avgCompute(LHS, RHS, /* IsCeil */ true, in avgCeilS()
792 KnownBits KnownBits::avgCeilU(const KnownBits &LHS, const KnownBits &RHS) { in avgCeilU() argument
793 return avgCompute(LHS, RHS, /* IsCeil */ true, in avgCeilU()
797 KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS, in mul() argument
800 assert(BitWidth == RHS.getBitWidth() && "Operand mismatch"); in mul()
801 assert((!NoUndefSelfMultiply || LHS == RHS) && in mul()
810 APInt UMaxRHS = RHS.getMaxValue(); in mul()
861 const APInt &Bottom1 = RHS.One; in mul()
866 unsigned TrailBitsKnown1 = (RHS.Zero | RHS.One).countr_one(); in mul()
868 unsigned TrailZero1 = RHS.countMinTrailingZeros(); in mul()
894 KnownBits KnownBits::mulhs(const KnownBits &LHS, const KnownBits &RHS) { in mulhs() argument
896 assert(BitWidth == RHS.getBitWidth() && "Operand mismatch"); in mulhs()
898 KnownBits WideRHS = RHS.sext(2 * BitWidth); in mulhs()
902 KnownBits KnownBits::mulhu(const KnownBits &LHS, const KnownBits &RHS) { in mulhu() argument
904 assert(BitWidth == RHS.getBitWidth() && "Operand mismatch"); in mulhu()
906 KnownBits WideRHS = RHS.zext(2 * BitWidth); in mulhu()
911 const KnownBits &RHS, bool Exact) { in divComputeLowBit() argument
923 (int)LHS.countMinTrailingZeros() - (int)RHS.countMaxTrailingZeros(); in divComputeLowBit()
925 (int)LHS.countMaxTrailingZeros() - (int)RHS.countMinTrailingZeros(); in divComputeLowBit()
946 KnownBits KnownBits::sdiv(const KnownBits &LHS, const KnownBits &RHS, in sdiv() argument
949 if (LHS.isNonNegative() && RHS.isNonNegative()) in sdiv()
950 return udiv(LHS, RHS, Exact); in sdiv()
955 if (LHS.isZero() || RHS.isZero()) { in sdiv()
963 if (LHS.isNegative() && RHS.isNegative()) { in sdiv()
965 APInt Denom = RHS.getSignedMaxValue(); in sdiv()
972 } else if (LHS.isNegative() && RHS.isNonNegative()) { in sdiv()
974 if (Exact || (-LHS.getSignedMaxValue()).uge(RHS.getSignedMaxValue())) { in sdiv()
975 APInt Denom = RHS.getSignedMinValue(); in sdiv()
979 } else if (LHS.isStrictlyPositive() && RHS.isNegative()) { in sdiv()
981 if (Exact || LHS.getSignedMinValue().uge(-RHS.getSignedMinValue())) { in sdiv()
982 APInt Denom = RHS.getSignedMaxValue(); in sdiv()
998 Known = divComputeLowBit(Known, LHS, RHS, Exact); in sdiv()
1002 KnownBits KnownBits::udiv(const KnownBits &LHS, const KnownBits &RHS, in udiv() argument
1007 if (LHS.isZero() || RHS.isZero()) { in udiv()
1017 APInt MinDenom = RHS.getMinValue(); in udiv()
1024 Known = divComputeLowBit(Known, LHS, RHS, Exact); in udiv()
1029 KnownBits KnownBits::remGetLowBits(const KnownBits &LHS, const KnownBits &RHS) { in remGetLowBits() argument
1031 if (!RHS.isZero() && RHS.Zero[0]) { in remGetLowBits()
1033 unsigned RHSZeros = RHS.countMinTrailingZeros(); in remGetLowBits()
1042 KnownBits KnownBits::urem(const KnownBits &LHS, const KnownBits &RHS) { in urem() argument
1043 KnownBits Known = remGetLowBits(LHS, RHS); in urem()
1044 if (RHS.isConstant() && RHS.getConstant().isPowerOf2()) { in urem()
1046 APInt HighBits = ~(RHS.getConstant() - 1); in urem()
1054 std::max(LHS.countMinLeadingZeros(), RHS.countMinLeadingZeros()); in urem()
1059 KnownBits KnownBits::srem(const KnownBits &LHS, const KnownBits &RHS) { in srem() argument
1060 KnownBits Known = remGetLowBits(LHS, RHS); in srem()
1061 if (RHS.isConstant() && RHS.getConstant().isPowerOf2()) { in srem()
1063 APInt LowBits = RHS.getConstant() - 1; in srem()
1084 KnownBits &KnownBits::operator&=(const KnownBits &RHS) { in operator &=() argument
1086 Zero |= RHS.Zero; in operator &=()
1088 One &= RHS.One; in operator &=()
1092 KnownBits &KnownBits::operator|=(const KnownBits &RHS) { in operator |=() argument
1094 Zero &= RHS.Zero; in operator |=()
1096 One |= RHS.One; in operator |=()
1100 KnownBits &KnownBits::operator^=(const KnownBits &RHS) { in operator ^=() argument
1102 APInt Z = (Zero & RHS.Zero) | (One & RHS.One); in operator ^=()
1104 One = (Zero & RHS.One) | (One & RHS.Zero); in operator ^=()