Skip to content

Commit

Permalink
Some more cross block pointer forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Dec 18, 2022
1 parent cdd7a15 commit 9daf4fa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
48 changes: 48 additions & 0 deletions oscar64/InterCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9265,6 +9265,50 @@ bool InterCodeBasicBlock::MoveTrainCrossBlock(void)
return changed;
}

bool InterCodeBasicBlock::ForwardLoopMovedTemp(void)
{
bool changed = false;

if (!mVisited)
{
mVisited = true;

if (mTrueJump && !mFalseJump && mTrueJump->mLoopHead && mTrueJump->mNumEntries == 2)
{
InterCodeBasicBlock* eblock = nullptr;
if (mTrueJump->mTrueJump == mTrueJump)
eblock = mTrueJump->mFalseJump;
else if (mTrueJump->mFalseJump == mTrueJump)
eblock = mTrueJump->mTrueJump;

if (eblock)
{
int i = mInstructions.Size() - 1;
while (i >= 0)
{
if (mInstructions[i]->mCode == IC_LOAD_TEMPORARY && CanMoveInstructionBehindBlock(i) &&
!mTrueJump->mLocalUsedTemps[mInstructions[i]->mDst.mTemp] &&
!mTrueJump->mLocalModifiedTemps[mInstructions[i]->mSrc[0].mTemp])
{
eblock->mInstructions.Insert(0, mInstructions[i]);
mInstructions.Remove(i);
changed = true;
}
else
i--;
}
}
}

if (mTrueJump && mTrueJump->ForwardLoopMovedTemp())
changed = true;
if (mFalseJump && mFalseJump->ForwardLoopMovedTemp())
changed = true;
}

return changed;
}

bool InterCodeBasicBlock::ForwardDiamondMovedTemp(void)
{
bool changed = false;
Expand Down Expand Up @@ -14187,6 +14231,10 @@ void InterCodeProcedure::Close(void)
}
#endif

BuildDataFlowSets();
ResetVisited();
mEntryBlock->ForwardLoopMovedTemp();

#if 1
do {
TempForwarding();
Expand Down
1 change: 1 addition & 0 deletions oscar64/InterCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ class InterCodeBasicBlock
bool IsLeafProcedure(void);

bool ForwardDiamondMovedTemp(void);
bool ForwardLoopMovedTemp(void);

bool MoveTrainCrossBlock(void);

Expand Down
29 changes: 29 additions & 0 deletions oscar64/NativeCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28004,6 +28004,22 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
mIns[i + 2].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
progress = true;
}
else if (
mIns[i + 0].ChangesAccuAndFlag() &&
(mIns[i + 1].mType == ASMIT_INC || mIns[i + 1].mType == ASMIT_DEC) &&
mIns[i + 2].mType == ASMIT_ORA && mIns[i + 2].mMode == ASMIM_IMMEDIATE && mIns[i + 2].mAddress == 0 &&
mIns[i + 1].MayBeMovedBefore(mIns[i + 0]))
{
mIns.Insert(i, mIns[i + 1]);
mIns[i].mLive |= LIVE_CPU_REG_A;
if (mIns[i + 1].RequiresYReg())
mIns[i].mLive |= LIVE_CPU_REG_Y;
if (mIns[i + 1].RequiresXReg())
mIns[i].mLive |= LIVE_CPU_REG_X;
mIns[i + 1].mLive |= LIVE_CPU_REG_Z;
mIns.Remove(i + 2);
progress = true;
}

if (
mIns[i + 0].mType == ASMIT_LDY && mIns[i + 0].mMode == ASMIM_IMMEDIATE && mIns[i + 0].mAddress <= 1 &&
Expand Down Expand Up @@ -28882,6 +28898,19 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
}
#endif
#if 1
else if (
mIns[i + 0].mType == ASMIT_LDA && mIns[i + 0].mMode == ASMIM_IMMEDIATE &&
mIns[i + 1].mType == ASMIT_STA &&
mIns[i + 2].mType == ASMIT_LDA &&
mIns[i + 3].mType == ASMIT_CMP && mIns[i + 3].mMode == ASMIM_IMMEDIATE && mIns[i + 3].mAddress == mIns[i + 0].mAddress && !(mIns[i + 3].mLive & (LIVE_CPU_REG_A | LIVE_CPU_REG_C)))
{
mIns[i + 1].mLive |= LIVE_CPU_REG_A;
mIns[i + 2].mType = ASMIT_CMP; mIns[i + 2].mLive |= LIVE_CPU_REG_Z;
mIns[i + 3].mType = ASMIT_NOP; mIns[i + 3].mMode = ASMIM_IMPLIED;

progress = true;
}

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() &&
Expand Down

0 comments on commit 9daf4fa

Please sign in to comment.