Skip to content

Commit

Permalink
Merge pull request #876 from jacob-baines/opt_inf_loop
Browse files Browse the repository at this point in the history
Fix infinite loops in copy propagation optimizer
  • Loading branch information
s3rvac authored Oct 31, 2020
2 parents fab0eb8 + a6cd165 commit 9516741
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,14 @@ void CopyPropagationOptimizer::handleCaseInductionVariable(

// Other value is undefined before the other definition.
bool ok = false;
auto prev = commonOtherDef->getUniquePredecessor();
while (prev) {
std::set<ShPtr<Statement>> visited;
for (auto prev = commonOtherDef->getUniquePredecessor(); prev && visited.insert(prev).second;
prev = prev->getUniquePredecessor()) {
auto vds = cast<VarDefStmt>(prev);
if (vds && vds->getVar() == otherValue && vds->getInitializer() == nullptr) {
ok = true;
break;
}
prev = prev->getUniquePredecessor();
}
// Other value may be in another BB.
// In such a case, check for very specific and restrictive pattern.
Expand Down Expand Up @@ -1043,8 +1043,9 @@ void CopyPropagationOptimizer::handleCaseInductionVariable2(
// y is undefined before xZero.
// y = undef
bool ok = false;
auto prev = xZero->getUniquePredecessor();
while (prev) {
std::set<ShPtr<Statement>> visited;
for (auto prev = xZero->getUniquePredecessor(); prev && visited.insert(prev).second;
prev = prev->getUniquePredecessor()) {
auto vds = cast<VarDefStmt>(prev);
if (vds && vds->getVar() == y) {
ok = (vds->getInitializer() == nullptr);
Expand All @@ -1054,7 +1055,6 @@ void CopyPropagationOptimizer::handleCaseInductionVariable2(
if (as && as->getLhs() == y) {
break;
}
prev = prev->getUniquePredecessor();
}
if (!ok) {
LOG << "\t" << "end 10" << std::endl;
Expand Down

0 comments on commit 9516741

Please sign in to comment.