Optimize negative const offsets in array index
This commit is contained in:
parent
bd2e198339
commit
0835b90219
|
@ -7670,6 +7670,66 @@ void InterCodeBasicBlock::PerformValueForwarding(const GrowingInstructionPtrArra
|
||||||
ins->mSrc[1].mTemp = cai->mDst.mTemp;
|
ins->mSrc[1].mTemp = cai->mDst.mTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (mi0 && mi1 && mi0->mCode == IC_CONSTANT && mi1->mCode == IC_BINARY_OPERATOR && mi1->mOperator == IA_SUB)
|
||||||
|
{
|
||||||
|
InterInstruction* ai0 = ltvalue[mi1->mSrc[0].mTemp], * ai1 = ltvalue[mi1->mSrc[1].mTemp];
|
||||||
|
if (ai0 && ai0->mCode == IC_CONSTANT)
|
||||||
|
{
|
||||||
|
InterInstruction* nai = new InterInstruction();
|
||||||
|
nai->mCode = IC_BINARY_OPERATOR;
|
||||||
|
nai->mOperator = IA_MUL;
|
||||||
|
nai->mSrc[0].mTemp = mi1->mSrc[1].mTemp;
|
||||||
|
nai->mSrc[0].mType = IT_INT16;
|
||||||
|
nai->mSrc[1].mTemp = ins->mSrc[0].mTemp;
|
||||||
|
nai->mSrc[1].mType = IT_INT16;
|
||||||
|
nai->mDst.mTemp = spareTemps++;
|
||||||
|
nai->mDst.mType = IT_INT16;
|
||||||
|
mInstructions.Insert(i, nai);
|
||||||
|
|
||||||
|
ltvalue[nai->mDst.mTemp] = nullptr;
|
||||||
|
|
||||||
|
InterInstruction* cai = new InterInstruction();
|
||||||
|
cai->mCode = IC_CONSTANT;
|
||||||
|
cai->mDst.mTemp = spareTemps++;
|
||||||
|
cai->mDst.mType = IT_INT16;
|
||||||
|
cai->mConst.mIntConst = ai0->mConst.mIntConst * mi0->mConst.mIntConst;
|
||||||
|
mInstructions.Insert(i, cai);
|
||||||
|
|
||||||
|
ltvalue[cai->mDst.mTemp] = nullptr;
|
||||||
|
|
||||||
|
ins->mOperator = IA_SUB;
|
||||||
|
ins->mSrc[1].mTemp = nai->mDst.mTemp;
|
||||||
|
ins->mSrc[0].mTemp = cai->mDst.mTemp;
|
||||||
|
}
|
||||||
|
else if (ai1 && ai1->mCode == IC_CONSTANT)
|
||||||
|
{
|
||||||
|
InterInstruction* nai = new InterInstruction();
|
||||||
|
nai->mCode = IC_BINARY_OPERATOR;
|
||||||
|
nai->mOperator = IA_MUL;
|
||||||
|
nai->mSrc[0].mTemp = mi1->mSrc[0].mTemp;
|
||||||
|
nai->mSrc[0].mType = IT_INT16;
|
||||||
|
nai->mSrc[1].mTemp = ins->mSrc[0].mTemp;
|
||||||
|
nai->mSrc[1].mType = IT_INT16;
|
||||||
|
nai->mDst.mTemp = spareTemps++;
|
||||||
|
nai->mDst.mType = IT_INT16;
|
||||||
|
mInstructions.Insert(i, nai);
|
||||||
|
|
||||||
|
ltvalue[nai->mDst.mTemp] = nullptr;
|
||||||
|
|
||||||
|
InterInstruction* cai = new InterInstruction();
|
||||||
|
cai->mCode = IC_CONSTANT;
|
||||||
|
cai->mDst.mTemp = spareTemps++;
|
||||||
|
cai->mDst.mType = IT_INT16;
|
||||||
|
cai->mConst.mIntConst = ai1->mConst.mIntConst * mi0->mConst.mIntConst;
|
||||||
|
mInstructions.Insert(i, cai);
|
||||||
|
|
||||||
|
ltvalue[cai->mDst.mTemp] = nullptr;
|
||||||
|
|
||||||
|
ins->mOperator = IA_SUB;
|
||||||
|
ins->mSrc[1].mTemp = nai->mDst.mTemp;
|
||||||
|
ins->mSrc[0].mTemp = cai->mDst.mTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if 1
|
#if 1
|
||||||
|
@ -12568,6 +12628,8 @@ void InterCodeProcedure::Close(void)
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
mEntryBlock->PerformValueForwarding(mValueForwardingTable, valueSet, tvalidSet, mLocalAliasedSet, mParamAliasedSet, numTemps, mModule->mGlobalVars);
|
mEntryBlock->PerformValueForwarding(mValueForwardingTable, valueSet, tvalidSet, mLocalAliasedSet, mParamAliasedSet, numTemps, mModule->mGlobalVars);
|
||||||
|
|
||||||
|
DisassembleDebug("PerformValueForwarding");
|
||||||
|
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
eliminated = mEntryBlock->EliminateDeadBranches();
|
eliminated = mEntryBlock->EliminateDeadBranches();
|
||||||
if (eliminated)
|
if (eliminated)
|
||||||
|
|
|
@ -24657,6 +24657,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
|
||||||
(mIns[i + 0].mType == ASMIT_INX || mIns[i + 0].mType == ASMIT_DEX) &&
|
(mIns[i + 0].mType == ASMIT_INX || mIns[i + 0].mType == ASMIT_DEX) &&
|
||||||
mIns[i + 1].mType == ASMIT_TXA && !(mIns[i + 1].mLive & LIVE_CPU_REG_A))
|
mIns[i + 1].mType == ASMIT_TXA && !(mIns[i + 1].mLive & LIVE_CPU_REG_A))
|
||||||
{
|
{
|
||||||
|
mIns[i + 0].mLive |= LIVE_CPU_REG_Z;
|
||||||
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
|
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
|
||||||
progress = true;
|
progress = true;
|
||||||
}
|
}
|
||||||
|
@ -24664,6 +24665,7 @@ bool NativeCodeBasicBlock::PeepHoleOptimizer(NativeCodeProcedure* proc, int pass
|
||||||
(mIns[i + 0].mType == ASMIT_INY || mIns[i + 0].mType == ASMIT_DEY) &&
|
(mIns[i + 0].mType == ASMIT_INY || mIns[i + 0].mType == ASMIT_DEY) &&
|
||||||
mIns[i + 1].mType == ASMIT_TYA && !(mIns[i + 1].mLive & LIVE_CPU_REG_A))
|
mIns[i + 1].mType == ASMIT_TYA && !(mIns[i + 1].mLive & LIVE_CPU_REG_A))
|
||||||
{
|
{
|
||||||
|
mIns[i + 0].mLive |= LIVE_CPU_REG_Z;
|
||||||
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
|
mIns[i + 1].mType = ASMIT_NOP; mIns[i + 1].mMode = ASMIM_IMPLIED;
|
||||||
progress = true;
|
progress = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue