Add an isOne() utility function to ScalarEvolution, similar to isZero()
authorDan Gohman <gohman@apple.com>
Mon, 18 May 2009 15:22:39 +0000 (15:22 +0000)
committerDan Gohman <gohman@apple.com>
Mon, 18 May 2009 15:22:39 +0000 (15:22 +0000)
and similar to ConstantInt's isOne().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72003 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/ScalarEvolution.h
lib/Analysis/ScalarEvolution.cpp

index 76e23b1169ba809764c1bf5f003a5335dd68d5dd..a5534e89c4e2a5cb883f7c0e2db705dfdab82ad3 100644 (file)
@@ -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
index 77a807063147e9d0e899dc3093d2f786449d37aa..4b99a869ff5fcd2e17033509b80f0c1df874c30c 100644 (file)
@@ -127,6 +127,11 @@ bool SCEV::isZero() const {
   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() {}
@@ -3392,7 +3397,7 @@ HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
     const SCEVConstant *CStep = dyn_cast<SCEVConstant>(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<SCEVConstant>(RHS)) {