Introduce JumpdestRemover optimisation step#2657
Conversation
|
Some of the bigger assemblies in the Parity multisig (assembly items: before, after): The function dispatcher leaves a lot of stray jumpdests, we could fix that or could keep a simple remover such as this. |
|
Haven't bothered updating the tests which check the exact bytecode before the code is accepted. |
|
Probably this should be run again after dedup/CSE. |
|
This step was previously done by the control flow graph optimizer, but it was removed because we currently cannot assume that labels that are never pushed can be removed, because they can be stored in storage. If we do a full analysis also passing in referenced labels "from above", it might work. In any case, there should be a test that fails if you do not consider this. |
Hm, yes that's true, this change would break that. Thinking a bit more about that, is that valid usage though? If it is at any point of time pushed to storage in the code/constructor, it is already safe. In an example like |
|
When the jumpdest remover as currently implemented analyses the runtime assembly, it does not consider the jumpdests from the runtime assembly that were accessed in the creation time assembly. |
True. Is that an actual case we have? I guess if helpers are used in a constructor which are also used in runtime functions. Strange no tests caught this, should add a test for it. |
|
The test |
|
Doesn't seem to fail on that one. |
|
As can be seen here - https://medium.com/@hayeah/diving-into-the-ethereum-vm-part-2-storage-layout-bc5349cb11b7 - it seems we have a lot of jumpdests that hinder peephole or CSE optimization, so increasing the priority of this. |
libevmasm/Assembly.cpp
Outdated
| } | ||
| } | ||
|
|
||
| /// Run again after Deduplicate or CSE |
There was a problem hiding this comment.
why is this needed? We will just have another iteration of the loop, won't we?
There was a problem hiding this comment.
I've seen some cases where dedup/cse left unused tags. Admittedly they could be improved to not do that.
|
Ok, now I'm relieved: The test does actually fail. |
f5a5345 to
3b9b103
Compare
|
Can you add some specific tests (including subassemblies) to |
3b9b103 to
27c1bff
Compare
|
Added test. |
libevmasm/JumpdestRemover.h
Outdated
|
|
||
| AssemblyItems& m_items; | ||
| bool mutable m_initialized = false; | ||
| std::set<std::pair<size_t, size_t>> mutable m_referencedTags; |
libevmasm/JumpdestRemover.h
Outdated
| static std::set<size_t> referencedTags(AssemblyItems const& _items, size_t _subId); | ||
|
|
||
| private: | ||
| void analyzeIfNecessary() const; |
d4c3ef3 to
80a865b
Compare
|
Weird that the compiler does not warn about that... |
|
This is ready to be merged. |
|
@chriseth as discussed last meeting we wanted to run the truffle tests on openzeppelin with this change. |
|
What about merging and then testing the nightly? |
|
Depends on #2782. |
a688b9f to
a6a4dee
Compare
|
Rebased, merging this next. |
No description provided.