Fix join entry loadstore zp if accu is used cross block

This commit is contained in:
drmortalwombat 2023-11-16 21:52:06 +01:00
parent 157f9c00e5
commit 38e1cd0bab

View File

@ -20235,6 +20235,8 @@ bool NativeCodeBasicBlock::JoinEntryLoadStoreZP(void)
CheckLive(); CheckLive();
if (!mEntryRequiredRegs[CPU_REG_A] || !mEntryRequiredRegs[CPU_REG_X])
{
for (int i = 0; i + 1 < mIns.Size(); i++) for (int i = 0; i + 1 < mIns.Size(); i++)
{ {
if (mIns[i].mType == ASMIT_LDA && mIns[i].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mType == ASMIT_STA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & LIVE_MEM) && !(mIns[i + 1].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z)) || if (mIns[i].mType == ASMIT_LDA && mIns[i].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mType == ASMIT_STA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && !(mIns[i].mLive & LIVE_MEM) && !(mIns[i + 1].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_Z)) ||
@ -20293,8 +20295,16 @@ bool NativeCodeBasicBlock::JoinEntryLoadStoreZP(void)
xblock->mExitRequiredRegs = mEntryRequiredRegs; xblock->mExitRequiredRegs = mEntryRequiredRegs;
xblock->mExitRequiredRegs += daddr; xblock->mExitRequiredRegs += daddr;
xblock->mIns.Push(mIns[i + 0]); if (!mEntryRequiredRegs[CPU_REG_A])
xblock->mIns.Push(mIns[i + 1]); {
xblock->mIns.Push(NativeCodeInstruction(mIns[i + 0].mIns, ASMIT_LDA, ASMIM_ZERO_PAGE, mIns[i + 0].mAddress));
xblock->mIns.Push(NativeCodeInstruction(mIns[i + 1].mIns, ASMIT_STA, ASMIM_ZERO_PAGE, mIns[i + 1].mAddress));
}
else
{
xblock->mIns.Push(NativeCodeInstruction(mIns[i + 0].mIns, ASMIT_LDX, ASMIM_ZERO_PAGE, mIns[i + 0].mAddress));
xblock->mIns.Push(NativeCodeInstruction(mIns[i + 1].mIns, ASMIT_STX, ASMIM_ZERO_PAGE, mIns[i + 1].mAddress));
}
xblock->Close(mIns[i].mIns, this, nullptr, ASMIT_JMP); xblock->Close(mIns[i].mIns, this, nullptr, ASMIT_JMP);
mEntryBlocks.Push(xblock); mEntryBlocks.Push(xblock);
@ -20308,6 +20318,7 @@ bool NativeCodeBasicBlock::JoinEntryLoadStoreZP(void)
} }
} }
} }
}
if (mTrueJump && mTrueJump->JoinEntryLoadStoreZP()) if (mTrueJump && mTrueJump->JoinEntryLoadStoreZP())
changed = true; changed = true;
@ -42715,7 +42726,7 @@ void NativeCodeProcedure::Compile(InterCodeProcedure* proc)
{ {
mInterProc = proc; mInterProc = proc;
CheckFunc = !strcmp(mInterProc->mIdent->mString, "parse_statement"); CheckFunc = !strcmp(mInterProc->mIdent->mString, "interpret_builtin");
int nblocks = proc->mBlocks.Size(); int nblocks = proc->mBlocks.Size();
tblocks = new NativeCodeBasicBlock * [nblocks]; tblocks = new NativeCodeBasicBlock * [nblocks];
@ -43623,7 +43634,6 @@ void NativeCodeProcedure::Optimize(void)
changed = true; changed = true;
} }
#endif #endif
#if _DEBUG #if _DEBUG
ResetVisited(); ResetVisited();
mEntryBlock->CheckBlocks(true); mEntryBlock->CheckBlocks(true);
@ -43651,19 +43661,20 @@ void NativeCodeProcedure::Optimize(void)
changed = true; changed = true;
} }
if (step > 6) if (step > 6)
{ {
ResetVisited(); ResetVisited();
if (mEntryBlock->JoinEntryLoadStoreZP()) if (mEntryBlock->JoinEntryLoadStoreZP())
changed = true; changed = true;
} }
#endif #endif
#if _DEBUG #if _DEBUG
ResetVisited(); ResetVisited();
mEntryBlock->CheckBlocks(true); mEntryBlock->CheckBlocks(true);
#endif #endif
#if 1 #if 1
if (step == 3 || step == 4) if (step == 3 || step == 4)
{ {
@ -43731,6 +43742,7 @@ void NativeCodeProcedure::Optimize(void)
changed = true; changed = true;
} }
#if 1 #if 1
if (step == 5 || step == 6) if (step == 5 || step == 6)
{ {