1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Fixed immediate cmp reorder, offsetted immediate load

This commit is contained in:
Brian Fiete 2024-12-18 06:09:31 -08:00
parent 40d6195db7
commit 5bf50d658c
2 changed files with 22 additions and 1 deletions

View file

@ -2878,6 +2878,14 @@ BeMCOperand BeMCContext::CreateLoad(const BeMCOperand& mcTarget)
return CreateLoad(fakePtr);
}
if (HasImmediateTarget(mcTarget))
{
BeMCOperand scratchReg = AllocVirtualReg(GetType(mcTarget), 2);
CreateDefineVReg(scratchReg);
AllocInst(BeMCInstKind_Mov, scratchReg, mcTarget);
return CreateLoad(scratchReg);
}
BeMCOperand result;
auto loadedTarget = BeMCOperand::ToLoad(mcTarget);
@ -6026,6 +6034,18 @@ void BeMCContext::GetRMParams(const BeMCOperand& operand, BeRMParamsInfo& rmInfo
}
}
bool BeMCContext::HasImmediateTarget(const BeMCOperand& operand)
{
if (operand.IsImmediate())
return true;
auto vregInfo = GetVRegInfo(operand);
if (vregInfo == NULL)
return false;
if (vregInfo->mRelTo)
return HasImmediateTarget(vregInfo->mRelTo);
return false;
}
void BeMCContext::DisableRegister(const BeMCOperand& operand, X64CPURegister reg)
{
auto vregInfo = GetVRegInfo(operand);
@ -10436,7 +10456,7 @@ bool BeMCContext::DoLegalization()
bool needSwap = false;
// Cmp <imm>, <r/m> is not legal, so we need to swap LHS/RHS, which means also modifying the instruction that uses the result of the cmp
if (inst->mArg0.IsImmediate())
if (arg0.IsImmediate())
needSwap = true;
if (arg0Type->IsFloat())

View file

@ -1446,6 +1446,7 @@ public:
int GetRegSize(int regNum);
void ValidateRMResult(const BeMCOperand& operand, BeRMParamsInfo& rmInfo, bool doValidate = true);
void GetRMParams(const BeMCOperand& operand, BeRMParamsInfo& rmInfo, bool doValidate = true);
bool HasImmediateTarget(const BeMCOperand& operand);
void DisableRegister(const BeMCOperand& operand, X64CPURegister reg);
void MarkInvalidRMRegs(const BeMCOperand& operand);
void GetUsedRegs(const BeMCOperand& operand, X64CPURegister& regA, X64CPURegister& regB); // Expands regs