More multi path constant folding

This commit is contained in:
drmortalwombat 2022-08-14 17:52:58 +02:00
parent 3d23e7f0b1
commit 65fc43c123
6 changed files with 95 additions and 38 deletions

View File

@ -971,6 +971,16 @@ static bool CanBypass(const InterInstruction* lins, const InterInstruction* bins
if (HasSideEffect(lins->mCode) && HasSideEffect(bins->mCode)) if (HasSideEffect(lins->mCode) && HasSideEffect(bins->mCode))
return false; return false;
if (lins->mCode == IC_CALL || lins->mCode == IC_CALL_NATIVE)
{
if (bins->mCode == IC_CALL || bins->mCode == IC_CALL_NATIVE ||
bins->mCode == IC_RETURN || bins->mCode == IC_RETURN_STRUCT || bins->mCode == IC_RETURN_VALUE ||
bins->mCode == IC_PUSH_FRAME || bins->mCode == IC_POP_FRAME)
return false;
if (bins->mCode == IC_LOAD || bins->mCode == IC_STORE || bins->mCode == IC_COPY)
return false;
}
if (lins->mDst.mTemp >= 0) if (lins->mDst.mTemp >= 0)
{ {
if (lins->mDst.mTemp == bins->mDst.mTemp) if (lins->mDst.mTemp == bins->mDst.mTemp)
@ -8356,7 +8366,7 @@ bool InterCodeBasicBlock::CanMoveInstructionDown(int si, int ti) const
{ {
return false; return false;
} }
else if (ins->mCode == IC_CALL || ins->mCode == IC_CALL_NATIVE || ins->mCode == IC_COPY || ins->mCode == IC_PUSH_FRAME || ins->mCode == IC_POP_FRAME || else if (ins->mCode == IC_COPY || ins->mCode == IC_PUSH_FRAME || ins->mCode == IC_POP_FRAME ||
ins->mCode == IC_RETURN || ins->mCode == IC_RETURN_STRUCT || ins->mCode == IC_RETURN_VALUE) ins->mCode == IC_RETURN || ins->mCode == IC_RETURN_STRUCT || ins->mCode == IC_RETURN_VALUE)
return false; return false;
else else
@ -12392,6 +12402,39 @@ void InterCodeProcedure::LoadStoreForwarding(InterMemory paramMemory)
} while (changed); } while (changed);
} }
void InterCodeProcedure::PropagateConstOperationsUp(void)
{
#if 1
ResetEntryBlocks();
ResetVisited();
mEntryBlock->CollectEntryBlocks(nullptr);
bool changed;
do {
changed = false;
ResetVisited();
mEntryBlock->BuildConstTempSets();
ResetVisited();
if (mEntryBlock->PropagateConstOperationsUp())
{
BuildDataFlowSets();
GlobalConstantPropagation();
TempForwarding();
RemoveUnusedInstructions();
changed = true;
DisassembleDebug("prop const op up");
}
} while (changed);
#endif
}
void InterCodeProcedure::Close(void) void InterCodeProcedure::Close(void)
{ {
int i, j, k, start; int i, j, k, start;
@ -12839,34 +12882,7 @@ void InterCodeProcedure::Close(void)
DisassembleDebug("Rebuilt traces"); DisassembleDebug("Rebuilt traces");
#endif #endif
#if 1 PropagateConstOperationsUp();
ResetEntryBlocks();
ResetVisited();
mEntryBlock->CollectEntryBlocks(nullptr);
do {
changed = false;
ResetVisited();
mEntryBlock->BuildConstTempSets();
ResetVisited();
if (mEntryBlock->PropagateConstOperationsUp())
{
BuildDataFlowSets();
GlobalConstantPropagation();
TempForwarding();
RemoveUnusedInstructions();
changed = true;
DisassembleDebug("prop const op up");
}
} while (changed);
#endif
#if 1 #if 1
BuildDataFlowSets(); BuildDataFlowSets();
@ -12925,6 +12941,8 @@ void InterCodeProcedure::Close(void)
#endif #endif
PropagateConstOperationsUp();
#if 1 #if 1
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {

View File

@ -577,6 +577,7 @@ protected:
void EliminateAliasValues(); void EliminateAliasValues();
void LoadStoreForwarding(InterMemory paramMemory); void LoadStoreForwarding(InterMemory paramMemory);
void ExpandSelect(void); void ExpandSelect(void);
void PropagateConstOperationsUp(void);
void MergeBasicBlocks(void); void MergeBasicBlocks(void);
void CheckUsedDefinedTemps(void); void CheckUsedDefinedTemps(void);

View File

@ -44,6 +44,7 @@ bool NativeRegisterData::SameData(const NativeRegisterData& d) const
switch (mMode) switch (mMode)
{ {
case NRDM_UNKNOWN:
case NRDM_IMMEDIATE: case NRDM_IMMEDIATE:
case NRDM_ZERO_PAGE: case NRDM_ZERO_PAGE:
return mValue == d.mValue; return mValue == d.mValue;
@ -189,7 +190,24 @@ void NativeRegisterDataSet::Intersect(const NativeRegisterDataSet& set)
changed = true; changed = true;
} }
} }
else if (mRegs[i].mMode == NRDM_ABSOLUTE_X || mRegs[i].mMode == NRDM_ABSOLUTE_Y || mRegs[i].mMode == NRDM_INDIRECT_Y) else if (mRegs[i].mMode == NRDM_INDIRECT_Y)
{
if (set.mRegs[i].mMode != NRDM_INDIRECT_Y || mRegs[i].mValue != set.mRegs[i].mValue || !mRegs[CPU_REG_Y].SameData(set.mRegs[CPU_REG_Y]))
{
mRegs[i].Reset();
changed = true;
}
else
{
int reg = mRegs[i].mValue;
if (!mRegs[reg].SameData(set.mRegs[reg]) || !mRegs[reg + 1].SameData(set.mRegs[reg + 1]))
{
mRegs[i].Reset();
changed = true;
}
}
}
else if (mRegs[i].mMode == NRDM_ABSOLUTE_X || mRegs[i].mMode == NRDM_ABSOLUTE_Y)
{ {
mRegs[i].Reset(); mRegs[i].Reset();
changed = true; changed = true;
@ -23147,6 +23165,26 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 0].mType = ASMIT_LSR; mIns[i + 0].mType = ASMIT_LSR;
progress = true; progress = true;
} }
else if (
mIns[i + 0].mType == ASMIT_ROL && mIns[i + 0].mMode == ASMIM_IMPLIED &&
mIns[i + 1].mType == ASMIT_AND && mIns[i + 1].mMode == ASMIM_IMMEDIATE && !(mIns[i + 1].mLive & LIVE_CPU_REG_C))
{
mIns[i + 0] = mIns[i + 1];
mIns[i + 0].mLive |= LIVE_CPU_REG_C;
mIns[i + 0].mAddress &= 0x7f;
mIns[i + 1].mType = ASMIT_ROL; mIns[i + 1].mMode = ASMIM_IMPLIED;
progress = true;
}
else if (
mIns[i + 0].mType == ASMIT_ROR && mIns[i + 0].mMode == ASMIM_IMPLIED &&
mIns[i + 1].mType == ASMIT_AND && mIns[i + 1].mMode == ASMIM_IMMEDIATE && !(mIns[i + 1].mLive & LIVE_CPU_REG_C))
{
mIns[i + 0] = mIns[i + 1];
mIns[i + 0].mLive |= LIVE_CPU_REG_C;
mIns[i + 0].mAddress &= 0xfe;
mIns[i + 1].mType = ASMIT_ROR; mIns[i + 1].mMode = ASMIM_IMPLIED;
progress = true;
}
else if ( else if (
mIns[i + 0].IsShift() && mIns[i + 0].mMode == ASMIM_ZERO_PAGE && mIns[i + 0].IsShift() && mIns[i + 0].mMode == ASMIM_ZERO_PAGE &&
mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mAddress == mIns[i + 0].mAddress && !(mIns[i + 1].mLive & LIVE_MEM)) mIns[i + 1].mType == ASMIT_LDA && mIns[i + 1].mMode == ASMIM_ZERO_PAGE && mIns[i + 1].mAddress == mIns[i + 0].mAddress && !(mIns[i + 1].mLive & LIVE_MEM))

View File

@ -74,7 +74,7 @@ int main2(int argc, const char** argv)
#else #else
strcpy(strProductName, "oscar64"); strcpy(strProductName, "oscar64");
strcpy(strProductVersion, "1.8.152"); strcpy(strProductVersion, "1.8.153");
#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,8,152,0 FILEVERSION 1,8,153,0
PRODUCTVERSION 1,8,152,0 PRODUCTVERSION 1,8,153,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.8.152.0" VALUE "FileVersion", "1.8.153.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.8.152.0" VALUE "ProductVersion", "1.8.153.0"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"

View File

@ -4231,15 +4231,15 @@
{ {
"Name" = "8:Microsoft Visual Studio" "Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:oscar64" "ProductName" = "8:oscar64"
"ProductCode" = "8:{5EE28B01-CA5F-4F23-8937-291BC1DD4853}" "ProductCode" = "8:{DD3A8713-73F3-416C-8D8A-905F9DF55406}"
"PackageCode" = "8:{F8E05C56-4982-400F-BBB1-D7C95C3C65C8}" "PackageCode" = "8:{077A6A53-3869-44C4-9BBE-C0F41C483A9B}"
"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.8.152" "ProductVersion" = "8:1.8.153"
"Manufacturer" = "8:oscar64" "Manufacturer" = "8:oscar64"
"ARPHELPTELEPHONE" = "8:" "ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:" "ARPHELPLINK" = "8:"