Skip to content

Make ISLE dataflow optimization control-flow aware (BrIf/BrTable) #56

@avrabe

Description

@avrabe

Context

PR #53 eliminated the has_unsupported_isle_instructions skip block — all standard WASM instructions are now wired into the ISLE pipeline. However, functions containing BrIf or BrTable are still skipped by has_dataflow_unsafe_control_flow for the two term-rewriting passes (optimize_term_rewriting and optimize_advanced_instructions).

Problem

The ISLE dataflow optimization (simplify_with_env) can incorrectly move side effects outside of control flow blocks. For example, a LocalSet after a BrIf may be moved to execute unconditionally — a semantic violation.

This means functions with conditional branches don't get term-rewriting optimizations (constant propagation through locals, redundant load elimination, etc.), even though they now get all other passes (DCE, branch simplification, code folding, etc.).

Solution

Make the dataflow analysis control-flow aware:

  1. Track which values are defined inside conditional blocks
  2. Don't propagate LocalSet values across branch boundaries
  3. Consider using dominator tree analysis to determine safe propagation points
  4. Or: split the function into basic blocks and optimize each independently

Files

  • loom-core/src/lib.rs: has_dataflow_unsafe_control_flow (line ~6654), optimize_term_rewriting (line ~6689), optimize_advanced_instructions (line ~10700)

Impact

This is the last major optimization coverage gap. Removing this restriction would give every function full optimization, not just functions without conditional branches.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions