Skip to content

Commit

Permalink
moved exp rules from algebraic opt to sccp eval
Browse files Browse the repository at this point in the history
  • Loading branch information
HodanPlodky committed Jan 3, 2025
1 parent 8fca0aa commit 9db6a32
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 0 additions & 6 deletions vyper/venom/passes/algebraic_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,6 @@ def _handle_inst_peephole(self, inst: IRInstruction) -> bool:
return False

if inst.opcode == "exp":
if self._lit_eq(operands[0], 0):
return self._store(inst, 1)

if self._lit_eq(operands[1], 1):
return self._store(inst, 1)

if self._lit_eq(operands[1], 0):
return self._update(inst, "iszero", operands[0])

Expand Down
11 changes: 10 additions & 1 deletion vyper/venom/passes/sccp/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ def wrapper(ops: list[IROperand]) -> IRLiteral | None:

return wrapper

def _exp(ops) -> IRLiteral | None:
if isinstance(ops[0], IRLiteral) and ops[0].value == 0:
return IRLiteral(1)

if isinstance(ops[1], IRLiteral) and ops[1].value == 1:
return IRLiteral(1)

return _wrap_lit(_wrap_binop(evm_pow))(ops)


ARITHMETIC_OPS: dict[str, Callable[[list[IROperand]], IRLiteral | None]] = {
"add": _wrap_lit(_wrap_binop(operator.add)),
Expand All @@ -208,7 +217,7 @@ def wrapper(ops: list[IROperand]) -> IRLiteral | None:
"sdiv": _wrap_multiplicative(_wrap_signed_binop(evm_div)),
"mod": _wrap_mod(_wrap_binop(evm_mod)),
"smod": _wrap_mod(_wrap_signed_binop(evm_mod)),
"exp": _wrap_lit(_wrap_binop(evm_pow)),
"exp": _exp,
"eq": _wrap_abstract_value(_var_eq, _wrap_binop(operator.eq)),
"lt": _wrap_comparison(signed=False, gt=False, oper=_wrap_binop(operator.lt)),
"gt": _wrap_comparison(signed=False, gt=True, oper=_wrap_binop(operator.gt)),
Expand Down

0 comments on commit 9db6a32

Please sign in to comment.