lower integer add-sub with immediates
This commit is contained in:
@@ -368,6 +368,34 @@ void LowerInstruction(const ir::Instruction& inst, MachineFunction& function,
|
|||||||
int dst_slot = function.CreateFrameIndex(4);
|
int dst_slot = function.CreateFrameIndex(4);
|
||||||
slots.emplace(&inst, dst_slot);
|
slots.emplace(&inst, dst_slot);
|
||||||
|
|
||||||
|
if (inst.GetOpcode() == ir::Opcode::Add) {
|
||||||
|
const ir::Value* variable = nullptr;
|
||||||
|
int constant = 0;
|
||||||
|
if (auto* lhs_const = dynamic_cast<const ir::ConstantInt*>(bin.GetLhs())) {
|
||||||
|
variable = bin.GetRhs();
|
||||||
|
constant = lhs_const->GetValue();
|
||||||
|
} else if (auto* rhs_const = dynamic_cast<const ir::ConstantInt*>(bin.GetRhs())) {
|
||||||
|
variable = bin.GetLhs();
|
||||||
|
constant = rhs_const->GetValue();
|
||||||
|
}
|
||||||
|
if (variable && constant >= -4095 && constant <= 4095) {
|
||||||
|
EmitValueToReg(variable, PhysReg::W8, slots, block);
|
||||||
|
block.Append(Opcode::AddRegImm, {Operand::Reg(PhysReg::W8), Operand::Reg(PhysReg::W8), Operand::Imm(constant)});
|
||||||
|
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W8), Operand::FrameIndex(dst_slot)});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (inst.GetOpcode() == ir::Opcode::Sub) {
|
||||||
|
if (auto* rhs_const = dynamic_cast<const ir::ConstantInt*>(bin.GetRhs())) {
|
||||||
|
int constant = rhs_const->GetValue();
|
||||||
|
if (constant >= -4095 && constant <= 4095) {
|
||||||
|
EmitValueToReg(bin.GetLhs(), PhysReg::W8, slots, block);
|
||||||
|
block.Append(Opcode::AddRegImm, {Operand::Reg(PhysReg::W8), Operand::Reg(PhysReg::W8), Operand::Imm(-constant)});
|
||||||
|
block.Append(Opcode::StoreStack, {Operand::Reg(PhysReg::W8), Operand::FrameIndex(dst_slot)});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (inst.GetOpcode() == ir::Opcode::Mul) {
|
if (inst.GetOpcode() == ir::Opcode::Mul) {
|
||||||
const ir::Value* variable = nullptr;
|
const ir::Value* variable = nullptr;
|
||||||
int constant = 0;
|
int constant = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user