Skip to content

feat(jit): SSA optimization pipeline with CSE/Load CSE - REVIEW NEEDED - #102

Open
bardo84 wants to merge 1 commit into
runmat-org:mainfrom
bardo84:feat/ssa-optimization
Open

feat(jit): SSA optimization pipeline with CSE/Load CSE - REVIEW NEEDED#102
bardo84 wants to merge 1 commit into
runmat-org:mainfrom
bardo84:feat/ssa-optimization

Conversation

@bardo84

@bardo84 bardo84 commented Dec 22, 2025

Copy link
Copy Markdown
Contributor

Summary

Adds SSA-based optimization passes to the Turbine JIT compiler, achieving 7.3x speedup on loop-heavy benchmarks.

⚠️ Review Required

This is an experimental implementation that requires review by founding authors before production use. Key areas needing attention:

  • SSA IR correctness (ssa.rs, ssa_builder.rs)
  • Optimization pass safety (ssa_opt.rs)
  • Performance variance investigation (see benchmark notes)
  • size level regression (slower than none)

Suggested Review Order

  1. Start here: SSA_IR_DEEP_DIVE.md (architecture overview)
  2. Core IR: ssa.rs (data structures, 500 lines)
  3. Optimizations: ssa_opt.rs - focus on:
    • optimize() function (lines 23-52)
    • cse() (lines 347-395)
    • load_cse() (lines 404-450)
  4. Integration: lib.rs changes (146 lines modified)
  5. Skip for now: dominators.rs, loop_analysis.rs (standard algorithms)

Benchmark Results (4B iterations, median of 7 runs)

CLI Optimization Levels

--jit-opt-level SSA Passes Time vs none
none 3.89s 1x
size simplify + DCE 11.18s 0.35x (slower)
speed simplify + DCE + CSE + Load CSE 0.53s 7.3x
aggressive + LICM 3.36s 1.2x

Individual Pass Analysis (via RUNMAT_SSA_PASSES)

Mask Passes Enabled Time Notes
0 none 3.89s Baseline
1 SIMPLIFY only 10.71s Slower than none
2 DCE only 10.97s Slower than none
3 SIMPLIFY + DCE 11.18s Same as size
12 CSE + LOAD_CSE 5.16s 1.3x faster
14 DCE + CSE + LOAD_CSE 0.45s 8.6x faster
15 All except LICM 0.47s 8.3x faster

Key Insight

CSE + Load CSE are the critical optimizations. The combination of all passes (simplify → DCE → CSE → Load CSE → DCE) produces the best results due to pass synergy.

New Optimizations

  1. VarPtr CSE - Eliminates redundant pointer computations
  2. Load CSE - Eliminates redundant loads within basic blocks (with store tracking)

Testing

cargo test -p runmat-turbine  # 104 tests pass
RUNMAT_SSA_PASSES=12 runmat script.m  # Fine-grained pass control

@vercel

vercel Bot commented Dec 22, 2025

Copy link
Copy Markdown

@bardo84 is attempting to deploy a commit to the Dystr Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant