Fix shortcut moves violating carry dependencies
This commit is contained in:
parent
b6a02550f9
commit
8287f03f49
|
@ -12445,6 +12445,21 @@ bool NativeCodeBasicBlock::SimplifyLoopEnd(NativeCodeProcedure* proc)
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NativeCodeBasicBlock::CanBytepassLoad(const NativeCodeInstruction& ains) const
|
||||||
|
{
|
||||||
|
for (int i = 0; i < mIns.Size(); i++)
|
||||||
|
{
|
||||||
|
if (ains.MayBeChangedOnAddress(mIns[i]))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (ains.mType == ASMIT_LDY && mIns[i].ReferencesYReg() ||
|
||||||
|
ains.mType == ASMIT_LDX && mIns[i].ReferencesXReg())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool NativeCodeBasicBlock::SimplifyDiamond(NativeCodeProcedure* proc)
|
bool NativeCodeBasicBlock::SimplifyDiamond(NativeCodeProcedure* proc)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
@ -12473,6 +12488,36 @@ bool NativeCodeBasicBlock::SimplifyDiamond(NativeCodeProcedure* proc)
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mTrueJump->mEntryRequiredRegs[CPU_REG_Y] && mFalseJump->mEntryRequiredRegs[CPU_REG_Y] && mTrueJump->mTrueJump->mEntryRequiredRegs[CPU_REG_Y])
|
||||||
|
{
|
||||||
|
int sz = mIns.Size() - 1;
|
||||||
|
while (sz >= 0 && !mIns[sz].ReferencesYReg())
|
||||||
|
sz--;
|
||||||
|
if (sz >= 0 && mIns[sz].mType == ASMIT_LDY && (mIns[sz].mMode == ASMIM_ZERO_PAGE || mIns[sz].mMode == ASMIM_ABSOLUTE) && !(mIns[sz].mLive & LIVE_CPU_REG_Z))
|
||||||
|
{
|
||||||
|
if (mTrueJump->CanBytepassLoad(mIns[sz]) && mFalseJump->CanBytepassLoad(mIns[sz]))
|
||||||
|
{
|
||||||
|
mTrueJump->mTrueJump->mIns.Insert(0, NativeCodeInstruction(ASMIT_LDY, mIns[sz]));
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mTrueJump->mEntryRequiredRegs[CPU_REG_X] && mFalseJump->mEntryRequiredRegs[CPU_REG_X] && mTrueJump->mTrueJump->mEntryRequiredRegs[CPU_REG_X])
|
||||||
|
{
|
||||||
|
int sz = mIns.Size() - 1;
|
||||||
|
while (sz >= 0 && !mIns[sz].ReferencesXReg())
|
||||||
|
sz--;
|
||||||
|
if (sz >= 0 && mIns[sz].mType == ASMIT_LDX && (mIns[sz].mMode == ASMIM_ZERO_PAGE || mIns[sz].mMode == ASMIM_ABSOLUTE) && !(mIns[sz].mLive & LIVE_CPU_REG_Z))
|
||||||
|
{
|
||||||
|
if (mTrueJump->CanBytepassLoad(mIns[sz]) && mFalseJump->CanBytepassLoad(mIns[sz]))
|
||||||
|
{
|
||||||
|
mTrueJump->mTrueJump->mIns.Insert(0, NativeCodeInstruction(ASMIT_LDX, mIns[sz]));
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if 1
|
#if 1
|
||||||
if (mTrueJump->mEntryRequiredRegs[CPU_REG_Y] && !mFalseJump->mEntryRequiredRegs[CPU_REG_Y] && !mTrueJump->mEntryRequiredRegs[CPU_REG_Z] && mTrueJump->mNumEntries == 1)
|
if (mTrueJump->mEntryRequiredRegs[CPU_REG_Y] && !mFalseJump->mEntryRequiredRegs[CPU_REG_Y] && !mTrueJump->mEntryRequiredRegs[CPU_REG_Z] && mTrueJump->mNumEntries == 1)
|
||||||
|
@ -16121,6 +16166,8 @@ bool NativeCodeBasicBlock::JoinTAXARange(int from, int to)
|
||||||
{
|
{
|
||||||
if (mIns[start].MayBeChangedOnAddress(mIns[i]) || mIns[start + 1].MayBeChangedOnAddress(mIns[i]))
|
if (mIns[start].MayBeChangedOnAddress(mIns[i]) || mIns[start + 1].MayBeChangedOnAddress(mIns[i]))
|
||||||
return false;
|
return false;
|
||||||
|
if (mIns[start + 1].RequiresCarry() && mIns[i].ChangesCarry())
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int live = mIns[to].mLive;
|
int live = mIns[to].mLive;
|
||||||
|
@ -29129,6 +29176,7 @@ void NativeCodeProcedure::Optimize(void)
|
||||||
mEntryBlock->CheckBlocks();
|
mEntryBlock->CheckBlocks();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if 1
|
||||||
if (step == 5)
|
if (step == 5)
|
||||||
{
|
{
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
|
@ -29139,6 +29187,13 @@ void NativeCodeProcedure::Optimize(void)
|
||||||
if (mEntryBlock->SimplifyLoopEnd(this))
|
if (mEntryBlock->SimplifyLoopEnd(this))
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
if (step == 7)
|
||||||
|
{
|
||||||
|
ResetVisited();
|
||||||
|
if (mEntryBlock->SimplifyDiamond(this))
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
if (step >= 6)
|
if (step >= 6)
|
||||||
|
|
|
@ -400,6 +400,8 @@ public:
|
||||||
bool SimplifyDiamond(NativeCodeProcedure* proc);
|
bool SimplifyDiamond(NativeCodeProcedure* proc);
|
||||||
bool SimplifyLoopEnd(NativeCodeProcedure* proc);
|
bool SimplifyLoopEnd(NativeCodeProcedure* proc);
|
||||||
|
|
||||||
|
bool CanBytepassLoad(const NativeCodeInstruction& ains) const;
|
||||||
|
|
||||||
bool MoveAccuTrainUp(int at, int end);
|
bool MoveAccuTrainUp(int at, int end);
|
||||||
bool MoveAccuTrainsUp(void);
|
bool MoveAccuTrainsUp(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue