-
-
Notifications
You must be signed in to change notification settings - Fork 808
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
fix: block mload
merging when src and dst overlap
#3635
Merged
charles-cooper
merged 11 commits into
vyperlang:master
from
charles-cooper:fix/merge_mload
Oct 3, 2023
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2191fc3
fix: block mload merging when src and dst overlap
charles-cooper f01eb07
use continue instead of break
charles-cooper 00150f7
fix the condition
charles-cooper a126502
fix the condition again
charles-cooper 5580e98
add test for mload merge overlap
charles-cooper 066f212
fix the condition to allow full overlap to become mcopy
charles-cooper 668ba84
add more unit tests for merge_mload
charles-cooper d739d09
add more mload merge tests
charles-cooper a0ef351
add more mload merging tests
charles-cooper cb71178
fix lint
charles-cooper d996a1e
clarify a couple test cases
charles-cooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,10 +662,10 @@ def _rewrite_mstore_dload(argz): | |
def _merge_mload(argz): | ||
if not version_check(begin="cancun"): | ||
return False | ||
return _merge_load(argz, "mload", "mcopy") | ||
return _merge_load(argz, "mload", "mcopy", allow_overlap=False) | ||
|
||
|
||
def _merge_load(argz, _LOAD, _COPY): | ||
def _merge_load(argz, _LOAD, _COPY, allow_overlap=True): | ||
# look for sequential operations copying from X to Y | ||
# and merge them into a single copy operation | ||
changed = False | ||
|
@@ -689,6 +689,11 @@ def _merge_load(argz, _LOAD, _COPY): | |
initial_dst_offset = dst_offset | ||
initial_src_offset = src_offset | ||
idx = i | ||
|
||
if not allow_overlap and initial_dst_offset <= initial_src_offset <= dst_offset: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you have to do do a + 32 somewhere here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the @external
def partial() -> uint256:
a: uint256 = 1337
b: uint256 = 0
c: uint256 = 0
d: uint256 = 0
e: uint256 = 0
c = a
d = b
e = c
return e |
||
# dst and src overlap, discontinue the optimization | ||
continue | ||
|
||
if ( | ||
initial_dst_offset + total_length == dst_offset | ||
and initial_src_offset + total_length == src_offset | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: think generally params should be "safe-by-default", and the "safer" option would be to have no overlap.
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.
hmm i see, my thinking was that this only affects where the source and destination address spaces are the same, and there is only one case for this,
mload
/mstore
. but i am open to changing the default.