From 05a6d16ddeb68dc343a32ef901746bad52461c1d Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 19 May 2025 17:23:28 +0200 Subject: [PATCH] Some cascading store optimization --- autotest/autotest.bat | 2 +- oscar64/Declaration.cpp | 18 +++++++++++------- oscar64/Ident.cpp | 6 +++--- oscar64/InterCode.cpp | 20 +++++++++++++++++++- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/autotest/autotest.bat b/autotest/autotest.bat index 7b49322..0bdb9db 100644 --- a/autotest/autotest.bat +++ b/autotest/autotest.bat @@ -39,7 +39,7 @@ rem @echo off @call :testh opp_list.cpp @if %errorlevel% neq 0 goto :error -@call :testh opp_functional.cpp +@call :testn opp_functional.cpp @if %errorlevel% neq 0 goto :error @call :testh operatoroverload.cpp diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index e2bbefe..76c2bec 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -1610,8 +1610,9 @@ const Ident* Declaration::FullIdent(void) Declaration* dec = mBase->mParams; while (dec) { - if (dec->mBase->mIdent) - tident = tident->Mangle(dec->mBase->MangleIdent()->mString); + const Ident* mident = dec->mBase->MangleIdent(); + if (mident) + tident = tident->Mangle(mident->mString); dec = dec->mNext; if (dec) tident = tident->Mangle(","); @@ -1747,7 +1748,7 @@ const Ident* Declaration::MangleIdent(void) } dec = dec->mNext; - if (dec) + if (mMangleIdent && dec) mMangleIdent = mMangleIdent->Mangle(","); } } @@ -1764,10 +1765,13 @@ const Ident* Declaration::MangleIdent(void) } - if (mFlags & DTF_CONST) - mMangleIdent = mMangleIdent->PreMangle("const "); - if (mFlags & DTF_VOLATILE) - mMangleIdent = mMangleIdent->PreMangle("volatile "); + if (mMangleIdent) + { + if (mFlags & DTF_CONST) + mMangleIdent = mMangleIdent->PreMangle("const "); + if (mFlags & DTF_VOLATILE) + mMangleIdent = mMangleIdent->PreMangle("volatile "); + } } return mMangleIdent; diff --git a/oscar64/Ident.cpp b/oscar64/Ident.cpp index 5fd117d..4f03633 100644 --- a/oscar64/Ident.cpp +++ b/oscar64/Ident.cpp @@ -47,7 +47,7 @@ const Ident* Ident::Unique(const char* str) const Ident* Ident::PreMangle(const char* str) const { - char buffer[200]; + char buffer[1000]; strcpy_s(buffer, str); strcat_s(buffer, mString); return Unique(buffer); @@ -55,14 +55,14 @@ const Ident* Ident::PreMangle(const char* str) const const Ident* Ident::Unique(const char* str, int id) { - char buffer[200]; + char buffer[1000]; sprintf_s(buffer, "%s#%d", str, id); return Unique(buffer); } const Ident* Ident::Mangle(const char* str) const { - char buffer[200]; + char buffer[1000]; strcpy_s(buffer, mString); strcat_s(buffer, str); return Unique(buffer); diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 93a954c..9fd1a5f 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -20738,6 +20738,24 @@ bool InterCodeBasicBlock::PeepholeReplaceOptimization(const GrowingVariableArray changed = true; } + if (i + 3 < mInstructions.Size() && + mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 0]->mOperator == IA_ADD && mInstructions[i + 0]->mSrc[0].mTemp < 0 && + mInstructions[i + 0]->mDst.IsUByte() && mInstructions[i + 0]->mSrc[1].IsUByte() && + mInstructions[i + 1]->mCode == IC_CONVERSION_OPERATOR && mInstructions[i + 1]->mOperator == IA_EXT8TO16U && + mInstructions[i + 1]->mSrc[0].mTemp == mInstructions[i + 0]->mDst.mTemp && mInstructions[i + 1]->mSrc[0].mFinal && + mInstructions[i + 2]->mCode == IC_LEA && mInstructions[i + 2]->mSrc[1].mTemp >= 0 && + mInstructions[i + 2]->mSrc[0].mTemp == mInstructions[i + 1]->mDst.mTemp && mInstructions[i + 2]->mSrc[0].mFinal && + mInstructions[i + 3]->mCode == IC_STORE && + mInstructions[i + 3]->mSrc[1].mTemp == mInstructions[i + 2]->mDst.mTemp && mInstructions[i + 3]->mSrc[1].mFinal) + { + mInstructions[i + 3]->mSrc[1].mIntConst += mInstructions[i + 0]->mSrc[0].mIntConst; + mInstructions[i + 1]->mSrc[0] = mInstructions[i + 0]->mSrc[1]; + mInstructions[i + 1]->mDst.mRange = mInstructions[i + 0]->mSrc[1].mRange; + mInstructions[i + 2]->mSrc[0].mRange = mInstructions[i + 0]->mSrc[1].mRange; + changed = true; + } + + if (i + 3 < mInstructions.Size() && mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 0]->mOperator == IA_SHR && mInstructions[i + 0]->mSrc[0].mTemp < 0 && @@ -23581,7 +23599,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "main"); + CheckFunc = !strcmp(mIdent->mString, "fill"); CheckCase = false; mEntryBlock = mBlocks[0];