Byte code optimizations

This commit is contained in:
drmortalwombat 2021-11-21 22:53:06 +01:00
parent 4af2bc0bb2
commit 6007553d03
8 changed files with 261 additions and 65 deletions

View File

@ -1,6 +1,13 @@
#include "charwin.h"
static const unsigned mul40[25] = {
0, 40, 80, 120, 160,
200, 240, 280, 320, 360,
400, 440, 480, 520, 560,
600, 640, 680, 720, 760,
800, 840, 880, 920, 960
};
static void copy_fwd(char * sdp, const char * ssp, char * cdp, const char * csp, char n)
{
@ -46,8 +53,8 @@ void cwin_init(CharWin * win, char * screen, char sx, char sy, char wx, char wy)
win->wy = wy;
win->cx = 0;
win->cy = 0;
win->sp = screen + 40 * sy + sx;
win->cp = (char *)0xd800 + 40 * sy + sx;
win->sp = screen + mul40[sy] + sx;
win->cp = (char *)0xd800 + mul40[sy] + sx;
}
@ -70,7 +77,7 @@ void cwin_fill(CharWin * win, char ch, char color)
void cwin_cursor_show(CharWin * win, bool show)
{
char * cp = win->sp + 40 * win->cy + win->cx;
char * cp = win->sp + mul40[win->cy] + win->cx;
if (show)
*cp |= 0x80;
else
@ -245,7 +252,7 @@ char cwin_put_string(CharWin * win, const char * str, char color)
void cwin_putat_char(CharWin * win, char x, char y, char ch, char color)
{
int offset = 40 * y + x;
int offset = mul40[y] + x;
ch &= 0xbf;
if (ch & 0x80)
@ -259,7 +266,7 @@ void cwin_putat_char(CharWin * win, char x, char y, char ch, char color)
void cwin_putat_chars(CharWin * win, char x, char y, const char * chars, char num, char color)
{
int offset = 40 * y + x;
int offset = mul40[y] + x;
char * sp = win->sp + offset;
char * cp = win->cp + offset;
@ -281,7 +288,7 @@ void cwin_putat_chars(CharWin * win, char x, char y, const char * chars, char nu
char cwin_putat_string(CharWin * win, char x, char y, const char * str, char color)
{
int offset = 40 * y + x;
int offset = mul40[y] + x;
char * sp = win->sp + offset;
char * cp = win->cp + offset;
@ -306,7 +313,7 @@ char cwin_putat_string(CharWin * win, char x, char y, const char * str, char col
char cwin_getat_char(CharWin * win, char x, char y)
{
char * sp = win->sp + 40 * y + x;
char * sp = win->sp + mul40[y] + x;
char c = *sp;
@ -320,7 +327,7 @@ char cwin_getat_char(CharWin * win, char x, char y)
void cwin_getat_chars(CharWin * win, char x, char y, char * chars, char num)
{
char * sp = win->sp + 40 * y + x;
char * sp = win->sp + mul40[y] + x;
for(char i=0; i<num; i++)
{
@ -340,8 +347,8 @@ void cwin_insert_char(CharWin * win)
{
char y = win->wy - 1, rx = win->wx - 1;
char * sp = win->sp + 40 * y;
char * cp = win->cp + 40 * y;
char * sp = win->sp + mul40[y];
char * cp = win->cp + mul40[y];
while (y > win->cy)
{
@ -365,8 +372,8 @@ void cwin_insert_char(CharWin * win)
void cwin_delete_char(CharWin * win)
{
char * sp = win->sp + 40 * win->cy;
char * cp = win->cp + 40 * win->cy;
char * sp = win->sp + mul40[win->cy];
char * cp = win->cp + mul40[win->cy];
char x = win->cx, rx = win->wx - 1;
@ -503,7 +510,7 @@ void cwin_scroll_up(CharWin * win, char by)
char * cp = win->cp;
char rx = win->wx;
int dst = 40 * by;
int dst = mul40[by];
for(char y=0; y<win->wy - by; y++)
{
@ -515,12 +522,12 @@ void cwin_scroll_up(CharWin * win, char by)
void cwin_scroll_down(CharWin * win, char by)
{
char * sp = win->sp + 40 * win->wy;
char * cp = win->cp + 40 * win->wy;
char * sp = win->sp + mul40[win->wy];
char * cp = win->cp + mul40[win->wy];
char rx = win->wx;
int dst = 40 * by;
int dst = mul40[by];
for(char y=0; y<win->wy - by; y++)
{
@ -535,8 +542,8 @@ void cwin_fill_rect(CharWin * win, char x, char y, char w, char h, char ch, char
{
if (w > 0)
{
char * sp = win->sp + 40 * y + x;
char * cp = win->cp + 40 * y + x;
char * sp = win->sp + mul40[y] + x;
char * cp = win->cp + mul40[y] + x;
for(char y=0; y<h; y++)
{

View File

@ -165,11 +165,9 @@ incip:
inc ip + 1
bne execjmp
bcode:
byt BC_LEA_ABS * 2
byt addr
byt BC_CALL_ABS * 2
byt <main
byt >main
byt BC_CALL * 2
byt BC_EXIT * 2
#endif
}
@ -2355,7 +2353,13 @@ __asm inp_pop_frame
#pragma bytecode(BC_POP_FRAME, inp_pop_frame)
__asm inp_call
{
{ lda (ip), y
sta addr
iny
lda (ip), y
sta addr + 1
iny
inp_call_addr:
tya
ldy #0
clc
@ -2372,7 +2376,8 @@ __asm inp_call
jmp startup.pexec
}
#pragma bytecode(BC_CALL, inp_call)
#pragma bytecode(BC_CALL_ADDR, inp_call.inp_call_addr)
#pragma bytecode(BC_CALL_ABS, inp_call)
__asm inp_copy
{

View File

@ -147,16 +147,17 @@ enum ByteCode
BC_SET_LT,
BC_SET_LE,
BC_JSR,
BC_NATIVE = 0x75,
BC_ENTER,
BC_RETURN,
BC_CALL,
BC_CALL_ADDR,
BC_CALL_ABS,
BC_PUSH_FRAME,
BC_POP_FRAME,
BC_JSR,
BC_COPY,
BC_COPY_LONG,
BC_STRCPY,

View File

@ -12,7 +12,7 @@ void itoa(int n, char * s, unsigned radix)
n = - n;
}
int i = 0;
char i = 0;
do {
int d = n % radix;
if (d < 10)
@ -27,7 +27,7 @@ void itoa(int n, char * s, unsigned radix)
s[i++] = '-';
}
s[i] = 0;
int j = 0;
char j = 0;
while (j + 1 < i)
{
char c = s[j];
@ -38,7 +38,7 @@ void itoa(int n, char * s, unsigned radix)
void utoa(unsigned int n, char * s, unsigned radix)
{
int i = 0;
char i = 0;
do {
unsigned int d = n % radix;
if (d < 10)
@ -49,8 +49,8 @@ void utoa(unsigned int n, char * s, unsigned radix)
} while ((n /= radix) > 0);
s[i] = 0;
int j = 0;
while (j + 1 < i)
char j = 0;
while ((char)(j + 1) < i)
{
char c = s[j];
s[j++] = s[--i];
@ -66,7 +66,7 @@ void ltoa(long n, char * s, unsigned radix)
n = - n;
}
int i = 0;
char i = 0;
do {
int d = n % radix;
if (d < 10)
@ -81,7 +81,7 @@ void ltoa(long n, char * s, unsigned radix)
s[i++] = '-';
}
s[i] = 0;
int j = 0;
char j = 0;
while (j + 1 < i)
{
char c = s[j];
@ -92,7 +92,7 @@ void ltoa(long n, char * s, unsigned radix)
void ultoa(unsigned long n, char * s, unsigned radix)
{
int i = 0;
char i = 0;
do {
unsigned int d = n % radix;
if (d < 10)
@ -103,7 +103,7 @@ void ultoa(unsigned long n, char * s, unsigned radix)
} while ((n /= radix) > 0);
s[i] = 0;
int j = 0;
char j = 0;
while (j + 1 < i)
{
char c = s[j];

View File

@ -34,8 +34,10 @@ static const char* ByteCodeNames[] = {
"LEA_ABS",
"LEA_ABS_INDEX",
"LEA_ABS_INDEX_U8",
"LEA_ACCU_INDEX",
"LOAD_LOCAL_8",
"LOAD_LOCAL_U8",
"LOAD_LOCAL_16",
"LOAD_LOCAL_32",
@ -74,6 +76,8 @@ static const char* ByteCodeNames[] = {
"BINOP_SHRR_U16",
"BINOP_SHRR_I16",
"BINOP_ADDA_16",
"BINOP_ADDI_16",
"BINOP_SUBI_16",
"BINOP_ANDI_16",
@ -143,24 +147,21 @@ static const char* ByteCodeNames[] = {
"SET_LT",
"SET_LE",
nullptr,
nullptr,
nullptr,
nullptr,
"JSR", //113
nullptr,
nullptr,
nullptr,
"NATIVE",
"NATIVE", //117
"ENTER",
"RETURN",
"CALL",
"CALL_ADDR",
"CALL_ABS",
"PUSH_FRAME",
"POP_FRAME",
"JSR",
"COPY",
"COPY_LONG",
"STRCPY",
@ -778,7 +779,7 @@ bool ByteCodeInstruction::UsesRegister(uint32 reg) const
if (mCode == BC_COPY || mCode == BC_STRCPY)
return true;
if (mCode == BC_JSR || mCode == BC_CALL)
if (mCode == BC_JSR || mCode == BC_CALL_ADDR || mCode == BC_CALL_ABS)
return true;
}
@ -804,12 +805,16 @@ bool ByteCodeInstruction::ChangesRegister(uint32 reg) const
return true;
if (mCode >= BC_BINOP_ADDI_16 && mCode <= BC_BINOP_ORI_8)
return true;
if (mCode == BC_CALL)
return true;
if (mCode == BC_BINOP_ADDA_16)
return true;
}
if (reg >= BC_REG_WORK && reg < BC_REG_FPARAMS_END || reg >= BC_REG_TMP && reg < BC_REG_TMP_SAVED)
{
if (mCode == BC_JSR || mCode == BC_CALL_ADDR || mCode == BC_CALL_ABS)
return true;
}
if (reg == BC_REG_ACCU)
{
if (mCode == BC_LOAD_REG_8 || mCode == BC_LOAD_REG_16 || mCode == BC_LOAD_REG_32)
@ -830,7 +835,7 @@ bool ByteCodeInstruction::ChangesRegister(uint32 reg) const
return true;
if (mCode >= BC_SET_EQ && mCode <= BC_SET_LE)
return true;
if (mCode == BC_JSR || mCode == BC_CALL)
if (mCode == BC_JSR || mCode == BC_CALL_ADDR || mCode == BC_CALL_ABS)
return true;
if (mCode >= BC_CONV_I16_I32 && mCode <= BC_BINOP_CMP_S32)
return true;
@ -842,12 +847,28 @@ bool ByteCodeInstruction::ChangesRegister(uint32 reg) const
return true;
if (mCode >= BC_LOAD_ABS_8 && mCode <= BC_STORE_ABS_32)
return true;
if (mCode == BC_JSR || mCode == BC_CALL)
if (mCode == BC_JSR || mCode == BC_CALL_ADDR || mCode == BC_CALL_ABS)
return true;
if (mCode == BC_LEA_ABS_INDEX || mCode == BC_LEA_ABS_INDEX_U8 || mCode == BC_LEA_ACCU_INDEX)
return true;
}
if (reg == BC_REG_WORK)
{
if (mCode == BC_JSR || mCode == BC_CALL_ADDR || mCode == BC_CALL_ABS)
return true;
if (mCode == BC_BINOP_DIVR_I16 || mCode == BC_BINOP_DIVR_U16 || mCode == BC_BINOP_MODR_I16 || mCode == BC_BINOP_MODR_U16 ||
mCode == BC_BINOP_DIV_I32 || mCode == BC_BINOP_DIV_U32 || mCode == BC_BINOP_MOD_I32 || mCode == BC_BINOP_MOD_U32 ||
mCode == BC_BINOP_MULR_16 || mCode == BC_BINOP_MULI8_16 || mCode == BC_BINOP_MUL_L32)
return true;
if (mCode >= BC_BINOP_ADD_F32 && mCode <= BC_OP_CEIL_F32)
return true;
if (mCode >= BC_CONV_U16_F32 && mCode <= BC_CONV_F32_I16)
return true;
}
return false;
}
@ -1103,10 +1124,24 @@ void ByteCodeInstruction::Assemble(ByteCodeGenerator* generator, ByteCodeBasicBl
assert(false);
break;
case BC_CALL:
case BC_CALL_ADDR:
block->PutCode(generator, mCode);
break;
case BC_CALL_ABS:
{
block->PutCode(generator, mCode);
LinkerReference rl;
rl.mOffset = block->mCode.Size();
rl.mFlags = LREF_HIGHBYTE | LREF_LOWBYTE;
rl.mRefObject = mLinkerObject;
rl.mRefOffset = 0;
block->mRelocations.Push(rl);
block->PutWord(0);
} break;
case BC_PUSH_FRAME:
case BC_POP_FRAME:
block->PutCode(generator, mCode);
@ -2879,11 +2914,10 @@ void ByteCodeBasicBlock::CallFunction(InterCodeProcedure* proc, const InterInstr
{
if (ins->mSrc[0].mTemp < 0)
{
ByteCodeInstruction bins(BC_LEA_ABS);
ByteCodeInstruction bins(BC_CALL_ABS);
bins.mRelocate = true;
bins.mLinkerObject = ins->mSrc[0].mLinkerObject;
bins.mValue = 0;
bins.mRegister = BC_REG_ADDR;
mIns.Push(bins);
}
else
@ -2892,11 +2926,10 @@ void ByteCodeBasicBlock::CallFunction(InterCodeProcedure* proc, const InterInstr
bins.mRegister = BC_REG_TMP + proc->mTempOffset[ins->mSrc[0].mTemp];
bins.mRegisterFinal = ins->mSrc[0].mFinal;
mIns.Push(bins);
ByteCodeInstruction cins(BC_CALL_ADDR);
mIns.Push(cins);
}
ByteCodeInstruction cins(BC_CALL);
mIns.Push(cins);
if (ins->mDst.mTemp >= 0)
{
ByteCodeInstruction bins(StoreTypedTmpCodes[ins->mDst.mType]);
@ -4292,6 +4325,69 @@ bool ByteCodeBasicBlock::JoinTailCodeSequences(void)
return changed;
}
bool ByteCodeBasicBlock::PropagateAccuCrossBorder(int accu, int addr)
{
bool changed = false;
if (!mVisited)
{
mVisited = true;
if (mEntryBlocks.Size() != 1)
accu = addr = -1;
int j = 0;
for (int i = 0; i < mIns.Size(); i++)
{
if (mIns[i].mCode == BC_ADDR_REG && addr == mIns[i].mRegister ||
mIns[i].mCode == BC_LOAD_REG_16 && accu == mIns[i].mRegister ||
mIns[i].mCode == BC_STORE_REG_16 && accu == mIns[i].mRegister)
{
changed = true;
}
else
{
if (mIns[i].mCode == BC_ADDR_REG)
addr = mIns[i].mRegister;
else if (mIns[i].mCode == BC_LOAD_REG_16)
accu = mIns[i].mRegister;
else if (mIns[i].mCode == BC_STORE_REG_16)
{
accu = mIns[i].mRegister;
if (addr == mIns[i].mRegister)
addr = -1;
}
else
{
if (accu >= 0 && mIns[i].ChangesRegister(accu))
accu = -1;
if (addr >= 0 && mIns[i].ChangesRegister(addr))
addr = -1;
if (accu >= 0 && mIns[i].ChangesAccu())
accu = -1;
if (addr >= 0 && mIns[i].ChangesAddr())
addr = -1;
}
if (i != j)
{
mIns[j] = mIns[i];
}
j++;
}
}
mIns.SetSize(j);
if (mTrueJump && mTrueJump->PropagateAccuCrossBorder(accu, addr))
changed = true;
if (mFalseJump && mFalseJump->PropagateAccuCrossBorder(accu, addr))
changed = true;
}
return changed;
}
bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase)
{
bool changed = false;
@ -4795,6 +4891,18 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase)
mIns[i + 2].mCode = BC_NOP;
progress = true;
}
else if (
mIns[i + 0].mCode == BC_LEA_ABS && mIns[i + 0].mRegister == BC_REG_ACCU &&
mIns[i + 1].mCode == BC_BINOP_ADDA_16 &&
mIns[i + 2].mCode == BC_ADDR_REG && mIns[i + 1].mRegister == mIns[i + 2].mRegister && mIns[i + 2].mRegisterFinal && !(mIns[i + 2].mLive & LIVE_ACCU))
{
mIns[i + 0].mCode = BC_LEA_ABS_INDEX;
mIns[i + 0].mRegister = mIns[i + 2].mRegister;
mIns[i + 0].mRegisterFinal = true;
mIns[i + 1].mCode = BC_NOP;
mIns[i + 2].mCode = BC_NOP;
progress = true;
}
else if (
mIns[i + 0].mCode == BC_LOAD_REG_16 &&
mIns[i + 1].mCode == BC_BINOP_ADDR_16 &&
@ -4817,6 +4925,36 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase)
mIns[i + 2].mCode = BC_BINOP_ADDA_16;
progress = true;
}
else if (
mIns[i + 0].mCode == BC_STORE_REG_16 &&
mIns[i + 2].mCode == BC_LEA_ABS_INDEX && mIns[i + 0].mRegister == mIns[i + 2].mRegister && mIns[i + 2].mRegisterFinal &&
(mIns[i + 1].mCode == BC_BINOP_ADDI_16 || mIns[i + 1].mCode == BC_BINOP_ANDI_16 || mIns[i + 1].mCode == BC_BINOP_ORI_16 || mIns[i + 1].mCode == BC_BINOP_MULI8_16) &&
mIns[i + 1].mRegister == mIns[i + 0].mRegister && !(mIns[i + 2].mLive & LIVE_ACCU))
{
mIns[i + 0].mCode = BC_NOP;
mIns[i + 1].mRegister = BC_REG_ACCU;
mIns[i + 2].mRegister = BC_REG_ACCU;
mIns[i + 1].mLive |= LIVE_ACCU;
progress = true;
}
#if 1
else if (
i + 3 == mIns.Size() && mFalseJump &&
mIns[i + 0].mCode == BC_STORE_REG_8 &&
mIns[i + 1].mCode == BC_LOAD_REG_8 &&
mIns[i + 2].mCode == BC_BINOP_CMPUR_8 && mIns[i + 0].mRegister == mIns[i + 2].mRegister && !(mExitLive & LIVE_ACCU) && mIns[i + 2].mRegisterFinal
)
{
mIns[i + 0].mCode = BC_NOP;
mIns[i + 1].mCode = BC_NOP;
mIns[i + 2].mRegister = mIns[i + 1].mRegister;
mIns[i + 2].mRegisterFinal = mIns[i + 1].mRegisterFinal;
mBranch = TransposeBranchCondition(mBranch);
progress = true;
}
#endif
}
#endif
#if 1
@ -5019,6 +5157,37 @@ bool ByteCodeBasicBlock::PeepHoleOptimizer(int phase)
progress = true;
}
#endif
else if (
mIns[i + 1].mCode == BC_STORE_REG_8 && !(mIns[i + 1].mLive & LIVE_ACCU) && mIns[i + 1].mRegister != BC_REG_ADDR &&
(mIns[i + 0].mCode == BC_LOAD_ADDR_8 || mIns[i + 0].mCode == BC_LOAD_ADDR_U8 || mIns[i + 0].mCode == BC_LOAD_ADDR_16 || mIns[i + 0].mCode == BC_LOAD_ADDR_32) &&
mIns[i + 0].mRegister == BC_REG_ACCU)
{
mIns[i + 0].mCode = BC_LOAD_ADDR_8;
mIns[i + 0].mRegister = mIns[i + 1].mRegister;
mIns[i + 1].mCode = BC_NOP;
progress = true;
}
else if (
mIns[i + 1].mCode == BC_STORE_REG_8 && !(mIns[i + 1].mLive & LIVE_ACCU) && mIns[i + 1].mRegister != BC_REG_ADDR &&
(mIns[i + 0].mCode == BC_LOAD_ABS_8 || mIns[i + 0].mCode == BC_LOAD_ABS_U8 || mIns[i + 0].mCode == BC_LOAD_ABS_16 || mIns[i + 0].mCode == BC_LOAD_ABS_32) &&
mIns[i + 0].mRegister == BC_REG_ACCU)
{
mIns[i + 0].mCode = BC_LOAD_ABS_8;
mIns[i + 0].mRegister = mIns[i + 1].mRegister;
mIns[i + 1].mCode = BC_NOP;
progress = true;
}
else if (
mIns[i + 1].mCode == BC_STORE_REG_8 && !(mIns[i + 1].mLive & LIVE_ACCU) && mIns[i + 1].mRegister != BC_REG_ADDR &&
(mIns[i + 0].mCode == BC_LOAD_LOCAL_8 || mIns[i + 0].mCode == BC_LOAD_LOCAL_U8 || mIns[i + 0].mCode == BC_LOAD_LOCAL_16 || mIns[i + 0].mCode == BC_LOAD_LOCAL_32) &&
mIns[i + 0].mRegister == BC_REG_ACCU)
{
mIns[i + 0].mCode = BC_LOAD_LOCAL_8;
mIns[i + 0].mRegister = mIns[i + 1].mRegister;
mIns[i + 1].mCode = BC_NOP;
progress = true;
}
#if 1
else if (
mIns[i + 0].mCode == BC_CONST_16 && mIns[i + 0].mRegister == BC_REG_ACCU &&
@ -5577,6 +5746,10 @@ void ByteCodeProcedure::Compile(ByteCodeGenerator* generator, InterCodeProcedure
}
} while (progress);
ResetVisited();
entryBlock->PropagateAccuCrossBorder(-1, -1);
#endif
entryBlock->Assemble(generator);
@ -5633,8 +5806,7 @@ ByteCodeGenerator::ByteCodeGenerator(Errors* errors, Linker* linker)
mExtByteCodes[i] = nullptr;
}
mByteCodeUsed[BC_LEA_ABS] = 1;
mByteCodeUsed[BC_CALL] = 1;
mByteCodeUsed[BC_CALL_ABS] = 1;
mByteCodeUsed[BC_EXIT] = 1;
mByteCodeUsed[BC_NATIVE] = 1;

View File

@ -148,16 +148,17 @@ enum ByteCode
BC_SET_LT,
BC_SET_LE,
BC_JSR,
BC_NATIVE = 0x75,
BC_ENTER,
BC_RETURN,
BC_CALL,
BC_CALL_ADDR,
BC_CALL_ABS,
BC_PUSH_FRAME,
BC_POP_FRAME,
BC_JSR,
BC_COPY,
BC_COPY_LONG,
BC_STRCPY,
@ -292,10 +293,13 @@ public:
void BinaryIntOperator(InterCodeProcedure* proc, const InterInstruction * ins, ByteCode code);
void NumericConversion(InterCodeProcedure* proc, const InterInstruction * ins);
void CollectEntryBlocks(ByteCodeBasicBlock * block);
bool JoinTailCodeSequences(void);
bool SameTail(ByteCodeInstruction& ins);
bool PropagateAccuCrossBorder(int accu, int addr);
bool PeepHoleOptimizer(int phase);
};

View File

@ -540,8 +540,12 @@ void ByteCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int star
fprintf(file, "RETURN\t%d, %d", memory[start + i], uint16(memory[start + i + 1] + 256 * memory[start + i + 2]));
i += 3;
break;
case BC_CALL:
fprintf(file, "CALL");
case BC_CALL_ADDR:
fprintf(file, "CALL\tADDR");
break;
case BC_CALL_ABS:
fprintf(file, "CALL\t%s", AddrName(uint16(memory[start + i + 0] + 256 * memory[start + i + 1]), abuffer, linker));
i += 2;
break;
case BC_JSR:
fprintf(file, "JSR\t%s", AddrName(uint16(memory[start + i + 0] + 256 * memory[start + i + 1]), abuffer, linker));

View File

@ -492,7 +492,7 @@ bool InterInstruction::ReferencesTemp(int temp) const
return true;
for (int i = 0; i < mNumOperands; i++)
if (mSrc[i].mTemp == temp)
return temp;
return true;
return false;
}
@ -4800,7 +4800,7 @@ void InterCodeBasicBlock::PeepholeOptimization(void)
limit -= 1;
int i = limit;
#if 1
while (i >= 0)
{
// move loads down
@ -4843,7 +4843,7 @@ void InterCodeBasicBlock::PeepholeOptimization(void)
i--;
}
#endif
i = 0;
while (i < mInstructions.Size())
{
@ -4933,6 +4933,7 @@ void InterCodeBasicBlock::PeepholeOptimization(void)
mInstructions[i + 0]->mSrc[0].mIntConst = ~((1LL << shift) - 1);
changed = true;
}
#if 1
else if (
mInstructions[i + 1]->mCode == IC_LOAD_TEMPORARY && mExitRequiredTemps[mInstructions[i + 1]->mDst.mTemp] &&
(!mExitRequiredTemps[mInstructions[i + 1]->mSrc[0].mTemp] ||
@ -4944,6 +4945,7 @@ void InterCodeBasicBlock::PeepholeOptimization(void)
mInstructions[i + 1]->mSrc[0].mTemp = mInstructions[i + 0]->mDst.mTemp;
changed = true;
}
#endif
else if (
mInstructions[i + 0]->mDst.mTemp >= 0 &&
mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && IsCommutative(mInstructions[i + 1]->mOperator) && mInstructions[i + 0]->mDst.mTemp == mInstructions[i + 1]->mSrc[0].mTemp && mInstructions[i + 0]->mDst.mTemp != mInstructions[i + 1]->mSrc[1].mTemp)
@ -4954,7 +4956,7 @@ void InterCodeBasicBlock::PeepholeOptimization(void)
changed = true;
}
#if 1
// Postincrement artifact
if (mInstructions[i + 0]->mCode == IC_LOAD_TEMPORARY && mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR &&
mInstructions[i + 1]->mSrc[0].mTemp < 0 &&
@ -4977,6 +4979,7 @@ void InterCodeBasicBlock::PeepholeOptimization(void)
changed = true;
}
}
#endif
}