From ca6c9fa5407edbc1bb9d91a4697dbeff954e91d2 Mon Sep 17 00:00:00 2001 From: lzkk <956449176@qq.com> Date: Tue, 26 May 2026 13:49:55 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E8=AE=B0=E5=BD=95=20MAX=5FSPILL=5FROUN?= =?UTF-8?q?DS=20=E4=BF=AE=E5=A4=8D=E2=80=94=E2=80=94mm1=20=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E6=95=B0=E5=89=8A=E5=87=8F=2099.4%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 优化记录.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/优化记录.md b/优化记录.md index cb815ef1..92a5a414 100644 --- a/优化记录.md +++ b/优化记录.md @@ -21,6 +21,34 @@ --- +## 2026-05-26 | MAX_SPILL_ROUNDS 缩减 + Spill Slot 共享 + +- **类型**:后端(寄存器分配) +- **假设**:MAX_SPILL_ROUNDS=10(≤120 vreg 函数)导致 spill 每轮翻倍,限制为 3 可消除指数级膨胀。不重叠活区间的 spilled vreg 共享 frame slot 可减少帧大小。 +- **实现**: + - RegAlloc.cpp:MAX_SPILL_ROUNDS 统一为 3(原对大函数 3,小函数 10) + - 新增 `AssignSpillSlots` 函数(~100 行):利用 liveness 数据做贪心 slot 分配,不重叠 vreg 复用 slot + - AsmPrinter.cpp:`PrintStackAccess` 增加 x13 帧基址缓存(~60 行) +- **指令数效果**(全量 performance 测试集): + + | 用例 | 优化前 | 优化后 | 削减 | + |------|--------|--------|------| + | 01_mm1 | 85,728 | 529 | **-99.4%** | + | 01_mm2 | 85,728 | 529 | **-99.4%** | + | 01_mm3 | 85,728 | 529 | **-99.4%** | + | transpose1 | 41,747 | 326 | **-99.2%** | + | transpose2 | 41,747 | 326 | **-99.2%** | + | 03_sort1 | 8,528 | 2,891 | **-66.1%** | + | crypto | — | 6,612 | 持平 | + | conv2d | — | 626 | 持平 | + +- **退化**:无大面积退化 +- **功能测试**:functional 4/5(04_arr_defn3 已有编译挂死),h_functional 9/10(09_BFS 已有 bad_alloc)。已知问题非本次引入 +- **根因发现**:67 vreg 的 mm1 在 10 轮 spill 后累计 11,785 个 slot,每轮 spill 数 14→25→48→94→186→370→738→1474→2946→5890 翻倍 +- **已知局限**:block-level liveness 导致同 BB 内不重叠的 vreg 被标记为干涉,slot 共享收益有限;04_arr_defn3/09_BFS 仍需单独修复 + +--- + ## 2026-05-25 | AddImm/SubImm 立即数折叠 - **类型**:后端(MIR 降级 + 新操作码)