commit 9903260e5965896db10241d23abfcd72b7c446ce
parent a68bf13802fcf376e1f5331422e27e7457d37504
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Thu, 21 May 2026 19:41:44 -0700
Refresh O2 optimizer plan
Diffstat:
| M | doc/OPT.md | | | 53 | ++++++++++++++++++++++++++++++++++++++++------------- |
1 file changed, 40 insertions(+), 13 deletions(-)
diff --git a/doc/OPT.md b/doc/OPT.md
@@ -444,6 +444,15 @@ copy_prop
verify(o2-copy-prop-ssa)
ssa_dce
verify(o2-copy-dce)
+dse
+verify(o2-dse-ssa)
+ssa_dce
+verify(o2-dse-dce)
+build_loop_tree
+licm
+verify(o2-licm-ssa)
+pressure_relief
+verify(o2-pressure-relief-ssa)
make_conventional_ssa
verify(o2-conventional-ssa)
undo_ssa
@@ -627,10 +636,15 @@ Current behavior:
- The first post-address value passes are in the O2 path: `opt_simplify`
canonicalizes cheap scalar/address identities before GVN; scalar GVN rewrites
dominated duplicate pure expressions and folds safe integer
- constants/branches; the first memory-aware GVN slice rewrites exact
- straight-line redundant loads and store/load reuse through the documented
- alias/version model; and `opt_copy_prop` propagates SSA copy chains plus
- collapses redundant integer extension chains.
+ constants/branches; the memory-aware GVN slice rewrites exact redundant
+ loads and store/load reuse through the documented alias/version model; and
+ `opt_copy_prop` propagates SSA copy chains plus collapses redundant integer
+ extension chains.
+- The first memory and loop passes are in the O2 path: `opt_dse` removes exact
+ overwritten or unread non-escaping local stores, `opt_licm` hoists safe loop
+ invariants while leaving trapping and memory operations in place, and
+ `opt_pressure_relief` sinks single-use immediate/constant defs with a
+ per-block linear rewrite plan.
Temporary defensive/pessimizing checks to lift:
@@ -653,8 +667,10 @@ Temporary defensive/pessimizing checks to lift:
are retargeted when CFG cleanup forwards or removes labeled trampoline
blocks.
-The next implementation work should continue extending this small-pass path
-incrementally before attempting GVN/DSE/LICM.
+The next implementation work should close the remaining Phase D gaps:
+`opt_ssa_combine` first, then full O2 jump optimization beyond the shared O1
+jump cleanup. After that, Phase E inlining and cleanup become the next major
+O2 feature.
---
@@ -811,11 +827,6 @@ Implement in order:
Do not batch these into one landing. Each pass needs a pass-local corpus case
that fails red without the pass or its bug fix.
-GVN is deliberately after this milestone. It should wait until SSA DCE, copy
-cleanup, block cloning, and address folding have made CFG mutation,
-memory/address operand mutation, verifier coverage, and analysis invalidation
-boring and reliable.
-
The path-aware memory GVN slice is now landed. Keep later memory rewrites tied
to the documented alias and memory numbering model: do not expand `IR_LOAD`
rewrites or reason across `IR_STORE`, calls, atomics, fences, volatile
@@ -913,6 +924,18 @@ Current DSE slice:
unread non-escaped locals, escaped-local call preservation, and volatile
preservation.
+Current LICM and pressure relief slices:
+
+- [x] `opt_licm` runs after DSE/DCE and loop-tree construction, hoisting safe
+ loop-invariant scalar work to preheaders.
+- [x] LICM pass-local tests cover safe invariant hoisting and preservation of
+ memory loads and potentially trapping division.
+- [x] `opt_pressure_relief` runs after LICM, planning all legal same-block
+ single-use immediate/constant sinks from one def-use rebuild and applying
+ affected block rewrites in linear passes.
+- [x] Pressure-relief pass-local tests cover sinking, loop-boundary refusal,
+ multi-use preservation, memory barriers, and many same-block moves.
+
Scalar/address identity simplification now runs before memory GVN. Red-green
coverage includes integer neutral/annihilator identities, same-register
integer identities, same-value integer compares, exact no-op conversions,
@@ -938,8 +961,12 @@ Remaining Phase D exit criteria:
- [x] Identity simplification has focused pass-local tests, a toy end-to-end
fixture, and an AArch64 disassembly sanity check showing identity arithmetic
removed from the generated code.
-- [ ] LICM, pressure relief, SSA combine, and full O2 jump optimization each
- have focused red-green tests before they enter the default O2 schedule.
+- [x] LICM and pressure relief have focused pass-local tests and are in the
+ default O2 schedule.
+- [ ] `opt_ssa_combine` has focused red-green tests before it enters the
+ default O2 schedule.
+- [ ] Full O2 jump optimization has focused red-green tests before it enters
+ the default O2 schedule.
### Phase E - Inlining and Cleanup