Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loops in copy propagation optimizer #876

Merged
merged 1 commit into from
Oct 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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