Add an isOne() utility function to ScalarEvolution, similar to isZero()

and similar to ConstantInt's isOne().

llvm-svn: 72003
This commit is contained in:
Dan Gohman 2009-05-18 15:22:39 +00:00
parent b81dd48fd2
commit ba7f6d8276
2 changed files with 10 additions and 1 deletions

View File

@ -77,6 +77,10 @@ namespace llvm {
/// ///
bool isZero() const; bool isZero() const;
/// isOne - Return true if the expression is a constant one.
///
bool isOne() const;
/// replaceSymbolicValuesWithConcrete - If this SCEV internally references /// replaceSymbolicValuesWithConcrete - If this SCEV internally references
/// the symbolic value "Sym", construct and return a new SCEV that produces /// the symbolic value "Sym", construct and return a new SCEV that produces
/// the same value, but which uses the concrete value Conc instead of the /// the same value, but which uses the concrete value Conc instead of the

View File

@ -127,6 +127,11 @@ bool SCEV::isZero() const {
return false; return false;
} }
bool SCEV::isOne() const {
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(this))
return SC->getValue()->isOne();
return false;
}
SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {} SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
SCEVCouldNotCompute::~SCEVCouldNotCompute() {} SCEVCouldNotCompute::~SCEVCouldNotCompute() {}
@ -3392,7 +3397,7 @@ HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
const SCEVConstant *CStep = dyn_cast<SCEVConstant>(Step); const SCEVConstant *CStep = dyn_cast<SCEVConstant>(Step);
if (!CStep || CStep->isZero()) if (!CStep || CStep->isZero())
return UnknownValue; return UnknownValue;
if (CStep->getValue()->getValue() == 1) { if (CStep->isOne()) {
// With unit stride, the iteration never steps past the limit value. // With unit stride, the iteration never steps past the limit value.
} else if (CStep->getValue()->getValue().isStrictlyPositive()) { } else if (CStep->getValue()->getValue().isStrictlyPositive()) {
if (const SCEVConstant *CLimit = dyn_cast<SCEVConstant>(RHS)) { if (const SCEVConstant *CLimit = dyn_cast<SCEVConstant>(RHS)) {