Remove side-effect-free expressions, and not only movable expressions.

This commit is contained in:
chriseth 2019-05-13 18:41:37 +02:00
parent e8a88b13e4
commit aa24e12054
2 changed files with 3 additions and 4 deletions

View File

@ -75,7 +75,7 @@ void UnusedPruner::operator()(Block& _block)
{ {
if (!varDecl.value) if (!varDecl.value)
statement = Block{std::move(varDecl.location), {}}; statement = Block{std::move(varDecl.location), {}};
else if (MovableChecker(m_dialect, *varDecl.value).movable()) else if (MovableChecker(m_dialect, *varDecl.value).sideEffectFree())
{ {
subtractReferences(ReferencesCounter::countReferences(*varDecl.value)); subtractReferences(ReferencesCounter::countReferences(*varDecl.value));
statement = Block{std::move(varDecl.location), {}}; statement = Block{std::move(varDecl.location), {}};
@ -93,9 +93,8 @@ void UnusedPruner::operator()(Block& _block)
else if (statement.type() == typeid(ExpressionStatement)) else if (statement.type() == typeid(ExpressionStatement))
{ {
ExpressionStatement& exprStmt = boost::get<ExpressionStatement>(statement); ExpressionStatement& exprStmt = boost::get<ExpressionStatement>(statement);
if (MovableChecker(m_dialect, exprStmt.expression).movable()) if (MovableChecker(m_dialect, exprStmt.expression).sideEffectFree())
{ {
// pop(x) should be movable!
subtractReferences(ReferencesCounter::countReferences(exprStmt.expression)); subtractReferences(ReferencesCounter::countReferences(exprStmt.expression));
statement = Block{std::move(exprStmt.location), {}}; statement = Block{std::move(exprStmt.location), {}};
} }

View File

@ -32,7 +32,7 @@ struct Dialect;
/** /**
* Optimisation stage that removes unused variables and functions and also * Optimisation stage that removes unused variables and functions and also
* removes movable expression statements. * removes side-effect-free expression statements.
* *
* Note that this does not remove circular references. * Note that this does not remove circular references.
* *