Expand let elimination to work on some simple expression types regardless of use count
This commit is contained in:
parent
67a7bbc821
commit
2479dbd9a6
5
opt.py
5
opt.py
|
@ -10,8 +10,9 @@ Optimization: TypeAlias = Callable[[Expression], Option[Expression]]
|
|||
def eliminate_single_let(expr: Expression) -> Option[Expression]:
|
||||
match expr:
|
||||
case LetBinding(lhs, rhs, body):
|
||||
if count_uses(lhs, body) <= 1:
|
||||
# RHS is used at most once i nthe body
|
||||
rhs_is_simple = isinstance(rhs, Int | Variable | Builtin)
|
||||
if count_uses(lhs, body) <= 1 or rhs_is_simple:
|
||||
# RHS is used at most once i nthe body or replication wouldnt be costly
|
||||
if count_uses(lhs, rhs) > 0:
|
||||
# RHS is recursive
|
||||
if not isinstance(body, Variable):
|
||||
|
|
Loading…
Reference in a new issue