diff --git a/IDEHelper/Backend/BeMCContext.cpp b/IDEHelper/Backend/BeMCContext.cpp index 54e08070..e03cc393 100644 --- a/IDEHelper/Backend/BeMCContext.cpp +++ b/IDEHelper/Backend/BeMCContext.cpp @@ -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 , 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()) diff --git a/IDEHelper/Backend/BeMCContext.h b/IDEHelper/Backend/BeMCContext.h index 01207590..f3d8952f 100644 --- a/IDEHelper/Backend/BeMCContext.h +++ b/IDEHelper/Backend/BeMCContext.h @@ -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