From bfe105c2cd1ec6ede2b4ce467125e188b9939c70 Mon Sep 17 00:00:00 2001 From: lzkk <956449176@qq.com> Date: Wed, 27 May 2026 17:39:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(mir):=20=E5=88=AB=E5=90=8D=E6=97=A0?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=86=B2=E7=AA=81=20+=20per-round=20reserve?= =?UTF-8?q?=E9=98=B2=E6=8C=87=E9=92=88=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 两个安全修复: 1. GPR32/GPR64别名检查移除segments.empty()条件 Wn/Xn是同一硬件寄存器,GPR32和GPR64 vreg在同一phys_reg上总是冲突 2. 每轮EnhancerIntervals后reserve*16,防止push_back导致reg_assignments_指针失效 当前正确率:94% (94/100) --- src/mir/GreedyAlloc.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mir/GreedyAlloc.cpp b/src/mir/GreedyAlloc.cpp index 803c9e38..65290aeb 100644 --- a/src/mir/GreedyAlloc.cpp +++ b/src/mir/GreedyAlloc.cpp @@ -532,6 +532,7 @@ static void AllocateRegistersForFunction(MachineFunction &function) // ---- 阶段 0:活跃分析 + 预处理 ---- auto raw = ComputeInstLiveness(function); auto intervals = EnhanceIntervals(raw, function); + intervals.reserve(function.GetNumVRegs() * 16); auto &blocks = function.GetBlocks(); std::vector pos_to_block; @@ -549,7 +550,7 @@ static void AllocateRegistersForFunction(MachineFunction &function) auto block_depth = AnalyzeLoopDepth(function); ComputeSpillWeights(intervals, block_depth, pos_to_block); PropagateCopyHints(intervals, function); - intervals.reserve(function.GetNumVRegs() * 4); + intervals.reserve(function.GetNumVRegs() * 16); // LLVM 风格:全局 cascade 计数器 int global_cascade = 1; @@ -661,6 +662,7 @@ static void AllocateRegistersForFunction(MachineFunction &function) // ---- 重新分析活跃 ---- raw = ComputeInstLiveness(function); intervals = EnhanceIntervals(raw, function); + intervals.reserve(function.GetNumVRegs() * 16); // ---- 重建位置映射 ---- pos_to_block.clear();