Skip to content
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[codegen]: same symbol jumpdest merge #3982

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/unit/compiler/asm/test_asm_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from vyper.compiler import compile_code
from vyper.compiler.phases import CompilerData
from vyper.compiler.settings import OptimizationLevel, Settings
from vyper.ir.compile_ir import _merge_jumpdests

codes = [
"""
Expand Down Expand Up @@ -123,3 +124,9 @@

assert "unused1()" not in asm
assert "unused2()" not in asm


def test_merge_jumpdests():
asm = ["_sym_label_0", "JUMP" "PUSH0", "_sym_label_0", "JUMPDEST", "_sym_label_0", "JUMPDEST"]
Fixed Show fixed Hide fixed

assert _merge_jumpdests(asm) is False, "should not return True as no changes were made"
9 changes: 5 additions & 4 deletions vyper/ir/compile_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,11 @@ def _merge_jumpdests(assembly):
# replace all instances of _sym_x with _sym_y
# (except for _sym_x JUMPDEST - don't want duplicate labels)
new_symbol = assembly[i + 2]
for j in range(len(assembly)):
if assembly[j] == current_symbol and i != j:
assembly[j] = new_symbol
changed = True
if new_symbol != current_symbol:
for j in range(len(assembly)):
if assembly[j] == current_symbol and i != j:
assembly[j] = new_symbol
changed = True
elif is_symbol(assembly[i + 2]) and assembly[i + 3] == "JUMP":
# _sym_x JUMPDEST _sym_y JUMP
# replace all instances of _sym_x with _sym_y
Expand Down
Loading