commit 7c59b98aaf9e129ef7277ef38782580f11ffd81f
parent fb2cb4c3a776e1ec0dd98270eb41140bdb991565
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Tue, 16 Jun 2026 01:04:29 -0700
doc/plan/O1.md: record the landed -O1 quality worklist (1.25x -> 1.09x clang)
Diffstat:
| M | doc/plan/O1.md | | | 73 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- |
1 file changed, 70 insertions(+), 3 deletions(-)
diff --git a/doc/plan/O1.md b/doc/plan/O1.md
@@ -62,10 +62,19 @@ diff text/mix across the corpus) — it was ad-hoc for this analysis.
---
-## 2. Current standings (2026-06-15, after commit 8826982d)
+## 2. Current standings
-**Aggregate `__TEXT` ≈ 1.25× clang `-O1`** across the corpus — but the ratio is
-bimodal and the aggregate understates the truth:
+> **Update (2026-06-16): the §3 worklist is fully landed (see §5).** Aggregate
+> `__TEXT` is now **≈ 1.09× clang `-O1`** (down from 1.25×, a −12.8% reduction in
+> kit's emitted `__TEXT`). The dominant symptom below — spill-address `sub x29`
+> at 36% of lvm / 12% of sqlite — is **eliminated** on aa64 (lvm 8,774 → 0,
+> sqlite 35,360 → 0; lvm `__TEXT` 96,788 → 59,276, **4.66× → 2.86×**; sqlite
+> 1.27× → 1.11×; miniz 1.94× → 1.67×; the clang-favored lz4/yyjson held at
+> 0.38×/0.86×). sqlite `-O1` compile stayed ≈1.6→1.67s (linear; W3 the main
+> contributor). The pre-campaign analysis below is retained for context.
+
+**[Pre-campaign] Aggregate `__TEXT` ≈ 1.25× clang `-O1`** across the corpus — but
+the ratio is bimodal and the aggregate understates the truth:
| file | kit/clang | note |
|---------|----------:|------|
@@ -715,6 +724,64 @@ up / ship the O2 path for that workload, not to bolt a non-linear analysis onto
## 5. Already landed
+### The §3 worklist (2026-06-16) — all items shipped
+
+Implemented in parallel (worktree-isolated), merged one-at-a-time against the
+`scripts/o1_quality.sh` harness, each correctness-gated (`test-opt` structural
+guard + `test-toy` 1392/0 + ecosystem 28/0 + smoke-x64/rv64). **Cumulative:
+aggregate `__TEXT` 1.25× → 1.09× clang; lvm 4.66× → 2.86×; sqlite `sub x29`
+35,360 → 0; sqlite `-O1` compile ≈1.6s → ≈1.67s (linear).**
+
+- **W1a** `c6baf36f` — local frame-address `add`/`sub`-CSE (`pass_combine.c`):
+ back-to-back rebuilds of the same frame address become a `mov`. Subsumed on
+ aa64 spill slots by W1.1; still fires on the positive `add xN,x29,#k` form.
+ Guard `redundant_frame_sub.sh`.
+- **W1.0** `d9902a7e` — hot-slot-low frame ordering (`pass_native_emit.c` +
+ `ir.h`/`native_target.h` priority field + `pass_lower.c` aggregation): hottest
+ spills get the smallest displacement. **aa64 −4.9% aggregate alone**; x64
+ disp8 density; rv64 keeps hot slots in the imm12 window. Guard
+ `hot_slot_order.sh`.
+- **W1.1** `9a99a0aa` — aa64 uniform x29-at-bottom known-frame layout
+ (`aa64/native.c`): every spill slot is one-instruction positive `ldr/str
+ [x29,#k]`; the `sub x17,x29,#k` fallback is gone for every known frame, alloca
+ included; fp-chain/CFI/tail-call preserved. **The big win: lvm −36%, sqlite
+ −11%, `sub x29` → 0.** Guard `aa64_x29_bottom.sh`.
+- **W3** `6f4cd59a` — linear move coalescing (`pass_coalesce.c`, populating
+ `opt_coalesce_parent` before `opt_assign_ranges`; no O(n²) matrix). Taught
+ `opt_verify_alloc` about coalesce roots and replaced the `mir_combine`
+ `!opt_coalesce_parent` proxy with an explicit `opt_o1_coalescing` flag. −1.43%
+ aggregate, spills not worse; +~7% sqlite `-O1` compile (the main cost). Guard
+ `o1_coalesce.sh`.
+- **W2** `a6992971` — rematerialization instead of spilling (`pass_lower.c`):
+ small `load_imm` / `addr_of[local]` recompute at the use; spill store dropped
+ when every use remats. sqlite −0.58% (801 stores dropped). Guard `o1_remat.sh`.
+- **W7** `9f3f9a01` — switch-chain immediate compares (`pass_native_emit.c`):
+ case values fold to `cmp #imm` instead of materializing a scratch; selector
+ pinned; per-arch fallback. cjson −1.0%, lua subset −0.47%. Guard
+ `o1_switch_imm.sh`.
+- **W6+W8** `fb2cb4c3` — cmp-imm + add-offset folds, and same-block spill
+ dead-store elimination (`pass_combine.c`). sqlite −0.21%, lvm −0.61%. W8 is a
+ correct/linear net that currently finds 0 sites (W2/DCE clear the pattern
+ upstream — the "compounds with W2" case). Guards `o1_cmp_imm.sh`,
+ `o1_stack_dse.sh`.
+- **W9+W10** `f97f2c08` — one-pass O1 branch cleanup + constant `cmp_branch`
+ folding (`pass_jump.c`): same-target collapse, pass-through forwarding (one
+ shot, ≤1 CFG rebuild), `x==x`/imm-imm fold; FP same-reg never folded; computed
+ goto preserved. Low ceiling on real C as predicted. Guard `o1_branch_cleanup.sh`.
+- **W4** `d4eeb840` — inline-pressure cap (`pass_inline.c`): the whole-program
+ inliner backs off into already-huge/high-pressure callers (cap 512), small +
+ `always_inline` still fuse. Byte-identical on the win files (lz4/yyjson
+ preserved); sqlite −324B / −75 spill insns; inliner phase faster. Guard
+ `o1_inline_cap.sh`.
+- **W1.2** `a1ccdbcb` — rv64 far-slot assessment (no codegen change): measured
+ **zero** far-slot traffic in lvm/sqlite hot loops (±2KB window + W1.0 ordering
+ cover it), so no residual work warranted, per the doc. Guard `rv64_far_slot.sh`.
+- **W1.3** — x64 is W1.0 alone (disp8 density); validated, no separate change.
+- **Harness** `b1950955` — `scripts/o1_quality.sh`, the A/B `-O1` quality
+ measurement (the §1 TODO).
+
+### Earlier
+
- **commit 8826982d** — three local, target-agnostic copy/extension folds:
`addr_of [base+0] → copy` and same-width same-class `convert → copy`
(`pass_simplify.c`), and `ZEXT(zero-extending load) → copy`