Skip to content

Commit

Permalink
Merge pull request ethereum#12322 from tzann/patch-1
Browse files Browse the repository at this point in the history
Fix ExpressionSplitter example
  • Loading branch information
chriseth authored Dec 1, 2021
2 parents 8569cf3 + d56fb3a commit d2585fd
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions docs/internals/optimizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -521,18 +521,21 @@ ExpressionSplitter

The expression splitter turns expressions like ``add(mload(0x123), mul(mload(0x456), 0x20))``
into a sequence of declarations of unique variables that are assigned sub-expressions
of that expression so that each function call has only variables or literals
of that expression so that each function call has only variables
as arguments.

The above would be transformed into

.. code-block:: yul
{
let _1 := mload(0x123)
let _2 := mul(_1, 0x20)
let _3 := mload(0x456)
let z := add(_3, _2)
let _1 = 0x20
let _2 = 0x456
let _3 = mload(_2)
let _4 = mul(_3, _1)
let _5 = 0x123
let _6 = mload(_5)
let z = add(_6, _4)
}
Note that this transformation does not change the order of opcodes or function calls.
Expand All @@ -543,7 +546,7 @@ this "outlining" of the inner expressions in all cases. We can sidestep this lim

The final program should be in a form such that (with the exception of loop conditions)
function calls cannot appear nested inside expressions
and all function call arguments have to be literals or variables.
and all function call arguments have to be variables.

The benefits of this form are that it is much easier to re-order the sequence of opcodes
and it is also easier to perform function call inlining. Furthermore, it is simpler
Expand Down

0 comments on commit d2585fd

Please sign in to comment.