Skip to content

Commit

Permalink
update tests, call clear_nops() in remove_unused_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Feb 12, 2025
1 parent c535b05 commit 61ab912
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
14 changes: 2 additions & 12 deletions tests/unit/compiler/venom/test_memmerging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from tests.venom_utils import assert_ctx_eq, parse_from_basic_block, parse_venom
from vyper.evm.opcodes import version_check
from vyper.venom.analysis import IRAnalysesCache
from vyper.venom.passes import SCCP, MemMergePass
from vyper.venom.passes import SCCP, MemMergePass, RemoveUnusedVariablesPass


def _check_pre_post(pre, post):
ctx = parse_from_basic_block(pre)
for fn in ctx.functions.values():
ac = IRAnalysesCache(fn)
MemMergePass(ac, fn).run_pass()
RemoveUnusedVariablesPass(ac, fn).run_pass()
assert_ctx_eq(ctx, parse_from_basic_block(post))


Expand Down Expand Up @@ -853,8 +854,6 @@ def test_memzeroing_2():

post = """
_global:
%1 = calldatasize
%2 = calldatasize
%3 = calldatasize
calldatacopy 64, %3, 256
stop
Expand All @@ -881,8 +880,6 @@ def test_memzeroing_3():

post = """
_global:
%1 = calldatasize
%2 = calldatasize
%3 = calldatasize
calldatacopy 0, %3, 264
stop
Expand All @@ -905,7 +902,6 @@ def test_memzeroing_small_calldatacopy():

post = """
_global:
%1 = calldatasize
mstore 0, 0
stop
"""
Expand Down Expand Up @@ -935,13 +931,8 @@ def test_memzeroing_smaller_calldatacopy():

post = """
_global:
%1 = calldatasize
%2 = calldatasize
%6 = calldatasize
calldatacopy 0, %6, 24
%3 = calldatasize
%4 = calldatasize
%5 = calldatasize
mstore 100, 0
stop
"""
Expand All @@ -966,7 +957,6 @@ def test_memzeroing_overlap():

post = """
_global:
%1 = calldatasize
%2 = calldatasize
calldatacopy 100, %2, 64
stop
Expand Down
4 changes: 4 additions & 0 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,10 @@ def insert_instruction(self, instruction: IRInstruction, index: Optional[int] =
instruction.error_msg = self.parent.error_msg
self.instructions.insert(index, instruction)

def clear_nops(self) -> None:
if any(inst.opcode == "nop" for inst in self.instructions):
self.instructions = [inst for inst in self.instructions if inst.opcode != "nop"]

def remove_instruction(self, instruction: IRInstruction) -> None:
assert isinstance(instruction, IRInstruction), "instruction must be an IRInstruction"
self.instructions.remove(instruction)
Expand Down
3 changes: 3 additions & 0 deletions vyper/venom/passes/remove_unused_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def run_pass(self):
inst = work_list.pop()
self._process_instruction(inst)

for bb in self.function.get_basic_blocks():
bb.clear_nops()

self.analyses_cache.invalidate_analysis(LivenessAnalysis)
self.analyses_cache.invalidate_analysis(DFGAnalysis)

Expand Down

0 comments on commit 61ab912

Please sign in to comment.