Skip to content

Use WTOWorklist in ConstraintAnalysis and RedundantSetElimination - #9216

Merged
tlively merged 12 commits into
mainfrom
wto-passes
Oct 8, 2026
Merged

tlively merged 12 commits into
mainfrom
wto-passes

Conversation

@tlively

@tlively tlively commented Oct 6, 2026

Copy link
Copy Markdown
Member

Replace RPOQueue with WTOWorklist in ConstraintAnalysis and
RedundantSetElimination so that loops stabilize before flow values
propagate to downstream blocks. This avoids quadratic/cubic blowups on
functions with sequential loops while also speeding up general workloads.

Benchmark results across 16 WebAssembly modules (3 iterations):

  • --constraint-analysis:
    • esbuild.wasm: 381.60s -> 7.59s (-98.0%, 50.3x speedup)
    • 15 non-esbuild modules geomean: 1.564s -> 1.487s (-4.9%)
    • 15 non-esbuild modules total: 72.00s -> 57.24s (-20.5%)
    • All 16 modules geomean: 2.205s -> 1.646s (-25.4%)
    • All 16 modules total: 453.60s -> 64.83s (-85.7%)
  • --rse:
    • esbuild.wasm: >600s (timeout) -> 1.62s (>370x speedup)
    • 15 non-esbuild modules total: 26.40s -> 25.47s (-3.5%)
    • All 16 modules geomean: N/A -> 0.922s (total: 27.09s)

Add `src/cfg/wto.h` with `WeakTopologicalOrdering` (`WTO`) and `WTOWorklist` built on top of `DomTree`. In a reducible CFG ordered in reverse postorder, every cycle is a natural loop headed by a block that dominates all blocks in the cycle, allowing a Bourdoncle Weak Topological Ordering to be constructed directly from the dominator tree and natural loops of the CFG.

Include unit tests in `test/gtest/wto.cpp` and `TODO` comments noting follow-on optimizations.
Replace RPOQueue with WTOWorklist in ConstraintAnalysis and
RedundantSetElimination so that loops stabilize before flow values
propagate to downstream blocks. This avoids quadratic/cubic blowups on
functions with sequential loops while also speeding up general workloads.

Benchmark results across 16 WebAssembly modules (3 iterations):
- --constraint-analysis:
  - esbuild.wasm: 381.60s -> 7.59s (-98.0%, 50.3x speedup)
  - 15 non-esbuild modules geomean: 1.564s -> 1.487s (-4.9%)
  - 15 non-esbuild modules total: 72.00s -> 57.24s (-20.5%)
  - All 16 modules geomean: 2.205s -> 1.646s (-25.4%)
  - All 16 modules total: 453.60s -> 64.83s (-85.7%)
- --rse:
  - esbuild.wasm: >600s (timeout) -> 1.62s (>370x speedup)
  - 15 non-esbuild modules total: 26.40s -> 25.47s (-3.5%)
  - All 16 modules geomean: N/A -> 0.922s (total: 27.09s)
@tlively
tlively requested a review from kripken October 6, 2026 07:06
@tlively
tlively requested a review from a team as a code owner October 6, 2026 07:07

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that is some compelling data!

@kripken

kripken commented Oct 7, 2026

Copy link
Copy Markdown
Member

ccing #4165 as this makes compilation faster

Base automatically changed from domtree-wto2 to main October 7, 2026 18:52
@tlively
tlively enabled auto-merge (squash) October 7, 2026 23:28
@tlively
tlively merged commit 93d6e9d into main Oct 8, 2026
16 checks passed
@tlively
tlively deleted the wto-passes branch October 8, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants