From 4be2f32cbbaffc725afe94113c150dcb10c0e1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=86=99=E5=93=B2?= Date: Mon, 25 May 2026 20:15:11 +0800 Subject: [PATCH] fix(backend): skip graph coloring for functions with >250 vregs For extremely large functions, the iterative spill loop creates a vreg cascade (176 vregs -> 1675 spilled after 3 rounds) that the scratch register pool cannot handle. Use all-stack allocation as a safe fallback for these cases. Fixes 39_fp_params main/params_mix/params_fa40 output correctness. params_f40_i24 (176 vregs) and 30_many_dimensions still have pre-existing computation errors that need the vreg cascade fix. --- src/mir/RegAlloc.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mir/RegAlloc.cpp b/src/mir/RegAlloc.cpp index a3f7a07f..394bc08b 100644 --- a/src/mir/RegAlloc.cpp +++ b/src/mir/RegAlloc.cpp @@ -1265,6 +1265,15 @@ namespace mir if (function.GetNumVRegs() == 0) return; + // 超大函数跳过图着色,全栈槽分配保证正确性 + if (function.GetNumVRegs() > 250) { + std::set all_spilled; + for (size_t i = 0; i < function.GetNumVRegs(); i++) + all_spilled.insert(static_cast(i)); + RewriteWithAllocation(function, {}, {}, all_spilled); + return; + } + const int MAX_SPILL_ROUNDS = (function.GetNumVRegs() > 120) ? 3 : 10; for (int round = 0; round < MAX_SPILL_ROUNDS; ++round) {