aboutsummaryrefslogtreecommitdiffstats
path: root/libyul
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-10-28 19:58:21 +0800
committerchriseth <chris@ethereum.org>2018-11-09 01:14:36 +0800
commitfa44d2072116fa818282a173f011b30d61c89995 (patch)
tree4dc78dca786b550875584519240690997f6a9955 /libyul
parent20481055e3b439657bd44ea66b05a633477eeaf8 (diff)
downloaddexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.tar
dexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.tar.gz
dexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.tar.bz2
dexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.tar.lz
dexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.tar.xz
dexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.tar.zst
dexon-solidity-fa44d2072116fa818282a173f011b30d61c89995.zip
Remove side-effect-free statements.
Diffstat (limited to 'libyul')
-rw-r--r--libyul/optimiser/README.md2
-rw-r--r--libyul/optimiser/UnusedPruner.cpp10
-rw-r--r--libyul/optimiser/UnusedPruner.h6
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.
*