From 2191fc3dc6f9ac378d208d9c194c0ca8bfaa8679 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sun, 1 Oct 2023 17:34:20 -0400 Subject: [PATCH] fix: block mload merging when src and dst overlap --- vyper/ir/optimizer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vyper/ir/optimizer.py b/vyper/ir/optimizer.py index 08c2168381..69a70780b0 100644 --- a/vyper/ir/optimizer.py +++ b/vyper/ir/optimizer.py @@ -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: + # dst and src overlap, block the optimization + break + if ( initial_dst_offset + total_length == dst_offset and initial_src_offset + total_length == src_offset