Remove the "isSigned" parameters from ConstantRange. It turns out they

are not needed as the results are the same with or without it.

Patch by Nicholas Lewycky.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34782 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2007-03-01 07:54:15 +00:00
parent cda067bad9
commit a6e8a955d6
4 changed files with 40 additions and 58 deletions

View File

@ -40,7 +40,7 @@ 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.
///
@ -79,13 +79,11 @@ class ConstantRange {
/// 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.
@ -123,7 +121,7 @@ class ConstantRange {
/// 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
@ -131,7 +129,7 @@ class ConstantRange {
/// [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

View File

@ -2345,7 +2345,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// 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()) {
@ -2369,13 +2369,13 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// 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()) {
@ -2406,14 +2406,14 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
// 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
}
@ -2424,7 +2424,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
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
}
@ -2446,8 +2446,7 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
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.

View File

@ -65,9 +65,7 @@ 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);
}
@ -88,20 +86,12 @@ APInt ConstantRange::getSetSize() const {
/// 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);
}
@ -122,17 +112,15 @@ ConstantRange ConstantRange::subtract(const APInt &Val) const {
//
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...
//
@ -148,7 +136,7 @@ ConstantRange::intersect1Wrapped(const ConstantRange &LHS,
} 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 {
@ -161,8 +149,7 @@ ConstantRange::intersect1Wrapped(const ConstantRange &LHS,
/// 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
@ -171,26 +158,26 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
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);
}
}
@ -203,8 +190,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
/// 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!");

View File

@ -1156,8 +1156,7 @@ Relation::KnownResult CEE::getCmpResult(CmpInst *CI,
// 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!
@ -1203,8 +1202,8 @@ bool Relation::contradicts(unsigned Op,
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;
}
@ -1264,8 +1263,8 @@ bool Relation::incorporate(unsigned Op, ValueInfo &VI) {
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) {