Lines Matching +full:lower +full:- +full:case

1 //===- ConstantRange.cpp - ConstantRange implementation -------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // for an integral value. This keeps track of a lower and upper bound for the
12 // keeps track of a [lower, upper) bound, which specifies an interval just like
21 //===----------------------------------------------------------------------===//
24 #include "llvm/Config/llvm-config.h"
45 : Lower(Full ? APInt::getMaxValue(BitWidth) : APInt::getMinValue(BitWidth)), in ConstantRange()
46 Upper(Lower) {} in ConstantRange()
49 : Lower(std::move(V)), Upper(Lower + 1) {} in ConstantRange()
52 : Lower(std::move(L)), Upper(std::move(U)) { in ConstantRange()
53 assert(Lower.getBitWidth() == Upper.getBitWidth() && in ConstantRange()
55 assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) && in ConstantRange()
56 "Lower == Upper, but they aren't min or max value!"); in ConstantRange()
71 // If we don't know the sign bit, pick the lower bound as a negative number in fromKnownBits()
72 // and the upper bound as a non-negative one. in fromKnownBits()
73 APInt Lower = Known.getMinValue(), Upper = Known.getMaxValue(); in fromKnownBits() local
74 Lower.setSignBit(); in fromKnownBits()
76 return ConstantRange(Lower, Upper + 1); in fromKnownBits()
106 case CmpInst::ICMP_EQ: in makeAllowedICmpRegion()
108 case CmpInst::ICMP_NE: in makeAllowedICmpRegion()
112 case CmpInst::ICMP_ULT: { in makeAllowedICmpRegion()
118 case CmpInst::ICMP_SLT: { in makeAllowedICmpRegion()
124 case CmpInst::ICMP_ULE: in makeAllowedICmpRegion()
126 case CmpInst::ICMP_SLE: in makeAllowedICmpRegion()
128 case CmpInst::ICMP_UGT: { in makeAllowedICmpRegion()
134 case CmpInst::ICMP_SGT: { in makeAllowedICmpRegion()
140 case CmpInst::ICMP_UGE: in makeAllowedICmpRegion()
142 case CmpInst::ICMP_SGE: in makeAllowedICmpRegion()
149 // Follows from De-Morgan's laws: in makeSatisfyingICmpRegion()
162 // However for non-singleton RHS, for example ult [2,5) makeAllowedICmpRegion in makeExactICmpRegion()
227 RHS = getUpper() - getLower(); in getEquivalentICmp()
228 Offset = -getLower(); in getEquivalentICmp()
248 case CmpInst::ICMP_EQ: in icmp()
253 case CmpInst::ICMP_NE: in icmp()
255 case CmpInst::ICMP_ULT: in icmp()
257 case CmpInst::ICMP_ULE: in icmp()
259 case CmpInst::ICMP_UGT: in icmp()
261 case CmpInst::ICMP_UGE: in icmp()
263 case CmpInst::ICMP_SLT: in icmp()
265 case CmpInst::ICMP_SLE: in icmp()
267 case CmpInst::ICMP_SGT: in icmp()
269 case CmpInst::ICMP_SGE: in icmp()
291 // Handle 0 and -1 separately to avoid division by zero or overflow. in makeExactMulNSWRegion()
298 // e.g. Returning [-127, 127], represented as [-127, -128). in makeExactMulNSWRegion()
300 return ConstantRange(-MaxValue, MinValue); in makeExactMulNSWRegion()
302 APInt Lower, Upper; in makeExactMulNSWRegion() local
304 Lower = APIntOps::RoundingSDiv(MaxValue, V, APInt::Rounding::UP); in makeExactMulNSWRegion()
307 Lower = APIntOps::RoundingSDiv(MinValue, V, APInt::Rounding::UP); in makeExactMulNSWRegion()
310 return ConstantRange::getNonEmpty(Lower, Upper + 1); in makeExactMulNSWRegion()
332 case Instruction::Add: { in makeGuaranteedNoWrapRegion()
334 return getNonEmpty(APInt::getZero(BitWidth), -Other.getUnsignedMax()); in makeGuaranteedNoWrapRegion()
339 SMin.isNegative() ? SignedMinVal - SMin : SignedMinVal, in makeGuaranteedNoWrapRegion()
340 SMax.isStrictlyPositive() ? SignedMinVal - SMax : SignedMinVal); in makeGuaranteedNoWrapRegion()
343 case Instruction::Sub: { in makeGuaranteedNoWrapRegion()
354 case Instruction::Mul: in makeGuaranteedNoWrapRegion()
358 // Avoid one makeExactMulNSWRegion() call for the common case of constants. in makeGuaranteedNoWrapRegion()
365 case Instruction::Shl: { in makeGuaranteedNoWrapRegion()
369 ConstantRange(APInt(BitWidth, 0), APInt(BitWidth, (BitWidth - 1) + 1))); in makeGuaranteedNoWrapRegion()
371 // If the entire range of shift amounts is already poison-producing, in makeGuaranteedNoWrapRegion()
372 // then we can freely add more poison-producing flags ontop of that. in makeGuaranteedNoWrapRegion()
375 // There are some legal shift amounts, we can compute conservatively-correct in makeGuaranteedNoWrapRegion()
376 // range of no-wrap inputs. Note that by now we have clamped the ShAmtUMax in makeGuaranteedNoWrapRegion()
377 // to be at most bitwidth-1, which results in most conservative range. in makeGuaranteedNoWrapRegion()
391 // makeGuaranteedNoWrapRegion() is exact for single-element ranges, as in makeExactNoWrapRegion()
392 // "for all" and "for any" coincide in this case. in makeExactNoWrapRegion()
406 // If (Val & Mask) != C, constrained to the non-equality being in makeMaskNotEqualRange()
414 return Lower == Upper && Lower.isMaxValue(); in isFullSet()
418 return Lower == Upper && Lower.isMinValue(); in isEmptySet()
422 return Lower.ugt(Upper) && !Upper.isZero(); in isWrappedSet()
426 return Lower.ugt(Upper); in isUpperWrapped()
430 return Lower.sgt(Upper) && !Upper.isMinSignedValue(); in isSignWrappedSet()
434 return Lower.sgt(Upper); in isUpperSignWrapped()
444 return (Upper - Lower).ult(Other.Upper - Other.Lower); in isSizeStrictlySmallerThan()
452 return MaxSize == 0 || APInt::getMaxValue(getBitWidth()).ugt(MaxSize - 1); in isSizeLargerThan()
454 return (Upper - Lower).ugt(MaxSize); in isSizeLargerThan()
469 return !isSignWrappedSet() && Lower.isNonNegative(); in isAllNonNegative()
479 return !isSignWrappedSet() && Lower.isStrictlyPositive(); in isAllPositive()
485 return getUpper() - 1; in getUnsignedMax()
497 return getUpper() - 1; in getSignedMax()
507 if (Lower == Upper) in contains()
511 return Lower.ule(V) && V.ult(Upper); in contains()
512 return Lower.ule(V) || V.ult(Upper); in contains()
523 return Lower.ule(Other.getLower()) && Other.getUpper().ule(Upper); in contains()
528 Lower.ule(Other.getLower()); in contains()
530 return Other.getUpper().ule(Upper) && Lower.ule(Other.getLower()); in contains()
551 if (Lower == Upper) in subtract()
553 return ConstantRange(Lower - Val, Upper - Val); in subtract()
593 if (Lower.ult(CR.Lower)) { in intersectWith()
594 // L---U : this in intersectWith()
595 // L---U : CR in intersectWith()
596 if (Upper.ule(CR.Lower)) in intersectWith()
599 // L---U : this in intersectWith()
600 // L---U : CR in intersectWith()
602 return ConstantRange(CR.Lower, Upper); in intersectWith()
604 // L-------U : this in intersectWith()
605 // L---U : CR in intersectWith()
608 // L---U : this in intersectWith()
609 // L-------U : CR in intersectWith()
613 // L-----U : this in intersectWith()
614 // L-----U : CR in intersectWith()
615 if (Lower.ult(CR.Upper)) in intersectWith()
616 return ConstantRange(Lower, CR.Upper); in intersectWith()
618 // L---U : this in intersectWith()
619 // L---U : CR in intersectWith()
624 if (CR.Lower.ult(Upper)) { in intersectWith()
625 // ------U L--- : this in intersectWith()
626 // L--U : CR in intersectWith()
630 // ------U L--- : this in intersectWith()
631 // L------U : CR in intersectWith()
632 if (CR.Upper.ule(Lower)) in intersectWith()
633 return ConstantRange(CR.Lower, Upper); in intersectWith()
635 // ------U L--- : this in intersectWith()
636 // L----------U : CR in intersectWith()
639 if (CR.Lower.ult(Lower)) { in intersectWith()
640 // --U L---- : this in intersectWith()
641 // L--U : CR in intersectWith()
642 if (CR.Upper.ule(Lower)) in intersectWith()
645 // --U L---- : this in intersectWith()
646 // L------U : CR in intersectWith()
647 return ConstantRange(Lower, CR.Upper); in intersectWith()
650 // --U L------ : this in intersectWith()
651 // L--U : CR in intersectWith()
656 // ------U L-- : this in intersectWith()
657 // --U L------ : CR in intersectWith()
658 if (CR.Lower.ult(Upper)) in intersectWith()
661 // ----U L-- : this in intersectWith()
662 // --U L---- : CR in intersectWith()
663 if (CR.Lower.ult(Lower)) in intersectWith()
664 return ConstantRange(Lower, CR.Upper); in intersectWith()
666 // ----U L---- : this in intersectWith()
667 // --U L-- : CR in intersectWith()
670 if (CR.Upper.ule(Lower)) { in intersectWith()
671 // --U L-- : this in intersectWith()
672 // ----U L---- : CR in intersectWith()
673 if (CR.Lower.ult(Lower)) in intersectWith()
676 // --U L---- : this in intersectWith()
677 // ----U L-- : CR in intersectWith()
678 return ConstantRange(CR.Lower, Upper); in intersectWith()
681 // --U L------ : this in intersectWith()
682 // ------U L-- : CR in intersectWith()
698 // L---U and L---U : this in unionWith()
699 // L---U L---U : CR in unionWith()
701 // L---------U in unionWith()
702 // -----U L----- in unionWith()
703 if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower)) in unionWith()
705 ConstantRange(Lower, CR.Upper), ConstantRange(CR.Lower, Upper), Type); in unionWith()
707 APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower; in unionWith()
708 APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper; in unionWith()
717 // ------U L----- and ------U L----- : this in unionWith()
718 // L--U L--U : CR in unionWith()
719 if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower)) in unionWith()
722 // ------U L----- : this in unionWith()
723 // L---------U : CR in unionWith()
724 if (CR.Lower.ule(Upper) && Lower.ule(CR.Upper)) in unionWith()
727 // ----U L---- : this in unionWith()
728 // L---U : CR in unionWith()
730 // ----------U L---- in unionWith()
731 // ----U L---------- in unionWith()
732 if (Upper.ult(CR.Lower) && CR.Upper.ult(Lower)) in unionWith()
734 ConstantRange(Lower, CR.Upper), ConstantRange(CR.Lower, Upper), Type); in unionWith()
736 // ----U L----- : this in unionWith()
737 // L----U : CR in unionWith()
738 if (Upper.ult(CR.Lower) && Lower.ule(CR.Upper)) in unionWith()
739 return ConstantRange(CR.Lower, Upper); in unionWith()
741 // ------U L---- : this in unionWith()
742 // L-----U : CR in unionWith()
743 assert(CR.Lower.ule(Upper) && CR.Upper.ult(Lower) && in unionWith()
744 "ConstantRange::unionWith missed a case with one range wrapped"); in unionWith()
745 return ConstantRange(Lower, CR.Upper); in unionWith()
748 // ------U L---- and ------U L---- : this in unionWith()
749 // -U L----------- and ------------U L : CR in unionWith()
750 if (CR.Lower.ule(Upper) || Lower.ule(CR.Upper)) in unionWith()
753 APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower; in unionWith()
782 case Instruction::Trunc: in castOp()
784 case Instruction::SExt: in castOp()
786 case Instruction::ZExt: in castOp()
788 case Instruction::BitCast: in castOp()
790 case Instruction::FPToUI: in castOp()
791 case Instruction::FPToSI: in castOp()
796 case Instruction::UIToFP: { in castOp()
807 case Instruction::SIToFP: { in castOp()
818 case Instruction::FPTrunc: in castOp()
819 case Instruction::FPExt: in castOp()
820 case Instruction::IntToPtr: in castOp()
821 case Instruction::PtrToInt: in castOp()
822 case Instruction::AddrSpaceCast: in castOp()
836 if (!Upper) // special case: [X, 0) -- not really wrapping around in zeroExtend()
837 LowerExt = Lower.zext(DstTySize); in zeroExtend()
842 return ConstantRange(Lower.zext(DstTySize), Upper.zext(DstTySize)); in zeroExtend()
851 // special case: [X, INT_MIN) -- not really wrapping around in signExtend()
853 return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize)); in signExtend()
856 return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1), in signExtend()
857 APInt::getLowBitsSet(DstTySize, SrcTySize-1) + 1); in signExtend()
860 return ConstantRange(Lower.sext(DstTySize), Upper.sext(DstTySize)); in signExtend()
870 APInt LowerDiv(Lower), UpperDiv(Upper); in truncate()
873 // Analyze wrapped sets in their two parts: [0, Upper) \/ [Lower, MaxValue] in truncate()
874 // We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and in truncate()
885 // Union covers the MaxValue case, so return if the remaining range is just in truncate()
895 LowerDiv -= Adjust; in truncate()
896 UpperDiv -= Adjust; in truncate()
939 case Instruction::Add: in binaryOp()
941 case Instruction::Sub: in binaryOp()
943 case Instruction::Mul: in binaryOp()
945 case Instruction::UDiv: in binaryOp()
947 case Instruction::SDiv: in binaryOp()
949 case Instruction::URem: in binaryOp()
951 case Instruction::SRem: in binaryOp()
953 case Instruction::Shl: in binaryOp()
955 case Instruction::LShr: in binaryOp()
957 case Instruction::AShr: in binaryOp()
959 case Instruction::And: in binaryOp()
961 case Instruction::Or: in binaryOp()
963 case Instruction::Xor: in binaryOp()
967 case Instruction::FAdd: in binaryOp()
969 case Instruction::FSub: in binaryOp()
971 case Instruction::FMul: in binaryOp()
985 case Instruction::Add: in overflowingBinaryOp()
987 case Instruction::Sub: in overflowingBinaryOp()
989 case Instruction::Mul: in overflowingBinaryOp()
1000 case Intrinsic::uadd_sat: in isIntrinsicSupported()
1001 case Intrinsic::usub_sat: in isIntrinsicSupported()
1002 case Intrinsic::sadd_sat: in isIntrinsicSupported()
1003 case Intrinsic::ssub_sat: in isIntrinsicSupported()
1004 case Intrinsic::umin: in isIntrinsicSupported()
1005 case Intrinsic::umax: in isIntrinsicSupported()
1006 case Intrinsic::smin: in isIntrinsicSupported()
1007 case Intrinsic::smax: in isIntrinsicSupported()
1008 case Intrinsic::abs: in isIntrinsicSupported()
1009 case Intrinsic::ctlz: in isIntrinsicSupported()
1010 case Intrinsic::cttz: in isIntrinsicSupported()
1011 case Intrinsic::ctpop: in isIntrinsicSupported()
1021 case Intrinsic::uadd_sat: in intrinsic()
1023 case Intrinsic::usub_sat: in intrinsic()
1025 case Intrinsic::sadd_sat: in intrinsic()
1027 case Intrinsic::ssub_sat: in intrinsic()
1029 case Intrinsic::umin: in intrinsic()
1031 case Intrinsic::umax: in intrinsic()
1033 case Intrinsic::smin: in intrinsic()
1035 case Intrinsic::smax: in intrinsic()
1037 case Intrinsic::abs: { in intrinsic()
1040 assert(IntMinIsPoison->getBitWidth() == 1 && "Must be boolean"); in intrinsic()
1041 return Ops[0].abs(IntMinIsPoison->getBoolValue()); in intrinsic()
1043 case Intrinsic::ctlz: { in intrinsic()
1046 assert(ZeroIsPoison->getBitWidth() == 1 && "Must be boolean"); in intrinsic()
1047 return Ops[0].ctlz(ZeroIsPoison->getBoolValue()); in intrinsic()
1049 case Intrinsic::cttz: { in intrinsic()
1052 assert(ZeroIsPoison->getBitWidth() == 1 && "Must be boolean"); in intrinsic()
1053 return Ops[0].cttz(ZeroIsPoison->getBoolValue()); in intrinsic()
1055 case Intrinsic::ctpop: in intrinsic()
1071 APInt NewUpper = getUpper() + Other.getUpper() - 1; in add()
1097 // we must return Empty set. In this case, we get that for free, because we in addWithNoWrap()
1117 APInt NewLower = getLower() - Other.getUpper() + 1; in sub()
1118 APInt NewUpper = getUpper() - Other.getLower(); in sub()
1133 // Calculate the range for "X - Y" which is guaranteed not to wrap(overflow). in subWithNoWrap()
1144 // we must return Empty set. In signed case, we get that for free, because we in subWithNoWrap()
1163 // be non-wrapping, round the result min and max value to the appropriate in multiply()
1165 // range according to the greatest power-of-two factor of the single element. in multiply()
1171 if (C->isOne()) in multiply()
1173 if (C->isAllOnes()) in multiply()
1178 if (C->isOne()) in multiply()
1180 if (C->isAllOnes()) in multiply()
1184 // Multiplication is signedness-independent. However different ranges can be in multiply()
1202 // In this case, skip the extra work of generating signed ranges which aren't in multiply()
1209 // here, the lower bound is the smallest of the cartesian product of the in multiply()
1210 // lower and upper ranges; for example: in multiply()
1211 // [-1,4) * [-2,3) = min(-1*-2, -1*2, 3*-2, 3*2) = -6. in multiply()
1328 APInt Lower = getUnsignedMin().udiv(RHS.getUnsignedMax()); in udiv() local
1333 // except for a range in the form of [X, 1) in which case it would be X. in udiv()
1341 return getNonEmpty(std::move(Lower), std::move(Upper)); in udiv()
1350 // There are no positive 1-bit values. The 1 would get interpreted as -1. in sdiv()
1363 PosRes = ConstantRange(PosL.Lower.sdiv(PosR.Upper - 1), in sdiv()
1364 (PosL.Upper - 1).sdiv(PosR.Lower) + 1); in sdiv()
1369 // We need to deal with one tricky case here: SignedMin / -1 is UB on the in sdiv()
1370 // IR level, so we'll want to exclude this case when calculating bounds. in sdiv()
1371 // (For APInts the operation is well-defined and yields SignedMin.) We in sdiv()
1372 // handle this by dropping either SignedMin from the LHS or -1 from the RHS. in sdiv()
1373 APInt Lo = (NegL.Upper - 1).sdiv(NegR.Lower); in sdiv()
1374 if (NegL.Lower.isMinSignedValue() && NegR.Upper.isZero()) { in sdiv()
1375 // Remove -1 from the LHS. Skip if it's the only element, as this would in sdiv()
1377 if (!NegR.Lower.isAllOnes()) { in sdiv()
1379 if (RHS.Lower.isAllOnes()) in sdiv()
1380 // Negative part of [-1, X] without -1 is [SignedMin, X]. in sdiv()
1383 // [X, -1] without -1 is [X, -2]. in sdiv()
1384 AdjNegRUpper = NegR.Upper - 1; in sdiv()
1387 ConstantRange(Lo, NegL.Lower.sdiv(AdjNegRUpper - 1) + 1)); in sdiv()
1395 // Negative part of [X, SignedMin] without SignedMin is [X, -1]. in sdiv()
1396 AdjNegLLower = Lower; in sdiv()
1399 AdjNegLLower = NegL.Lower + 1; in sdiv()
1403 AdjNegLLower.sdiv(NegR.Upper - 1) + 1)); in sdiv()
1407 ConstantRange(std::move(Lo), NegL.Lower.sdiv(NegR.Upper - 1) + 1)); in sdiv()
1414 NegRes = ConstantRange((PosL.Upper - 1).sdiv(NegR.Upper - 1), in sdiv()
1415 PosL.Lower.sdiv(NegR.Lower) + 1); in sdiv()
1420 ConstantRange(NegL.Lower.sdiv(PosR.Lower), in sdiv()
1421 (NegL.Upper - 1).sdiv(PosR.Upper - 1) + 1)); in sdiv()
1423 // Prefer a non-wrapping signed range here. in sdiv()
1438 if (RHSInt->isZero()) in urem()
1442 return {LHSInt->urem(*RHSInt)}; in urem()
1450 APInt Upper = APIntOps::umin(getUnsignedMax(), RHS.getUnsignedMax() - 1) + 1; in urem()
1460 if (RHSInt->isZero()) in srem()
1464 return {LHSInt->srem(*RHSInt)}; in srem()
1486 APInt Upper = APIntOps::umin(MaxLHS, MaxAbsRHS - 1) + 1; in srem()
1492 if (MinLHS.ugt(-MinAbsRHS)) in srem()
1495 APInt Lower = APIntOps::umax(MinLHS, -MaxAbsRHS + 1); in srem() local
1496 return ConstantRange(std::move(Lower), APInt(getBitWidth(), 1)); in srem()
1500 APInt Lower = APIntOps::umax(MinLHS, -MaxAbsRHS + 1); in srem() local
1501 APInt Upper = APIntOps::umin(MaxLHS, MaxAbsRHS - 1) + 1; in srem()
1502 return ConstantRange(std::move(Lower), std::move(Upper)); in srem()
1542 // Special-case binary complement, since we can give a precise answer. in binaryXor()
1543 if (Other.isSingleElement() && Other.getSingleElement()->isAllOnes()) in binaryXor()
1545 if (isSingleElement() && getSingleElement()->isAllOnes()) in binaryXor()
1556 // If LHS is known to be the subset of RHS, treat LHS ^ RHS as RHS -nuw/nsw in binaryXor()
1558 // -nuw/nsw RHS. in binaryXor()
1562 CR = CR.intersectWith(this->sub(Other), PreferredRangeType::Unsigned); in binaryXor()
1575 if (RHS->uge(BW)) in shl()
1579 if (RHS->ule(EqualLeadingBits)) in shl()
1583 APInt::getBitsSetFrom(BW, RHS->getZExtValue()) + 1); in shl()
1624 // operation, when Upper of the LHS of ashr is a non-negative. in ashr()
1625 // number. Since ashr of a non-negative number will result in a in ashr()
1630 // 'PosMin' is the lower bound of the result of the ashr in ashr()
1631 // operation, when Lower of the LHS is a non-negative number. in ashr()
1632 // Since ashr of a non-negative number will result in a smaller in ashr()
1633 // number, the Lower value of LHS is shifted right with the in ashr()
1644 // 'NegMin' is the lower bound of the result of the ashr in ashr()
1645 // operation, when Lower of the LHS of ashr is a negative number. in ashr()
1647 // number, the Lower value of LHS is shifted right with the in ashr()
1653 // Upper and Lower of LHS are non-negative. in ashr()
1657 // Upper and Lower of LHS are negative. in ashr()
1661 // Upper is non-negative and Lower is negative. in ashr()
1717 // Because we could be dealing with negative numbers here, the lower bound is in smul_sat()
1718 // the smallest of the cartesian product of the lower and upper ranges; in smul_sat()
1720 // [-1,4) * [-2,3) = min(-1*-2, -1*2, 3*-2, 3*2) = -6. in smul_sat()
1759 return ConstantRange(Upper, Lower); in inverse()
1769 if (Upper.isStrictlyPositive() || !Lower.isStrictlyPositive()) in abs()
1772 Lo = APIntOps::umin(Lower, -Upper + 1); in abs()
1791 // All non-negative. in abs()
1797 return ConstantRange(-SMax, -SMin + 1); in abs()
1801 APIntOps::umax(-SMin, SMax) + 1); in abs()
1812 // 1) Lower is zero, handling cases of kind [0, 1), [0, 2), etc. in ctlz()
1817 if ((getUpper() - 1).isZero()) { in ctlz()
1818 // We have in input interval of kind [0, 1). In this case we cannot in ctlz()
1819 // really help but return empty-set. in ctlz()
1823 // Compute the resulting range by excluding zero from Lower. in ctlz()
1825 APInt(getBitWidth(), (getUpper() - 1).countl_zero()), in ctlz()
1827 } else if ((getUpper() - 1).isZero()) { in ctlz()
1842 static ConstantRange getUnsignedCountTrailingZerosRange(const APInt &Lower, in getUnsignedCountTrailingZerosRange() argument
1844 assert(!ConstantRange(Lower, Upper).isWrappedSet() && in getUnsignedCountTrailingZerosRange()
1846 assert(Lower != Upper && "Unexpected empty set."); in getUnsignedCountTrailingZerosRange()
1847 unsigned BitWidth = Lower.getBitWidth(); in getUnsignedCountTrailingZerosRange()
1848 if (Lower + 1 == Upper) in getUnsignedCountTrailingZerosRange()
1849 return ConstantRange(APInt(BitWidth, Lower.countr_zero())); in getUnsignedCountTrailingZerosRange()
1850 if (Lower.isZero()) in getUnsignedCountTrailingZerosRange()
1855 unsigned LCPLength = (Lower ^ (Upper - 1)).countl_zero(); in getUnsignedCountTrailingZerosRange()
1856 // If Lower is {LCP, 000...}, the maximum is Lower.countr_zero(). in getUnsignedCountTrailingZerosRange()
1857 // Otherwise, the maximum is BitWidth - LCPLength - 1 ({LCP, 100...}). in getUnsignedCountTrailingZerosRange()
1861 std::max(BitWidth - LCPLength - 1, Lower.countr_zero()) + 1)); in getUnsignedCountTrailingZerosRange()
1873 // 1) Lower is zero, handling cases of kind [0, 1), [0, 2), etc. in cttz()
1877 if (Lower.isZero()) { in cttz()
1879 // We have in input interval of kind [0, 1). In this case we cannot in cttz()
1880 // really help but return empty-set. in cttz()
1884 // Compute the resulting range by excluding zero from Lower. in cttz()
1888 return getUnsignedCountTrailingZerosRange(Lower, Zero); in cttz()
1890 ConstantRange CR1 = getUnsignedCountTrailingZerosRange(Lower, Zero); in cttz()
1900 return getUnsignedCountTrailingZerosRange(Lower, Upper); in cttz()
1902 // [Lower, 0). in cttz()
1903 // Handle [Lower, 0) in cttz()
1904 ConstantRange CR1 = getUnsignedCountTrailingZerosRange(Lower, Zero); in cttz()
1910 static ConstantRange getUnsignedPopCountRange(const APInt &Lower, in getUnsignedPopCountRange() argument
1912 assert(!ConstantRange(Lower, Upper).isWrappedSet() && in getUnsignedPopCountRange()
1914 assert(Lower != Upper && "Unexpected empty set."); in getUnsignedPopCountRange()
1915 unsigned BitWidth = Lower.getBitWidth(); in getUnsignedPopCountRange()
1916 if (Lower + 1 == Upper) in getUnsignedPopCountRange()
1917 return ConstantRange(APInt(BitWidth, Lower.popcount())); in getUnsignedPopCountRange()
1919 APInt Max = Upper - 1; in getUnsignedPopCountRange()
1921 unsigned LCPLength = (Lower ^ Max).countl_zero(); in getUnsignedPopCountRange()
1922 unsigned LCPPopCount = Lower.getHiBits(LCPLength).popcount(); in getUnsignedPopCountRange()
1923 // If Lower is {LCP, 000...}, the minimum is the popcount of LCP. in getUnsignedPopCountRange()
1926 LCPPopCount + (Lower.countr_zero() < BitWidth - LCPLength ? 1 : 0); in getUnsignedPopCountRange()
1927 // If Max is {LCP, 111...}, the maximum is the popcount of LCP + (BitWidth - in getUnsignedPopCountRange()
1929 // Otherwise, the minimum is the popcount of LCP + (BitWidth - in getUnsignedPopCountRange()
1930 // length of LCP - 1). in getUnsignedPopCountRange()
1931 unsigned MaxBits = LCPPopCount + (BitWidth - LCPLength) - in getUnsignedPopCountRange()
1932 (Max.countr_one() < BitWidth - LCPLength ? 1 : 0); in getUnsignedPopCountRange()
1945 return getUnsignedPopCountRange(Lower, Upper); in ctpop()
1947 // [Lower, 0). in ctpop()
1948 // Handle [Lower, 0) == [Lower, Max] in ctpop()
1949 ConstantRange CR1 = ConstantRange(APInt(BitWidth, Lower.countl_one()), in ctpop()
1983 // a s+ b overflows high iff a s>=0 && b s>= 0 && a s> smax - b. in signedAddMayOverflow()
1984 // a s+ b overflows low iff a s< 0 && b s< 0 && a s< smin - b. in signedAddMayOverflow()
1986 Min.sgt(SignedMax - OtherMin)) in signedAddMayOverflow()
1989 Max.slt(SignedMin - OtherMax)) in signedAddMayOverflow()
1993 Max.sgt(SignedMax - OtherMax)) in signedAddMayOverflow()
1996 Min.slt(SignedMin - OtherMin)) in signedAddMayOverflow()
2010 // a u- b overflows low iff a u< b. in unsignedSubMayOverflow()
2029 // a s- b overflows high iff a s>=0 && b s< 0 && a s> smax + b. in signedSubMayOverflow()
2030 // a s- b overflows low iff a s< 0 && b s>= 0 && a s< smin + b. in signedSubMayOverflow()
2070 OS << "full-set"; in print()
2072 OS << "empty-set"; in print()
2074 OS << "[" << Lower << "," << Upper << ")"; in print()
2091 ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue()); in getConstantRangeFromMetadata()
2099 CR = CR.unionWith(ConstantRange(Low->getValue(), High->getValue())); in getConstantRangeFromMetadata()