Skip to content

Commit

Permalink
remove swapper in venom_to_assembly
Browse files Browse the repository at this point in the history
and small rename
  • Loading branch information
charles-cooper committed Nov 12, 2024
1 parent 1ebc876 commit d97371b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
10 changes: 5 additions & 5 deletions vyper/venom/basicblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

COMMUTATIVE_INSTRUCTIONS = frozenset(["add", "mul", "smul", "or", "xor", "and", "eq"])

FLIPPABLE_INSTRUCTIONS = ("gt", "lt", "sgt", "slt")
COMPARATOR_INSTRUCTIONS = ("gt", "lt", "sgt", "slt")

if TYPE_CHECKING:
from vyper.venom.function import IRFunction
Expand Down Expand Up @@ -233,8 +233,8 @@ def is_commutative(self) -> bool:
return self.opcode in COMMUTATIVE_INSTRUCTIONS

@property
def is_flippable(self) -> bool:
return self.opcode in FLIPPABLE_INSTRUCTIONS
def is_comparator(self) -> bool:
return self.opcode in COMPARATOR_INSTRUCTIONS

@property
def is_bb_terminator(self) -> bool:
Expand Down Expand Up @@ -288,8 +288,8 @@ def get_outputs(self) -> list[IROperand]:
"""
return [self.output] if self.output else []

def flip_operands(self):
assert self.is_flippable
def flip_comparison(self):
assert self.is_comparator
if self.opcode in ("gt", "sgt"):
self.opcode = self.opcode.replace("g", "l")
else:
Expand Down
6 changes: 3 additions & 3 deletions vyper/venom/passes/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def key(x):
# heuristic: sort by size of child dependency graph
children.sort(key=key)

if inst.is_commutative and children != list(self.ida[inst]):
if inst.is_commutative and children == list(self.ida[inst]):
inst.operands.reverse()

if inst.is_flippable and children != list(self.ida[inst]):
inst.flip_operands()
if inst.is_comparator and children != list(self.ida[inst]):
inst.flip_comparison()

for dep_inst in children:
self._process_instruction_r(instructions, dep_inst)
Expand Down
7 changes: 0 additions & 7 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,6 @@ 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 d97371b

Please sign in to comment.