@@ -841,14 +841,14 @@ void CopyPropagationOptimizer::handleCaseInductionVariable(
841
841
842
842
// Other value is undefined before the other definition.
843
843
bool ok = false ;
844
- auto prev = commonOtherDef->getUniquePredecessor ();
845
- while (prev) {
844
+ std::set<ShPtr<Statement>> visited;
845
+ for (auto prev = commonOtherDef->getUniquePredecessor (); prev && visited.insert (prev).second ;
846
+ prev = prev->getUniquePredecessor ()) {
846
847
auto vds = cast<VarDefStmt>(prev);
847
848
if (vds && vds->getVar () == otherValue && vds->getInitializer () == nullptr ) {
848
849
ok = true ;
849
850
break ;
850
851
}
851
- prev = prev->getUniquePredecessor ();
852
852
}
853
853
// Other value may be in another BB.
854
854
// In such a case, check for very specific and restrictive pattern.
@@ -1043,8 +1043,9 @@ void CopyPropagationOptimizer::handleCaseInductionVariable2(
1043
1043
// y is undefined before xZero.
1044
1044
// y = undef
1045
1045
bool ok = false ;
1046
- auto prev = xZero->getUniquePredecessor ();
1047
- while (prev) {
1046
+ std::set<ShPtr<Statement>> visited;
1047
+ for (auto prev = xZero->getUniquePredecessor (); prev && visited.insert (prev).second ;
1048
+ prev = prev->getUniquePredecessor ()) {
1048
1049
auto vds = cast<VarDefStmt>(prev);
1049
1050
if (vds && vds->getVar () == y) {
1050
1051
ok = (vds->getInitializer () == nullptr );
@@ -1054,7 +1055,6 @@ void CopyPropagationOptimizer::handleCaseInductionVariable2(
1054
1055
if (as && as->getLhs () == y) {
1055
1056
break ;
1056
1057
}
1057
- prev = prev->getUniquePredecessor ();
1058
1058
}
1059
1059
if (!ok) {
1060
1060
LOG << " \t " << " end 10" << std::endl;
0 commit comments