This patch removes the "isSigned" parameter from the methods of ConstantRange. That concept was redundant with the wrapped set, except that wrapped set is a property of the ConstantRange.
Patch attached. This updates users of ConstantRange to cope with the modified API. Nick
Index: include/llvm/Support/ConstantRange.h =================================================================== RCS file: /var/cvs/llvm/llvm/include/llvm/Support/ConstantRange.h,v retrieving revision 1.19 diff -u -t -d -u -p -5 -r1.19 ConstantRange.h --- include/llvm/Support/ConstantRange.h 28 Feb 2007 22:02:48 -0000 1.19 +++ include/llvm/Support/ConstantRange.h 1 Mar 2007 05:00:51 -0000 @@ -38,11 +38,11 @@ namespace llvm { class ConstantRange { APInt Lower, Upper; static ConstantRange intersect1Wrapped(const ConstantRange &LHS, - const ConstantRange &RHS, bool sign); + const ConstantRange &RHS); public: /// Initialize a full (the default) or empty set for the specified bit width. /// ConstantRange(uint32_t BitWidth, bool isFullSet = true); @@ -77,17 +77,15 @@ class ConstantRange { bool isEmptySet() const; /// isWrappedSet - Return true if this set wraps around the top of the range, /// for example: [100, 8) /// - bool isWrappedSet(bool isSigned) const; + bool isWrappedSet() const; /// contains - Return true if the specified value is in the set. - /// The isSigned parameter indicates whether the comparisons should be - /// performed as if the values are signed or not. /// - bool contains(const APInt &Val, bool isSigned) const; + bool contains(const APInt &Val) const; /// getSingleElement - If this set contains a single element, return it, /// otherwise return null. /// const APInt *getSingleElement() const { @@ -121,19 +119,19 @@ class ConstantRange { /// this range with another range. The resultant range is pruned as much as /// possible, but there may be cases where elements are included that are in /// one of the sets but not the other. For example: [100, 8) intersect [3, /// 120) yields [3, 120) /// - ConstantRange intersectWith(const ConstantRange &CR, bool isSigned) const; + ConstantRange intersectWith(const ConstantRange &CR) const; /// unionWith - Return the range that results from the union of this range /// with another range. The resultant range is guaranteed to include the /// elements of both sets, but may contain more. For example, [3, 9) union /// [12,15) is [3, 15), which includes 9, 10, and 11, which were not included /// in either set before. /// - ConstantRange unionWith(const ConstantRange &CR, bool isSigned) const; + ConstantRange unionWith(const ConstantRange &CR) const; /// zeroExtend - Return a new range in the specified integer type, which must /// be strictly larger than the current type. The returned range will /// correspond to the possible range of values if the source range had been /// zero extended to BitWidth. Index: lib/Support/ConstantRange.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/Support/ConstantRange.cpp,v retrieving revision 1.38 diff -u -t -d -u -p -5 -r1.38 ConstantRange.cpp --- lib/Support/ConstantRange.cpp 28 Feb 2007 22:02:48 -0000 1.38 +++ lib/Support/ConstantRange.cpp 1 Mar 2007 05:00:51 -0000 @@ -63,13 +63,11 @@ bool ConstantRange::isEmptySet() const { } /// isWrappedSet - Return true if this set wraps around the top of the range, /// for example: [100, 8) /// -bool ConstantRange::isWrappedSet(bool isSigned) const { - if (isSigned) - return Lower.sgt(Upper); +bool ConstantRange::isWrappedSet() const { return Lower.ugt(Upper); } /// getSetSize - Return the number of elements in this set. /// @@ -86,24 +84,16 @@ APInt ConstantRange::getSetSize() const return Upper - Lower; } /// contains - Return true if the specified value is in the set. /// -bool ConstantRange::contains(const APInt &V, bool isSigned) const { - if (Lower == Upper) { - if (isFullSet()) - return true; - return false; - } +bool ConstantRange::contains(const APInt &V) const { + if (Lower == Upper) + return isFullSet(); - if (!isWrappedSet(isSigned)) - if (isSigned) - return Lower.sle(V) && V.slt(Upper); - else - return Lower.ule(V) && V.ult(Upper); - if (isSigned) - return Lower.sle(V) || V.slt(Upper); + if (!isWrappedSet()) + return Lower.ule(V) && V.ult(Upper); else return Lower.ule(V) || V.ult(Upper); } /// subtract - Subtract the specified constant from the endpoints of this @@ -120,21 +110,19 @@ ConstantRange ConstantRange::subtract(co // intersect1Wrapped - This helper function is used to intersect two ranges when // it is known that LHS is wrapped and RHS isn't. // ConstantRange ConstantRange::intersect1Wrapped(const ConstantRange &LHS, - const ConstantRange &RHS, bool isSigned) { - assert(LHS.isWrappedSet(isSigned) && !RHS.isWrappedSet(isSigned)); + const ConstantRange &RHS) { + assert(LHS.isWrappedSet() && !RHS.isWrappedSet()); // Check to see if we overlap on the Left side of RHS... // - bool LT = (isSigned ? RHS.Lower.slt(LHS.Upper) : RHS.Lower.ult(LHS.Upper)); - bool GT = (isSigned ? RHS.Upper.sgt(LHS.Lower) : RHS.Upper.ugt(LHS.Lower)); - if (LT) { + if (RHS.Lower.ult(LHS.Upper)) { // We do overlap on the left side of RHS, see if we overlap on the right of // RHS... - if (GT) { + if (RHS.Upper.ugt(LHS.Lower)) { // Ok, the result overlaps on both the left and right sides. See if the // resultant interval will be smaller if we wrap or not... // if (LHS.getSetSize().ult(RHS.getSetSize())) return LHS; @@ -146,11 +134,11 @@ ConstantRange::intersect1Wrapped(const C return ConstantRange(RHS.Lower, LHS.Upper); } } else { // We don't overlap on the left side of RHS, see if we overlap on the right // of RHS... - if (GT) { + if (RHS.Upper.ugt(LHS.Lower)) { // Simple overlap... return ConstantRange(LHS.Lower, RHS.Upper); } else { // No overlap... return ConstantRange(LHS.getBitWidth(), false); @@ -159,40 +147,39 @@ ConstantRange::intersect1Wrapped(const C } /// intersectWith - Return the range that results from the intersection of this /// range with another range. /// -ConstantRange ConstantRange::intersectWith(const ConstantRange &CR, - bool isSigned) const { +ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const { assert(getBitWidth() == CR.getBitWidth() && "ConstantRange types don't agree!"); // Handle common special cases if (isEmptySet() || CR.isFullSet()) return *this; if (isFullSet() || CR.isEmptySet()) return CR; - if (!isWrappedSet(isSigned)) { - if (!CR.isWrappedSet(isSigned)) { + if (!isWrappedSet()) { + if (!CR.isWrappedSet()) { using namespace APIntOps; - APInt L = isSigned ? smax(Lower, CR.Lower) : umax(Lower, CR.Lower); - APInt U = isSigned ? smin(Upper, CR.Upper) : umin(Upper, CR.Upper); + APInt L = umax(Lower, CR.Lower); + APInt U = umin(Upper, CR.Upper); - if (isSigned ? L.slt(U) : L.ult(U)) // If range isn't empty... + if (L.ult(U)) // If range isn't empty... return ConstantRange(L, U); else return ConstantRange(getBitWidth(), false);// Otherwise, empty set } else - return intersect1Wrapped(CR, *this, isSigned); + return intersect1Wrapped(CR, *this); } else { // We know "this" is wrapped... - if (!CR.isWrappedSet(isSigned)) - return intersect1Wrapped(*this, CR, isSigned); + if (!CR.isWrappedSet()) + return intersect1Wrapped(*this, CR); else { // Both ranges are wrapped... using namespace APIntOps; - APInt L = isSigned ? smax(Lower, CR.Lower) : umax(Lower, CR.Lower); - APInt U = isSigned ? smin(Upper, CR.Upper) : umin(Upper, CR.Upper); + APInt L = umax(Lower, CR.Lower); + APInt U = umin(Upper, CR.Upper); return ConstantRange(L, U); } } return *this; } @@ -201,12 +188,11 @@ ConstantRange ConstantRange::intersectWi /// another range. The resultant range is guaranteed to include the elements of /// both sets, but may contain more. For example, [3, 9) union [12,15) is [3, /// 15), which includes 9, 10, and 11, which were not included in either set /// before. /// -ConstantRange ConstantRange::unionWith(const ConstantRange &CR, - bool isSigned) const { +ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const { assert(getBitWidth() == CR.getBitWidth() && "ConstantRange types don't agree!"); assert(0 && "Range union not implemented yet!"); Index: lib/Analysis/ScalarEvolution.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/Analysis/ScalarEvolution.cpp,v retrieving revision 1.97 diff -u -t -d -u -p -5 -r1.97 ScalarEvolution.cpp --- lib/Analysis/ScalarEvolution.cpp 28 Feb 2007 23:31:17 -0000 1.97 +++ lib/Analysis/ScalarEvolution.cpp 1 Mar 2007 05:00:54 -0000 @@ -2346,11 +2346,11 @@ SCEVHandle SCEVAddRecExpr::getNumIterati // Okay at this point we know that all elements of the chrec are constants and // that the start element is zero. // First check to see if the range contains zero. If not, the first // iteration exits. - if (!Range.contains(APInt(getBitWidth(),0), isSigned)) + if (!Range.contains(APInt(getBitWidth(),0))) return SCEVConstant::get(ConstantInt::get(getType(),0)); if (isAffine()) { // If this is an affine expression then we have this situation: // Solve {0,+,A} in Range === Ax in Range @@ -2370,17 +2370,17 @@ SCEVHandle SCEVAddRecExpr::getNumIterati // Evaluate at the exit value. If we really did fall out of the valid // range, then we computed our trip count, otherwise wrap around or other // things must have happened. ConstantInt *Val = EvaluateConstantChrecAtConstant(this, ExitValue); - if (Range.contains(Val->getValue(), isSigned)) + if (Range.contains(Val->getValue())) return new SCEVCouldNotCompute(); // Something strange happened // Ensure that the previous value is in the range. This is a sanity check. assert(Range.contains( EvaluateConstantChrecAtConstant(this, - ConstantInt::get(getType(), ExitVal - One))->getValue(), isSigned) && + ConstantInt::get(getType(), ExitVal - One))->getValue()) && "Linear scev computation is off in a bad way!"); return SCEVConstant::get(cast<ConstantInt>(ExitValue)); } else if (isQuadratic()) { // If this is a quadratic (3-term) AddRec {L,+,M,+,N}, find the roots of the // quadratic equation to solve it. To do this, we must frame our problem in @@ -2407,29 +2407,29 @@ SCEVHandle SCEVAddRecExpr::getNumIterati // Make sure the root is not off by one. The returned iteration should // not be in the range, but the previous one should be. When solving // for "X*X < 5", for example, we should not return a root of 2. ConstantInt *R1Val = EvaluateConstantChrecAtConstant(this, R1->getValue()); - if (Range.contains(R1Val->getValue(), isSigned)) { + if (Range.contains(R1Val->getValue())) { // The next iteration must be out of the range... Constant *NextVal = ConstantExpr::getAdd(R1->getValue(), ConstantInt::get(R1->getType(), 1)); R1Val = EvaluateConstantChrecAtConstant(this, NextVal); - if (!Range.contains(R1Val->getValue(), isSigned)) + if (!Range.contains(R1Val->getValue())) return SCEVUnknown::get(NextVal); return new SCEVCouldNotCompute(); // Something strange happened } // If R1 was not in the range, then it is a good return value. Make // sure that R1-1 WAS in the range though, just in case. Constant *NextVal = ConstantExpr::getSub(R1->getValue(), ConstantInt::get(R1->getType(), 1)); R1Val = EvaluateConstantChrecAtConstant(this, NextVal); - if (Range.contains(R1Val->getValue(), isSigned)) + if (Range.contains(R1Val->getValue())) return R1; return new SCEVCouldNotCompute(); // Something strange happened } } } @@ -2447,12 +2447,11 @@ SCEVHandle SCEVAddRecExpr::getNumIterati SCEVHandle Val = evaluateAtIteration(SCEVConstant::get(TestVal)); if (!isa<SCEVConstant>(Val)) // This shouldn't happen. return new SCEVCouldNotCompute(); // Check to see if we found the value! - if (!Range.contains(cast<SCEVConstant>(Val)->getValue()->getValue(), - isSigned)) + if (!Range.contains(cast<SCEVConstant>(Val)->getValue()->getValue())) return SCEVConstant::get(TestVal); // Increment to test the next index. TestVal = cast<ConstantInt>(ConstantExpr::getAdd(TestVal, One)); } while (TestVal != EndVal); Index: lib/Transforms/Scalar/CorrelatedExprs.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/Transforms/Scalar/CorrelatedExprs.cpp,v retrieving revision 1.55 diff -u -t -d -u -p -5 -r1.55 CorrelatedExprs.cpp --- lib/Transforms/Scalar/CorrelatedExprs.cpp 28 Feb 2007 22:03:51 -0000 1.55 +++ lib/Transforms/Scalar/CorrelatedExprs.cpp 1 Mar 2007 05:00:54 -0000 @@ -1154,12 +1154,11 @@ Relation::KnownResult CEE::getCmpResult( // if (ConstantInt *C = dyn_cast<ConstantInt>(Op1)) { // Check to see if we already know the result of this comparison... ICmpInst::Predicate ipred = ICmpInst::Predicate(predicate); ConstantRange R = ICmpInst::makeConstantRange(ipred, C->getValue()); - ConstantRange Int = R.intersectWith(Op0VI->getBounds(), - ICmpInst::isSignedPredicate(ipred)); + ConstantRange Int = R.intersectWith(Op0VI->getBounds()); // If the intersection of the two ranges is empty, then the condition // could never be true! // if (Int.isEmptySet()) { @@ -1201,12 +1200,12 @@ bool Relation::contradicts(unsigned Op, // if (ConstantInt *C = dyn_cast<ConstantInt>(Val)) if (Op >= ICmpInst::FIRST_ICMP_PREDICATE && Op <= ICmpInst::LAST_ICMP_PREDICATE) { ICmpInst::Predicate ipred = ICmpInst::Predicate(Op); - if (ICmpInst::makeConstantRange(ipred, C->getValue()).intersectWith( - VI.getBounds(), ICmpInst::isSignedPredicate(ipred)).isEmptySet()) + if (ICmpInst::makeConstantRange(ipred, C->getValue()) + .intersectWith(VI.getBounds()).isEmptySet()) return true; } switch (Rel) { default: assert(0 && "Unknown Relationship code!"); @@ -1262,12 +1261,12 @@ bool Relation::incorporate(unsigned Op, if (ConstantInt *C = dyn_cast<ConstantInt>(Val)) if (Op >= ICmpInst::FIRST_ICMP_PREDICATE && Op <= ICmpInst::LAST_ICMP_PREDICATE) { ICmpInst::Predicate ipred = ICmpInst::Predicate(Op); VI.getBounds() = - ICmpInst::makeConstantRange(ipred, C->getValue()).intersectWith( - VI.getBounds(), ICmpInst::isSignedPredicate(ipred)); + ICmpInst::makeConstantRange(ipred, C->getValue()) + .intersectWith(VI.getBounds()); } switch (Rel) { default: assert(0 && "Unknown prior value!"); case Instruction::Add: Rel = Op; return true;
_______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits