From 7dddcc772b12f6c6763633e18e062b1f84f0123c Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 8 Nov 2021 20:18:40 +0100 Subject: [PATCH] Some peephole optimizing for native compiler --- oscar64/NativeCodeGenerator.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index a8bec09..3da1d6b 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -10016,6 +10016,21 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(int pass) mIns[i + 0].mType = ASMIT_SEC; progress = true; } + else if ( + mIns[i + 0].mType == ASMIT_CLC && + mIns[i + 1].mType == ASMIT_TYA && + mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress <= 2 && !(mIns[i + 2].mLive & (LIVE_CPU_REG_C | LIVE_CPU_REG_Y))) + { + int t = mIns[i + 2].mAddress; + mIns[i + 0].mType = ASMIT_INY; + if (t > 1) + mIns[i + 1].mType = ASMIT_INY; + else + mIns[i + 1].mType = ASMIT_NOP; + mIns[i + 1].mLive |= LIVE_CPU_REG_Y; + mIns[i + 2].mType = ASMIT_TYA; mIns[i + 2].mMode = ASMIM_IMPLIED; + progress = true; + } #if 1 else if ( @@ -10211,6 +10226,21 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(int pass) mIns[i + 3].mType = ASMIT_ROL; progress = true; } + else if ( + mIns[i + 0].mType == ASMIT_LDA && + mIns[i + 1].mType == ASMIT_STA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && + mIns[i + 3].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mAddress && mIns[i + 3].mAddress && + mIns[i + 2].mMode == ASMIM_IMPLIED && !(mIns[i + 3].mLive & LIVE_MEM) && + (mIns[i + 2].mType == ASMIT_ASL || mIns[i + 2].mType == ASMIT_LSR || mIns[i + 2].mType == ASMIT_ROL || mIns[i + 2].mType == ASMIT_ROR) && + (mIns[i + 3].mType == ASMIT_ORA || mIns[i + 3].mType == ASMIT_AND || mIns[i + 3].mType == ASMIT_EOR || mIns[i + 3].mType == ASMIT_ADC || mIns[i + 3].mType == ASMIT_SBC)) + { + mIns[i + 1].mType = ASMIT_NOP; + mIns[i + 3].mMode = mIns[i + 0].mMode; + mIns[i + 3].mAddress= mIns[i + 0].mAddress; + mIns[i + 3].mLinkerObject = mIns[i + 0].mLinkerObject; + mIns[i + 3].mFlags = mIns[i + 0].mFlags; + progress = true; + } #if 0 if ( mIns[i + 0].mType == ASMIT_LDY && mIns[i + 0].mMode == ASMIM_IMMEDIATE && mIns[i + 0].mAddress == 0 &&