Skip to content

Rewrite: hoist loop-invariant py.Constant out of closure bodies in ilist.foreach/ilist.map #698

Description

@zhenrongliew

Closures passed to ilist.foreach/ilist.map often contain py.Constant statements that don't depend on the loop element. Unrolling/inlining these bodies re-materializes the constants per iteration, which blows up IR size and compile time.

Solution

A rewrite that lifts py.Constant (later, any loop-invariant pure statement) from a closure body into the enclosing region, iterating to fixpoint so constants escape nested foreach/map bodies.

Bodies that genuinely depend on the element are unaffected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compiler optimizationArea: compiler optimization passes, IR transformations, and code generation improvements.area: rewriteArea: rewrite rules, pattern matching, and optimizer passes.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions