topic17: v1.2 regression allocator optimization + scenario analysis - #25
Closed
Cynthia-Xichen wants to merge 5 commits into
Closed
topic17: v1.2 regression allocator optimization + scenario analysis#25Cynthia-Xichen wants to merge 5 commits into
Cynthia-Xichen wants to merge 5 commits into
Conversation
jizhenjun
reviewed
Jul 17, 2026
|
|
||
| ## 1. 测试场景总览 | ||
|
|
||
| | 场景 | #vreg | #指令 | 描述 | |
Collaborator
There was a problem hiding this comment.
这里的场景是什么意思,具体的case吗,如果是生成的指令集,可以把对应指令集文件也上传上来
jizhenjun
reviewed
Jul 17, 2026
|
|
||
| ## 2. 核心指标对比 | ||
|
|
||
| | 场景 | Pool | V1.0 peak | V1.2 peak | V1.0 spill | V1.2 spill | V1.0 sw | V1.2 sw | sw减少 | |
Collaborator
There was a problem hiding this comment.
pool、peak、spill、sw这几个字段是什么含义
jizhenjun
reviewed
Jul 17, 2026
|
|
||
| ## 1. 测试场景总览 | ||
|
|
||
| | 场景 | #vreg | #指令 | 描述 | |
jizhenjun
reviewed
Jul 17, 2026
| @@ -0,0 +1,105 @@ | |||
| # 寄存器分配场景分析报告 (v1.2) | |||
|
|
|||
| 基于 9 个测试场景,在 27 个物理寄存器下运行,对比 v1.0(原始版本)与 v1.2(当前版本)的行为差异及优化方向。 | |||
jizhenjun
reviewed
Jul 18, 2026
|
|
||
| | vregs | pool | peak | self | evict | slot | sw | lw | lines | bytes | | ||
| |-------|------|------|------|-------|------|----|----|-------|-------| | ||
| | 33 | 27 | 30 | 0 | 3 | 3 | 3 | 0 | 36 | 600 | |
| **构建方式**: | ||
| ```python | ||
| # 32 个 li 全在 pos=0 定义 + 1 条 add 使用全部 33 个 vreg | ||
| # 所有 interval 完全重叠 [0, 1) |
| mapping = allocator.allocate(intervals) | ||
| code = allocator.get_allocated_code(block) | ||
|
|
||
| # 查看分配报告 |
Collaborator
There was a problem hiding this comment.
溢出清空加入到benchmark里的cycles统计
|
|
||
| 原实现将所有 sw 追加到汇编末尾,导致溢出值的写回顺序与指令执行顺序不一致。修复为按指令位置插入:sw 跟在定义指令之后。同时新增 `_pick_scratch` 方法,为 SPILL_ 标记的变量选择合适的临时加载寄存器。 | ||
|
|
||
| ### 7.4 v1.2 peak_active 统计指标 |
jizhenjun
reviewed
Jul 18, 2026
| mapping = allocator.allocate(intervals) | ||
| code = allocator.get_allocated_code(block) | ||
|
|
||
| # 查看分配报告 |
Collaborator
There was a problem hiding this comment.
统计寄存器溢出次数,让benchmark加入到cycles统计里
|
|
||
| 原实现将所有 sw 追加到汇编末尾,导致溢出值的写回顺序与指令执行顺序不一致。修复为按指令位置插入:sw 跟在定义指令之后。同时新增 `_pick_scratch` 方法,为 SPILL_ 标记的变量选择合适的临时加载寄存器。 | ||
|
|
||
| ### 7.4 v1.2 peak_active 统计指标 |
added 4 commits
July 27, 2026 08:32
- restructured compute_live_intervals to single-pass O(N+V) scan - fixed self-spill handling: proper SPILL_ prefix, no spurious sw - fixed spill code insertion order (sw at correct instruction position) - fixed peak_active tracking position (after allocation, not before) - added allocator report: peak_active, phys_regs_used, spill details - comprehensive 9-scenario benchmark with v1.0 vs v1.2 comparison - added regalloc_scenario_analysis_report_v1.2.md
Full scenario-level analysis covering 64 test cases across two rounds: - 9 high-dimension scenarios (dense_60, spiral_60, large_800x150, etc.) - 32 general edge-case scenarios (T01-T32) - 23 core allocation semantic scenarios (C01-C23) Key findings: 2 correctness bugs (alloc_map eviction, peak_active cap), 4 optimization directions, detailed per-scenario metrics.
Add 23 systematic test scenarios across 6 bottleneck dimensions: - Activity (4): slight/moderate/severe/zero overlap - Lifetime (4): short-lived/long chain/mixed/alternating - Reuse (4): single-spill-many-uses/many-spills-one-use/loop-body/adjacent - Eviction (4): same-end/skewed/chain/spiral - Stack pressure (3): wave/cascade/zero-reuse - Code expansion (4): max-spill/expansion-ratio/dense-chain/random Test framework in scratchv/backend/ for reproducible runs.
…pick_scratch cache)
Bug A (critical·correctness): spill() eviction branch omitted
alloc_map update, causing evicted vregs to be read from wrong phys reg
without a reload (lw). Fix: set alloc_map[vreg] = 'SPILL_{vreg}' after
active.pop() in spill().
Bug B (medium·diagnostic): peak_active capped by pool_size because
self-spilled intervals are not in active[]. Fix: add peak_real_pressure
field that counts self-spilled intervals too.
Bug C (low·code quality): _pick_scratch picked a different scratch reg
each time for the same spilled vreg. Fix: add _scratch_cache with
vreg_hint parameter for last-used-register memory.
Also: fix eviction/self-spill counting in test framework (Bug A fix
changed alloc_map semantics, count evictions from spill_code entries).
+ add code comments
+ sync topic17 design doc and dev doc to v1.3
Cynthia-Xichen
force-pushed
the
topic17-analysis-v1.2
branch
2 times, most recently
from
July 27, 2026 08:45
34b71e0 to
b91127a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Topic 17 linear scan register allocator v1.2 optimization + comprehensive scenario analysis.
Changes
Code (scratchv/backend/regalloc_linear.py):
Docs:
Benchmark Highlights (27 physical regs, 9 scenarios)