fix(mir): 回退到稳定版本——PhysReg映射+spill reload+别名无条件冲突

稳定在94%正确率。包含三个关键修复:
1. PhysReg映射修正: Ptr +31, Float +62, FP_ALLOCATABLE排除S0-S1
2. Spill reload为每次use创建新vreg
3. GPR32/GPR64别名无条件冲突

Mem2Reg交互问题(65_color, 94_nested_loops)已精确诊断为:
高寄存器压力→未分配vreg→共享回退寄存器X16→地址计算错误→SIGSEGV
完整修复需要LLVM SplitKit级别的活范围区域分裂。
lzk
lzkk 3 days ago
parent 0f1b545568
commit d6f42a2a2e

@ -52,10 +52,8 @@ struct SpillWeightCmp
const auto& lb = intervals[b];
if (la.generation != lb.generation)
return la.generation > lb.generation;
// 新 vreg 按 FirstUsePos 升序:确保处理顺序与指令顺序一致,
// 这样当 vreg B 被分配时,更早的 vreg A 已在 reg_assignments_ 中
if (la.deferred_count == 0 && lb.deferred_count == 0)
return la.FirstUsePos() > lb.FirstUsePos();
return la.Length() > lb.Length();
return la.spill_weight < lb.spill_weight;
}
};
@ -534,7 +532,6 @@ 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<int> pos_to_block;
@ -552,7 +549,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() * 16);
intervals.reserve(function.GetNumVRegs() * 4);
// LLVM 风格:全局 cascade 计数器
int global_cascade = 1;
@ -664,7 +661,6 @@ static void AllocateRegistersForFunction(MachineFunction &function)
// ---- 重新分析活跃 ----
raw = ComputeInstLiveness(function);
intervals = EnhanceIntervals(raw, function);
intervals.reserve(function.GetNumVRegs() * 16);
// ---- 重建位置映射 ----
pos_to_block.clear();

Loading…
Cancel
Save