diff options
author | chriseth <chris@ethereum.org> | 2018-11-09 02:09:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-09 02:09:07 +0800 |
commit | cbd0116e98862a36d6c904ed03d8d26b248838f0 (patch) | |
tree | 4dc78dca786b550875584519240690997f6a9955 /libyul/optimiser | |
parent | 20481055e3b439657bd44ea66b05a633477eeaf8 (diff) | |
parent | fa44d2072116fa818282a173f011b30d61c89995 (diff) | |
download | dexon-solidity-cbd0116e98862a36d6c904ed03d8d26b248838f0.tar.gz dexon-solidity-cbd0116e98862a36d6c904ed03d8d26b248838f0.tar.zst dexon-solidity-cbd0116e98862a36d6c904ed03d8d26b248838f0.zip |
Merge pull request #5326 from ethereum/removeSideEffectFreeStatements
[Yul] Remove side-effect-free statements.
Diffstat (limited to 'libyul/optimiser')
-rw-r--r-- | libyul/optimiser/README.md | 2 | ||||
-rw-r--r-- | libyul/optimiser/UnusedPruner.cpp | 10 | ||||
-rw-r--r-- | libyul/optimiser/UnusedPruner.h | 6 |
3 files changed, 14 insertions, 4 deletions
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<ExpressionStatement>(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. * |