Skip to content

Branch Simplification (RemoveUnusedBrs) #16

@avrabe

Description

@avrabe

Goal

Remove unreachable branches, fold constant conditions, simplify control flow.

Why High-Impact

  • 30-40% of code has simplifiable branches
  • Guard patterns and error handling create many constant-folded branches
  • Enables block merging and further DCE
  • LOOM currently has NO control flow support - major gap

Tasks

  • Implement constant condition folding for br_if
  • Remove branches that are never taken
  • Remove branches that are always taken (replace with unconditional br)
  • Simplify branch tables with constant indices
  • Remove unreachable code after unconditional branches
  • Add tests for branch optimization scenarios

Dependencies

Implementation Complexity

Medium-High

Priority

CRITICAL

Estimated Time

2-3 weeks (after control flow support)

References

  • wasm-opt: remove-unused-brs pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions