fix(mir)修改临时寄存器使用

feature/mir
mxr 1 week ago
parent cc41bb60ae
commit 70234dde70

@ -154,16 +154,16 @@ void EmitValueToReg(const ir::Value* value, PhysReg target,
slot = function.CreateFrameIndex(4);
// 将 imm 写入栈槽(与 ConstantFloat 相同方式)
if (isLegalMovImm(imm)) {
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W8), Operand::Imm(static_cast<int64_t>(imm))});
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W10), Operand::Imm(static_cast<int64_t>(imm))});
} else {
uint16_t low = imm & 0xFFFF;
uint16_t high = (imm >> 16) & 0xFFFF;
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W8), Operand::Imm(low)});
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W10), Operand::Imm(low)});
if (high != 0) {
block.Append(Opcode::Movk, {Operand::Reg(PhysReg::W8), Operand::Imm(high), Operand::Imm(16)});
block.Append(Opcode::Movk, {Operand::Reg(PhysReg::W10), Operand::Imm(high), Operand::Imm(16)});
}
}
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W8), Operand::FrameIndex(slot)});
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W10), Operand::FrameIndex(slot)});
const_cast<ValueSlotMap&>(slots).emplace(value, slot);
} else {
slot = it->second;
@ -209,16 +209,16 @@ void EmitValueToReg(const ir::Value* value, PhysReg target,
// 同样需要对 int_val 进行大立即数分解
if (isLegalMovImm(int_val)) {
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W8), Operand::Imm(static_cast<int64_t>(int_val))});
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W10), Operand::Imm(static_cast<int64_t>(int_val))});
} else {
uint16_t low = int_val & 0xFFFF;
uint16_t high = (int_val >> 16) & 0xFFFF;
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W8), Operand::Imm(low)});
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W10), Operand::Imm(low)});
if (high != 0) {
block.Append(Opcode::Movk, {Operand::Reg(PhysReg::W8), Operand::Imm(high), Operand::Imm(16)});
block.Append(Opcode::Movk, {Operand::Reg(PhysReg::W10), Operand::Imm(high), Operand::Imm(16)});
}
}
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W8), Operand::FrameIndex(slot)});
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W10), Operand::FrameIndex(slot)});
const_cast<ValueSlotMap&>(slots).emplace(value, slot);
} else {
slot = it->second;
@ -239,8 +239,8 @@ void EmitValueToReg(const ir::Value* value, PhysReg target,
if (it == slots.end()) {
slot = function.CreateFrameIndex(4);
// 写入 0
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W8), Operand::Imm(0)});
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W8), Operand::FrameIndex(slot)});
block.Append(Opcode::MovImm, {Operand::Reg(PhysReg::W10), Operand::Imm(0)});
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W10), Operand::FrameIndex(slot)});
const_cast<ValueSlotMap&>(slots).emplace(value, slot);
} else {
slot = it->second;
@ -768,8 +768,13 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function,
std::string end_label = ".L_fcset_end_" + std::to_string(reinterpret_cast<uintptr_t>(&fcmp));
// 5. 处理 NaN 情况
block.Append(Opcode::BCond, {Operand::Cond(CondCode::VS), Operand::Label(end_label)});
if (isOrdered) {
// 有序比较:如果无序 (V=1) → 直接结束(结果为 0
block.Append(Opcode::BCond, {Operand::Cond(CondCode::VS), Operand::Label(end_label)});
} else {
// 无序比较:如果无序 (V=1) → 结果置 1
block.Append(Opcode::BCond, {Operand::Cond(CondCode::VS), Operand::Label(set1_label)});
}
// 6. 正常条件跳转
block.Append(Opcode::BCond, {Operand::Cond(cc), Operand::Label(set1_label)});

Loading…
Cancel
Save