From 9c6b745993c3811c9b534b59bd648ae52ae405a6 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 30 Nov 2022 22:47:13 +0100 Subject: [PATCH] Fix self destruct of load store forwarding dict --- oscar64/InterCode.cpp | 2 +- oscar64/NativeCodeGenerator.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 7bc1b9e..95760f5 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -8525,7 +8525,7 @@ bool InterCodeBasicBlock::LoadStoreForwarding(const GrowingInstructionPtrArray& } mLoadStoreInstructions.SetSize(k); - if (nins) + if (nins && t >= 0) { // Check self destruction of source operaand int l = 0; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 153d100..83d0e21 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -19370,6 +19370,7 @@ bool NativeCodeBasicBlock::BackwardReplaceZeroPage(int at, int from, int to, boo if (at == mIns.Size()) mExitRequiredRegs += to; + bool done = false; while (at > 0) { at--; @@ -19378,7 +19379,10 @@ bool NativeCodeBasicBlock::BackwardReplaceZeroPage(int at, int from, int to, boo mIns[at].mAddress = to; changed = true; if (mIns[at].mType == ASMIT_STA || mIns[at].mType == ASMIT_STX || mIns[at].mType == ASMIT_STY) + { + done = true; break; + } } } @@ -19402,7 +19406,7 @@ bool NativeCodeBasicBlock::BackwardReplaceZeroPage(int at, int from, int to, boo if (mEntryBlocks[0]->BackwardReplaceZeroPage(mEntryBlocks[0]->mIns.Size(), from, to, false)) changed = true; } - else if (at == 0) + else if (!done) { if (mEntryBlocks.Size() == 1) { @@ -28524,6 +28528,25 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass progress = true; } #endif +#if 1 + else if ( + mIns[i + 0].mType == ASMIT_STA && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && !(mIns[i + 0].mLive & LIVE_CPU_REG_A) && + !mIns[i + 1].ReferencesZeroPage(mIns[i + 0].mAddress) && !mIns[i + 1].ChangesCarry() && + !mIns[i + 2].ReferencesZeroPage(mIns[i + 0].mAddress) && !mIns[i + 2].ChangesCarry() && + mIns[i + 3].IsShift() && mIns[i + 3].SameEffectiveAddress(mIns[i + 0])) + { + AsmInsType type = mIns[i + 3].mType; + mIns[i + 3] = mIns[i + 2]; + mIns[i + 2] = mIns[i + 1]; + mIns[i + 1] = mIns[i + 0]; + mIns[i + 0] = NativeCodeInstruction(type); + mIns[i + 1].mLive |= LIVE_CPU_REG_C; + mIns[i + 2].mLive |= LIVE_CPU_REG_C; + mIns[i + 3].mLive |= LIVE_CPU_REG_C; + + progress = true; + } +#endif else if ( mIns[i + 0].ChangesAccuAndFlag() && mIns[i + 1].mType == ASMIT_STA &&