From fa44d2072116fa818282a173f011b30d61c89995 Mon Sep 17 00:00:00 2001 From: chriseth Date: Sun, 28 Oct 2018 12:58:21 +0100 Subject: Remove side-effect-free statements. --- libyul/optimiser/README.md | 2 ++ libyul/optimiser/UnusedPruner.cpp | 10 ++++++++++ libyul/optimiser/UnusedPruner.h | 6 ++---- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'libyul') diff --git a/libyul/optimiser/README.md b/libyul/optimiser/README.md index faef818b..c2575179 100644 --- a/libyul/optimiser/README.md +++ b/libyul/optimiser/README.md @@ -135,6 +135,8 @@ If there are two assignments to a variable where the first one is a movable expr and the variable is not used between the two assignments (and the second is not inside a loop or conditional, the first one is not inside), the first assignment is removed. +This step also removes movable expression statements. + ## Function Unifier diff --git a/libyul/optimiser/UnusedPruner.cpp b/libyul/optimiser/UnusedPruner.cpp index a7b32873..71e86798 100644 --- a/libyul/optimiser/UnusedPruner.cpp +++ b/libyul/optimiser/UnusedPruner.cpp @@ -85,6 +85,16 @@ void UnusedPruner::operator()(Block& _block) }}; } } + else if (statement.type() == typeid(ExpressionStatement)) + { + ExpressionStatement& exprStmt = boost::get(statement); + if (MovableChecker(exprStmt.expression).movable()) + { + // pop(x) should be movable! + subtractReferences(ReferencesCounter::countReferences(exprStmt.expression)); + statement = Block{std::move(exprStmt.location), {}}; + } + } removeEmptyBlocks(_block); diff --git a/libyul/optimiser/UnusedPruner.h b/libyul/optimiser/UnusedPruner.h index 2dd74940..b5aea3dd 100644 --- a/libyul/optimiser/UnusedPruner.h +++ b/libyul/optimiser/UnusedPruner.h @@ -32,10 +32,8 @@ namespace yul { /** - * Optimisation stage that removes unused variables and functions. - * - * TODO: Also remove intermediate variable assignments from movable expressions - * which are not referenced until after the next assignment to the same variable. + * Optimisation stage that removes unused variables and functions and also + * removes movable expression statements. * * Note that this does not remove circular references. * -- cgit v1.2.3