From 34cb79449f58965e77766096cff570be8a3d9c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=86=99=E5=93=B2?= Date: Sun, 24 May 2026 16:37:18 +0800 Subject: [PATCH] fix(backend): skip coalescing for large functions to prevent segfault\n\nFor functions with >150 vregs, discard move_preferences after\ncollection to skip active coalescing. Large functions like\nconv2d, 65_color, 68_brainfk have complex interference graphs\nthat cause coalescing to generate incorrect spill code.\n\nFixes segfaults in: conv2d-1/2/3, 65_color, 68_brainfk, 37_dct.\n\nKnown limitations: 30_many_dimensions and 39_fp_params still\nsegfault (pre-existing original compiler bugs in lowering/RA).\nMinor instruction count changes: h-8 +2.5%, matmul +7% etc. --- src/mir/RegAlloc.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mir/RegAlloc.cpp b/src/mir/RegAlloc.cpp index a8d6cd60..394106c5 100644 --- a/src/mir/RegAlloc.cpp +++ b/src/mir/RegAlloc.cpp @@ -1431,6 +1431,10 @@ namespace mir } } + // 大函数丢弃 move 偏好以保持分配稳定性 + if (function.GetNumVRegs() > 150) + move_preferences.clear(); + std::vector gp_alloc(GP_ALLOCATABLE, GP_ALLOCATABLE + GP_NUM_ALLOCATABLE); std::vector fp_alloc(FP_ALLOCATABLE, FP_ALLOCATABLE + FP_NUM_ALLOCATABLE); @@ -1719,6 +1723,9 @@ namespace mir } } + if (function.GetNumVRegs() > 150) + move_preferences.clear(); + std::vector gp_alloc(GP_ALLOCATABLE, GP_ALLOCATABLE + GP_NUM_ALLOCATABLE); std::vector fp_alloc(FP_ALLOCATABLE, FP_ALLOCATABLE + FP_NUM_ALLOCATABLE); InterferenceGraph gp_graph, fp_graph;