[llvm-commits] CVS: llvm/lib/Analysis/ScalarEvolution.cpp

Chris Lattner sabre at nondot.org
Mon Dec 18 17:16:17 PST 2006



Changes in directory llvm/lib/Analysis:

ScalarEvolution.cpp updated: 1.72 -> 1.73
---
Log message:

Fix a bug in GetConstantFactor for affine expressions, in which the existing
code was wrong for things like 3+4*i.



---
Diffs of the changes:  (+9 -5)

 ScalarEvolution.cpp |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)


Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.72 llvm/lib/Analysis/ScalarEvolution.cpp:1.73
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.72	Tue Dec 12 17:36:14 2006
+++ llvm/lib/Analysis/ScalarEvolution.cpp	Mon Dec 18 19:16:02 2006
@@ -74,6 +74,7 @@
 #include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/InstIterator.h"
 #include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/ADT/Statistic.h"
 #include <ostream>
@@ -1372,11 +1373,14 @@
   }
     
   if (SCEVAddRecExpr *A = dyn_cast<SCEVAddRecExpr>(S)) {
-    // FIXME: Generalize.
-    if (A->getNumOperands() == 2)
-      return std::min(GetConstantFactor(A->getOperand(0)),
-                      GetConstantFactor(A->getOperand(1)));
-    // ?
+    // For now, we just handle linear expressions.
+    if (A->getNumOperands() == 2) {
+      // We want the GCD between the start and the stride value.
+      uint64_t Start = GetConstantFactor(A->getOperand(0));
+      if (Start == 1) return 1;
+      uint64_t Stride = GetConstantFactor(A->getOperand(1));
+      return GreatestCommonDivisor64(Start, Stride);
+    }
   }
   
   // SCEVSDivExpr, SCEVUnknown.






More information about the llvm-commits mailing list