Skip to content

Commit

Permalink
reorder some code
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Jun 17, 2022
1 parent 65411dd commit fdcb403
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions vyper/ir/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,6 @@ def _int(x):
# e.g. ge x MIN_UINT256, sle x MAX_INT256
return (1, [])

if binop == "lt":
# special case, not covered by the others
if _int(args[1]) == 1:
return ("iszero", [args[0]])
if binop == "gt":
# another special case
if _int(args[1]) == 0:
# improve codesize (not gas)
return ("iszero", [["iszero", args[0]]])

# rewrites. in positions where iszero is preferred, (gt x 5) => (ge x 6)
if is_strict != prefer_strict and _is_int(args[1]):
rhs = _int(args[1])
Expand Down Expand Up @@ -177,6 +167,16 @@ def _int(x):

return (new_op, [args[0], new_rhs])

# some special cases that are not covered by others
if binop == "lt":
if _int(args[1]) == 1:
return ("iszero", [args[0]])

if binop == "gt":
if _int(args[1]) == 0:
# improve codesize (not gas)
return ("iszero", [["iszero", args[0]]])


# def _optimize_arith(
# binop: str, args: IRArgs, ann: Optional[str], parent_op: Any = None
Expand Down

0 comments on commit fdcb403

Please sign in to comment.