Cross-statement CSE with hoisting to common ancestor scope
Add `Declare_local of scope_id` IR node that emits a local variable
declaration and zero-initialization. Implement `hoist_cross_statement_cse`
pass that scans flattened Seq siblings for alpha-equivalent Local_scope
nodes across different Set statements, hoists them as Declare_local +
body before the first user, and replaces all occurrences with Get_local.
The pass runs after intra-statement CSE in the optimization pipeline,
includes a conservative safety check that rejects hoisting when
intervening statements write to tensors read by the Local_scope body.
Includes regression test exercising to_doc, to_doc_cstyle, and
c_syntax pp_ll paths with cross-statement deduplication.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9fb1c8
-
Apr 22 22:19 +00:00