aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-10-11 18:41:04 +0000
committerChris Lattner <sabre@nondot.org>2005-10-11 18:41:04 +0000
commitd6155e96f78a9f4344f5e697f7dd74d2f2325092 (patch)
treedc4cad6430b1359e0dafad88e956ac49a0697e06 /lib/Transforms/Scalar/LoopStrengthReduce.cpp
parent7b445c521bc191d0d25799b289e17b45f202a1af (diff)
Fix (hopefully the last) issue where LSR is nondeterminstic. When pulling
out CSE's of base expressions it could build a result whose order was nondet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23698 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index ad88fc10b2..a74b91b4f7 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -715,6 +715,10 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) {
// If any subexpressions are used Uses.size() times, they are common.
std::map<SCEVHandle, unsigned> SubExpressionUseCounts;
+ // UniqueSubExprs - Keep track of all of the subexpressions we see in the
+ // order we see them.
+ std::vector<SCEVHandle> UniqueSubExprs;
+
std::vector<SCEVHandle> SubExprs;
for (unsigned i = 0; i != NumUses; ++i) {
// If the base is zero (which is common), return zero now, there are no
@@ -725,22 +729,24 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) {
SeparateSubExprs(SubExprs, Uses[i].Base);
// Add one to SubExpressionUseCounts for each subexpr present.
for (unsigned j = 0, e = SubExprs.size(); j != e; ++j)
- SubExpressionUseCounts[SubExprs[j]]++;
+ if (++SubExpressionUseCounts[SubExprs[j]] == 1)
+ UniqueSubExprs.push_back(SubExprs[j]);
SubExprs.clear();
}
-
- // Now that we know how many times each is used, build Result.
- for (std::map<SCEVHandle, unsigned>::iterator I =
- SubExpressionUseCounts.begin(), E = SubExpressionUseCounts.end();
- I != E; )
+ // Now that we know how many times each is used, build Result. Iterate over
+ // UniqueSubexprs so that we have a stable ordering.
+ for (unsigned i = 0, e = UniqueSubExprs.size(); i != e; ++i) {
+ std::map<SCEVHandle, unsigned>::iterator I =
+ SubExpressionUseCounts.find(UniqueSubExprs[i]);
+ assert(I != SubExpressionUseCounts.end() && "Entry not found?");
if (I->second == NumUses) { // Found CSE!
Result = SCEVAddExpr::get(Result, I->first);
- ++I;
} else {
// Remove non-cse's from SubExpressionUseCounts.
- SubExpressionUseCounts.erase(I++);
+ SubExpressionUseCounts.erase(I);
}
+ }
// If we found no CSE's, return now.
if (Result == Zero) return Result;