diff options
author | Chris Lattner <sabre@nondot.org> | 2006-12-19 01:16:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-12-19 01:16:02 +0000 |
commit | 0a1e99317e58d3e705344018cac65f36a98a9414 (patch) | |
tree | 1f916c7d3546466a834a1f6dc4c00576a473171c /llvm/lib/Analysis/ScalarEvolution.cpp | |
parent | c1b828c78df96bef0ebcf09e3531b1df64871e74 (diff) | |
download | bcm5719-llvm-0a1e99317e58d3e705344018cac65f36a98a9414.tar.gz bcm5719-llvm-0a1e99317e58d3e705344018cac65f36a98a9414.zip |
Fix a bug in GetConstantFactor for affine expressions, in which the existing
code was wrong for things like 3+4*i.
llvm-svn: 32662
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7d73d7d3981..6cc89bd8019 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -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 @@ static uint64_t GetConstantFactor(SCEVHandle S) { } 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. |