-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid unnecessary pops in evm code transform. #12759
Conversation
69d8a68
to
ab5242e
Compare
ab5242e
to
31113b2
Compare
Gas differences: Click for a table of gas differences
Diff of all regressions: https://gist.github.com/ekpyron/4fee7493fcf1f43088f1a7082d074867 |
Diff of external benchmarks between develop and this PR: https://gist.github.com/ekpyron/6f22ccabbed99b96c78dc0f9ec61624b |
f19e401
to
0e6021a
Compare
@@ -117,6 +117,35 @@ struct OpPop: SimplePeepholeOptimizerMethod<OpPop> | |||
} | |||
}; | |||
|
|||
struct OpStop: SimplePeepholeOptimizerMethod<OpStop> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this not handled by other steps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently not...
Ideally, this wouldn't be needed, but apparently some cases still slip through the logic below... and it generally doesn't hurt to have this.
It fixes the regression on the FixedRegistrar
semantics test and saves ~2% of code size there apparently... this warrants a closer look at some point, but for now the peephole optimizer seems like a good fallback mechanism.
@@ -134,7 +126,9 @@ sub_0: assembly { | |||
tag_4 | |||
jumpi | |||
pop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I know - not entirely sure why it isn't yet. Either the logic in the rest of the PR misses some cases or this only comes into existence during evmasm optimization...
e9e0363
to
c82c196
Compare
FYI this doesn't seem to measurably affect compile times on |
visited.insert(_u); | ||
depths[_u] = low[_u] = _depth; | ||
|
||
vector<CFG::BasicBlock*> children; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector<CFG::BasicBlock*> children; | |
vector<CFG::BasicBlock*> children = _u->entries; |
@chriseth This I think I should still change... without this, I'm visiting the graph as directed graph, but the algorithm assumes it's undirected... it does affect gas costs, sometimes a bit better, sometimes a bit worse... I'm a bit surprised that it works both ways, but also visiting the entries here is probably the safer choice - although it may be worth thinking through this a bit more at some point...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe someone should try to understand the algorithm...
075af6f
to
faaf0b9
Compare
@@ -134,7 +126,9 @@ sub_0: assembly { | |||
tag_4 | |||
jumpi | |||
pop | |||
jump(tag_3) | |||
0x00 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it not deduplicate anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure.
But I find it suspicious that the evmasm optimiser first inlines, then removes unused tags and then deduplicates (which relies on stuff being tagged, if I read it correctly)... I guess there's something off with that there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true. I think the deduplicator even ignores additional tags when it compares for equality.
faaf0b9
to
5cd9800
Compare
Not happy about this yet, but pushing it as draft nonetheless...
Doesn't work in all cases either as it stands (and adds too much junk for some reason)...