From ba7f6d8276a83042cd0147d4ae0b60d1c83fad5f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 18 May 2009 15:22:39 +0000 Subject: [PATCH] Add an isOne() utility function to ScalarEvolution, similar to isZero() and similar to ConstantInt's isOne(). llvm-svn: 72003 --- llvm/include/llvm/Analysis/ScalarEvolution.h | 4 ++++ llvm/lib/Analysis/ScalarEvolution.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 76e23b1169ba..a5534e89c4e2 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -77,6 +77,10 @@ namespace llvm { /// bool isZero() const; + /// isOne - Return true if the expression is a constant one. + /// + bool isOne() const; + /// replaceSymbolicValuesWithConcrete - If this SCEV internally references /// 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 diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 77a807063147..4b99a869ff5f 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -127,6 +127,11 @@ bool SCEV::isZero() const { return false; } +bool SCEV::isOne() const { + if (const SCEVConstant *SC = dyn_cast(this)) + return SC->getValue()->isOne(); + return false; +} SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {} SCEVCouldNotCompute::~SCEVCouldNotCompute() {} @@ -3392,7 +3397,7 @@ HowManyLessThans(const SCEV *LHS, const SCEV *RHS, const SCEVConstant *CStep = dyn_cast(Step); if (!CStep || CStep->isZero()) return UnknownValue; - if (CStep->getValue()->getValue() == 1) { + if (CStep->isOne()) { // With unit stride, the iteration never steps past the limit value. } else if (CStep->getValue()->getValue().isStrictlyPositive()) { if (const SCEVConstant *CLimit = dyn_cast(RHS)) {