Fix over eager function parameter optimiztion

This commit is contained in:
drmortalwombat 2023-06-16 15:21:30 +02:00
parent c300f6c364
commit 0f182d2d6d
8 changed files with 72 additions and 11 deletions

View File

@ -714,6 +714,11 @@ Declaration* Declaration::ToStriped(int stripe)
p = p->mNext; p = p->mNext;
} }
} }
else if (mType == DT_TYPE_ARRAY)
{
ndec->mStride = stripe;
ndec->mBase = mBase->ToStriped(stripe);
}
else else
{ {
ndec->mScope = mScope; ndec->mScope = mScope;
@ -904,6 +909,26 @@ bool Declaration::IsSame(const Declaration* dec) const
return false; return false;
} }
bool Declaration::IsSameValue(const Declaration* dec) const
{
if (mType != dec->mType || mSize != dec->mSize)
return false;
switch (mType)
{
case DT_CONST_INTEGER:
return mInteger == dec->mInteger;
case DT_CONST_FLOAT:
return mNumber == dec->mNumber;
case DT_CONST_ADDRESS:
return mInteger == dec->mInteger;
case DT_CONST_POINTER:
return mValue && dec->mValue && mValue->mType == dec->mValue->mType && mValue->mDecValue == dec->mValue->mDecValue;
}
return false;
}
bool Declaration::CanAssign(const Declaration* fromType) const bool Declaration::CanAssign(const Declaration* fromType) const
{ {
if (this->IsSame(fromType)) if (this->IsSame(fromType))

View File

@ -211,6 +211,7 @@ public:
bool IsSame(const Declaration* dec) const; bool IsSame(const Declaration* dec) const;
bool IsSubType(const Declaration* dec) const; bool IsSubType(const Declaration* dec) const;
bool IsConstSame(const Declaration* dec) const; bool IsConstSame(const Declaration* dec) const;
bool IsSameValue(const Declaration* dec) const;
bool IsIntegerType(void) const; bool IsIntegerType(void) const;
bool IsNumericType(void) const; bool IsNumericType(void) const;

View File

@ -682,7 +682,7 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo
{ {
if (pdec->mFlags & DTF_FPARAM_CONST) if (pdec->mFlags & DTF_FPARAM_CONST)
{ {
if (!pex->mDecValue->IsSame(pdec->mValue->mDecValue)) if (!pex->mDecValue->IsSameValue(pdec->mValue->mDecValue))
{ {
pdec->mFlags |= DTF_FPARAM_NOCONST; pdec->mFlags |= DTF_FPARAM_NOCONST;
pdec->mFlags &= ~DTF_FPARAM_CONST; pdec->mFlags &= ~DTF_FPARAM_CONST;

View File

@ -1556,7 +1556,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (vl.mType->mFlags & DTF_DEFINED) if (vl.mType->mFlags & DTF_DEFINED)
{ {
int64 index = exp->mRight->mDecValue->mInteger; int64 index = exp->mRight->mDecValue->mInteger;
if (index < 0 || index * stride >= vl.mType->mSize) if (index < 0 || index * stride >= vl.mType->mSize * vl.mType->mStripe)
mErrors->Error(exp->mLocation, EWARN_INDEX_OUT_OF_BOUNDS, "Constant array index out of bounds"); mErrors->Error(exp->mLocation, EWARN_INDEX_OUT_OF_BOUNDS, "Constant array index out of bounds");
} }
} }

View File

@ -37441,7 +37441,6 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 4].mType = ASMIT_NOP; mIns[i + 4].mMode = ASMIM_IMPLIED; mIns[i + 4].mType = ASMIT_NOP; mIns[i + 4].mMode = ASMIM_IMPLIED;
progress = true; progress = true;
} }
#endif #endif
} }
#endif #endif
@ -37490,6 +37489,42 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 3].mType = ASMIT_NOP; mIns[i + 3].mType = ASMIT_NOP;
progress = true; progress = true;
} }
else if (pass > 8 &&
mIns[i + 0].mType == ASMIT_TYA &&
mIns[i + 1].mType == ASMIT_CLC &&
mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && (mIns[i + 2].mAddress & 0xff) < 4 &&
mIns[i + 3].mType == ASMIT_TAY &&
!(mIns[i + 3].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C)))
{
int n = mIns[i + 2].mAddress & 0xff;
for (int k = 0; k < n; k++)
{
mIns[i + k].mType = ASMIT_INY; mIns[i + k].mMode = ASMIM_IMPLIED; mIns[i + k].mLive |= LIVE_CPU_REG_Y;
}
for (int k = n; k < 4; k++)
{
mIns[i + k].mType = ASMIT_NOP; mIns[i + k].mMode = ASMIM_IMPLIED;
}
progress = true;
}
else if (pass > 8 &&
mIns[i + 0].mType == ASMIT_TXA &&
mIns[i + 1].mType == ASMIT_CLC &&
mIns[i + 2].mType == ASMIT_ADC && mIns[i + 2].mMode == ASMIM_IMMEDIATE && (mIns[i + 2].mAddress & 0xff) < 4 &&
mIns[i + 3].mType == ASMIT_TAX &&
!(mIns[i + 3].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C)))
{
int n = mIns[i + 2].mAddress & 0xff;
for (int k = 0; k < n; k++)
{
mIns[i + k].mType = ASMIT_INX; mIns[i + k].mMode = ASMIM_IMPLIED; mIns[i + k].mLive |= LIVE_CPU_REG_X;
}
for (int k = n; k < 4; k++)
{
mIns[i + k].mType = ASMIT_NOP; mIns[i + k].mMode = ASMIM_IMPLIED;
}
progress = true;
}
} }
CheckLive(); CheckLive();

View File

@ -74,7 +74,7 @@ int main2(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.20.206"); strcpy(strProductVersion, "1.20.207");
#ifdef __APPLE__ #ifdef __APPLE__
uint32_t length = sizeof(basePath); uint32_t length = sizeof(basePath);

View File

@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,20,206,0 FILEVERSION 1,20,207,0
PRODUCTVERSION 1,20,206,0 PRODUCTVERSION 1,20,207,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -43,12 +43,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "oscar64" VALUE "CompanyName", "oscar64"
VALUE "FileDescription", "oscar64 compiler" VALUE "FileDescription", "oscar64 compiler"
VALUE "FileVersion", "1.20.206.0" VALUE "FileVersion", "1.20.207.0"
VALUE "InternalName", "oscar64.exe" VALUE "InternalName", "oscar64.exe"
VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "LegalCopyright", "Copyright (C) 2021"
VALUE "OriginalFilename", "oscar64.exe" VALUE "OriginalFilename", "oscar64.exe"
VALUE "ProductName", "oscar64" VALUE "ProductName", "oscar64"
VALUE "ProductVersion", "1.20.206.0" VALUE "ProductVersion", "1.20.207.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -5233,15 +5233,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{238E4EBC-D891-4E22-9F93-39D885860A68}" "ProductCode" = "8:{FEED3AD1-30EE-4FD2-954E-A54FFC19B2ED}"
"PackageCode" = "8:{2D672B29-2FA7-4586-B7DB-C19817A075E8}" "PackageCode" = "8:{88265E1D-B2B8-4C78-A582-11E0B0CF7FB7}"
"UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}"
"AspNetVersion" = "8:2.0.50727.0" "AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE" "RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE" "RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE" "InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.20.206" "ProductVersion" = "8:1.20.207"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"