diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index 43b6fbe..8e002cb 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -7670,6 +7670,66 @@ void InterCodeBasicBlock::PerformValueForwarding(const GrowingInstructionPtrArra 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 #if 1 @@ -12568,6 +12628,8 @@ void InterCodeProcedure::Close(void) ResetVisited(); mEntryBlock->PerformValueForwarding(mValueForwardingTable, valueSet, tvalidSet, mLocalAliasedSet, mParamAliasedSet, numTemps, mModule->mGlobalVars); + DisassembleDebug("PerformValueForwarding"); + ResetVisited(); eliminated = mEntryBlock->EliminateDeadBranches(); if (eliminated) diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index a8cf622..b7427e3 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -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 + 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; 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 + 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; progress = true; }