From 1e3d0308bf75b6139987939c18d0c6f67ea11599 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 13 Oct 2021 12:07:51 -0700 Subject: [PATCH] Fixed an errorVReg relto issue --- IDEHelper/Backend/BeMCContext.cpp | 36 +++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/IDEHelper/Backend/BeMCContext.cpp b/IDEHelper/Backend/BeMCContext.cpp index 04cbfabb..c209606d 100644 --- a/IDEHelper/Backend/BeMCContext.cpp +++ b/IDEHelper/Backend/BeMCContext.cpp @@ -9626,13 +9626,15 @@ bool BeMCContext::DoLegalization() } else { - // This may be a local variable that failed to be assigned to a reg, create a scratch local with a forced reg - auto scratchReg = AllocVirtualReg(errorVRegInfo->mType, 2, false); - auto scratchVRegInfo = mVRegInfo[scratchReg.mVRegIdx]; + // This may be a local variable that failed to be assigned to a reg, create a scratch local with a forced reg auto errorVReg = BeMCOperand::FromVReg(rmInfo.mErrorVReg); + auto errorVRegLoad = BeMCOperand::ToLoad(errorVReg); if ((vregInfo->mRelTo == errorVReg) || (vregInfo->mRelOffset == errorVReg)) { + auto scratchReg = AllocVirtualReg(errorVRegInfo->mType, 2, false); + auto scratchVRegInfo = mVRegInfo[scratchReg.mVRegIdx]; + CreateDefineVReg(scratchReg, instIdx++); AllocInst(BeMCInstKind_Mov, scratchReg, errorVReg, instIdx++); isFinalRun = false; @@ -9653,6 +9655,32 @@ bool BeMCContext::DoLegalization() vregInfo->mRelOffset.mVRegIdx = scratchReg.mVRegIdx; } } + else if ((vregInfo->mRelTo == errorVRegLoad) || (vregInfo->mRelOffset == errorVRegLoad)) + { + auto scratchType = GetType(errorVRegLoad); + auto scratchReg = AllocVirtualReg(scratchType, 2, false); + auto scratchVRegInfo = mVRegInfo[scratchReg.mVRegIdx]; + + CreateDefineVReg(scratchReg, instIdx++); + AllocInst(BeMCInstKind_Mov, scratchReg, errorVRegLoad, instIdx++); + isFinalRun = false; + if (debugging) + OutputDebugStrF(" RM failed, scratch vreg\n"); + vregExprChangeSet.Add(scratchReg.mVRegIdx); + + if (vregInfo->mRelTo == errorVRegLoad) + { + scratchVRegInfo->mForceReg = true; + CheckForce(scratchVRegInfo); + vregInfo->mRelTo = scratchReg; + } + else if (vregInfo->mRelOffset == errorVRegLoad) + { + scratchVRegInfo->mForceReg = true; + CheckForce(scratchVRegInfo); + vregInfo->mRelOffset = scratchReg; + } + } else { // This should be impossible - a previous def for an inner expr should have caught this case @@ -15906,7 +15934,7 @@ void BeMCContext::Generate(BeFunction* function) mDbgPreferredRegs[32] = X64Reg_R8;*/ //mDbgPreferredRegs[8] = X64Reg_RAX; - //mDebugging = (function->mName == "?DrawCard@Stats@NecroCard@bf@@QEAAX_N@Z"); + mDebugging = (function->mName == "?PopulateComboBox$ny@PropertyPanel@Editor@Cobalt@bf@@QEAAXPEAVMenu@widgets@Beefy@4@@Z"); // || (function->mName == "?MethodA@TestProgram@BeefTest@bf@@CAXXZ"); // || (function->mName == "?Hey@Blurg@bf@@SAXXZ") // ;