Skip to content

Commit

Permalink
restore assembly swap
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Nov 20, 2024
1 parent 367baa3 commit 24e9615
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ def _generate_evm_for_instruction(
# the same variable, however, before a jump that is not possible
self._stack_reorder(assembly, stack, list(target_stack))

if inst.is_commutative:
cost_no_swap = self._stack_reorder([], stack, operands, dry_run=True)
operands[-1], operands[-2] = operands[-2], operands[-1]
cost_with_swap = self._stack_reorder([], stack, operands, dry_run=True)
if cost_with_swap > cost_no_swap:
operands[-1], operands[-2] = operands[-2], operands[-1]

cost = self._stack_reorder([], stack, operands, dry_run=True)
if DEBUG_SHOW_COST and cost:
print("ENTER", inst, file=sys.stderr)
Expand Down

0 comments on commit 24e9615

Please sign in to comment.