Skip to content

Commit

Permalink
fix: block mload merging when src and dst overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 1, 2023
1 parent c913b2d commit 2191fc3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions vyper/ir/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
# dst and src overlap, block the optimization
break

if (
initial_dst_offset + total_length == dst_offset
and initial_src_offset + total_length == src_offset
Expand Down

0 comments on commit 2191fc3

Please sign in to comment.