mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove side-effect-free statements.
This commit is contained in:
parent
20481055e3
commit
fa44d20721
@ -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
|
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.
|
a loop or conditional, the first one is not inside), the first assignment is removed.
|
||||||
|
|
||||||
|
This step also removes movable expression statements.
|
||||||
|
|
||||||
|
|
||||||
## Function Unifier
|
## Function Unifier
|
||||||
|
|
||||||
|
@ -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);
|
removeEmptyBlocks(_block);
|
||||||
|
|
||||||
|
@ -32,10 +32,8 @@ namespace yul
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimisation stage that removes unused variables and functions.
|
* Optimisation stage that removes unused variables and functions and also
|
||||||
*
|
* removes movable expression statements.
|
||||||
* TODO: Also remove intermediate variable assignments from movable expressions
|
|
||||||
* which are not referenced until after the next assignment to the same variable.
|
|
||||||
*
|
*
|
||||||
* Note that this does not remove circular references.
|
* Note that this does not remove circular references.
|
||||||
*
|
*
|
||||||
|
@ -16,9 +16,7 @@
|
|||||||
// {
|
// {
|
||||||
// let _18 := 0x20
|
// let _18 := 0x20
|
||||||
// let allocate__7 := 0x40
|
// let allocate__7 := 0x40
|
||||||
// let allocate_p_12 := mload(allocate__7)
|
// mstore(allocate__7, add(mload(allocate__7), _18))
|
||||||
// mstore(allocate__7, add(allocate_p_12, _18))
|
|
||||||
// pop(allocate_p_12)
|
|
||||||
// let allocate_p_12_31 := mload(allocate__7)
|
// let allocate_p_12_31 := mload(allocate__7)
|
||||||
// mstore(allocate__7, add(allocate_p_12_31, allocate__7))
|
// mstore(allocate__7, add(allocate_p_12_31, allocate__7))
|
||||||
// mstore(add(allocate_p_12_31, 96), 2)
|
// mstore(add(allocate_p_12_31, 96), 2)
|
||||||
|
8
test/libyul/yulOptimizerTests/unusedPruner/pop.yul
Normal file
8
test/libyul/yulOptimizerTests/unusedPruner/pop.yul
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
let a := 1
|
||||||
|
pop(a)
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// unusedPruner
|
||||||
|
// {
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user