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.

llvm-svn: 23698
This commit is contained in:
Chris Lattner 2005-10-11 18:41:04 +00:00
parent 7effc54496
commit 23ecce5c82

View File

@ -715,6 +715,10 @@ RemoveCommonExpressionsFromUseBases(std::vector<BasedUser> &Uses) {
// If any subexpressions are used Uses.size() times, they are common. // If any subexpressions are used Uses.size() times, they are common.
std::map<SCEVHandle, unsigned> SubExpressionUseCounts; 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; std::vector<SCEVHandle> SubExprs;
for (unsigned i = 0; i != NumUses; ++i) { for (unsigned i = 0; i != NumUses; ++i) {
// If the base is zero (which is common), return zero now, there are no // 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); SeparateSubExprs(SubExprs, Uses[i].Base);
// Add one to SubExpressionUseCounts for each subexpr present. // Add one to SubExpressionUseCounts for each subexpr present.
for (unsigned j = 0, e = SubExprs.size(); j != e; ++j) 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(); SubExprs.clear();
} }
// Now that we know how many times each is used, build Result. Iterate over
// Now that we know how many times each is used, build Result. // UniqueSubexprs so that we have a stable ordering.
for (std::map<SCEVHandle, unsigned>::iterator I = for (unsigned i = 0, e = UniqueSubExprs.size(); i != e; ++i) {
SubExpressionUseCounts.begin(), E = SubExpressionUseCounts.end(); std::map<SCEVHandle, unsigned>::iterator I =
I != E; ) SubExpressionUseCounts.find(UniqueSubExprs[i]);
assert(I != SubExpressionUseCounts.end() && "Entry not found?");
if (I->second == NumUses) { // Found CSE! if (I->second == NumUses) { // Found CSE!
Result = SCEVAddExpr::get(Result, I->first); Result = SCEVAddExpr::get(Result, I->first);
++I;
} else { } else {
// Remove non-cse's from SubExpressionUseCounts. // Remove non-cse's from SubExpressionUseCounts.
SubExpressionUseCounts.erase(I++); SubExpressionUseCounts.erase(I);
} }
}
// If we found no CSE's, return now. // If we found no CSE's, return now.
if (Result == Zero) return Result; if (Result == Zero) return Result;