Reverse shift with negated distance
This commit is contained in:
parent
d3e7a991a4
commit
e1736c8214
|
@ -6358,6 +6358,20 @@ static bool ispow2(int64 v)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int binlog(int64 n)
|
||||
{
|
||||
int k = -1;
|
||||
|
||||
while (n)
|
||||
{
|
||||
n >>= 1;
|
||||
k++;
|
||||
}
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
|
||||
void InterCodeBasicBlock::CheckValueUsage(InterInstruction * ins, const GrowingInstructionPtrArray& tvalue, const GrowingVariableArray& staticVars, const GrowingInterCodeProcedurePtrArray& staticProcs, FastNumberSet& fsingle)
|
||||
{
|
||||
switch (ins->mCode)
|
||||
|
@ -20552,6 +20566,61 @@ bool InterCodeBasicBlock::PeepholeReplaceOptimization(const GrowingVariableArray
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
if (i + 1 < mInstructions.Size())
|
||||
{
|
||||
if (mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 0]->mOperator == IA_SUB &&
|
||||
mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 1]->mOperator == IA_SHL &&
|
||||
mInstructions[i + 1]->mSrc[0].mTemp == mInstructions[i + 0]->mDst.mTemp && mInstructions[i + 1]->mSrc[0].mFinal && mInstructions[i + 1]->mSrc[0].IsUByte() &&
|
||||
mInstructions[i + 1]->mSrc[1].mTemp < 0 && ispow2(mInstructions[i + 1]->mSrc[1].mIntConst))
|
||||
{
|
||||
int64 k = binlog(mInstructions[i + 1]->mSrc[1].mIntConst);
|
||||
|
||||
if (mInstructions[i + 0]->mSrc[0].mTemp >= 0 && mInstructions[i + 0]->mSrc[1].mTemp < 0)
|
||||
{
|
||||
int64 s = mInstructions[i + 0]->mSrc[1].mIntConst;
|
||||
mInstructions[i + 0]->mSrc[1] = mInstructions[i + 0]->mSrc[0];
|
||||
mInstructions[i + 0]->mSrc[0].mTemp = -1;
|
||||
mInstructions[i + 0]->mSrc[0].mIntConst = mInstructions[i + 0]->mSrc[1].mRange.mMinValue;
|
||||
mInstructions[i + 0]->mDst.mRange.SetLimit(0, mInstructions[i + 0]->mSrc[1].mRange.mMaxValue - mInstructions[i + 0]->mSrc[0].mIntConst);
|
||||
mInstructions[i + 1]->mOperator = IA_SHR;
|
||||
mInstructions[i + 1]->mSrc[0] = mInstructions[i + 0]->mDst;
|
||||
int64 d = s - mInstructions[i + 0]->mSrc[0].mIntConst;
|
||||
if (d < 0)
|
||||
mInstructions[i + 1]->mSrc[1].mIntConst >>= -d;
|
||||
else
|
||||
mInstructions[i + 1]->mSrc[1].mIntConst <<= d;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (mInstructions[i + 0]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 0]->mOperator == IA_SUB &&
|
||||
mInstructions[i + 1]->mCode == IC_BINARY_OPERATOR && mInstructions[i + 1]->mOperator == IA_SHR &&
|
||||
mInstructions[i + 1]->mSrc[0].mTemp == mInstructions[i + 0]->mDst.mTemp && mInstructions[i + 1]->mSrc[0].mFinal && mInstructions[i + 1]->mSrc[0].IsUByte() &&
|
||||
mInstructions[i + 1]->mSrc[1].mTemp < 0 && ispow2(mInstructions[i + 1]->mSrc[1].mIntConst))
|
||||
{
|
||||
int64 k = binlog(mInstructions[i + 1]->mSrc[1].mIntConst);
|
||||
|
||||
if (mInstructions[i + 0]->mSrc[0].mTemp >= 0 && mInstructions[i + 0]->mSrc[1].mTemp < 0)
|
||||
{
|
||||
int64 s = mInstructions[i + 0]->mSrc[1].mIntConst;
|
||||
mInstructions[i + 0]->mSrc[1] = mInstructions[i + 0]->mSrc[0];
|
||||
mInstructions[i + 0]->mSrc[0].mTemp = -1;
|
||||
mInstructions[i + 0]->mSrc[0].mIntConst = mInstructions[i + 0]->mSrc[1].mRange.mMinValue;
|
||||
mInstructions[i + 0]->mDst.mRange.SetLimit(0, mInstructions[i + 0]->mSrc[1].mRange.mMaxValue - mInstructions[i + 0]->mSrc[0].mIntConst);
|
||||
mInstructions[i + 1]->mOperator = IA_SHL;
|
||||
mInstructions[i + 1]->mSrc[0] = mInstructions[i + 0]->mDst;
|
||||
int64 d = s - mInstructions[i + 0]->mSrc[0].mIntConst;
|
||||
if (d < 0)
|
||||
mInstructions[i + 1]->mSrc[1].mIntConst <<= -d;
|
||||
else
|
||||
mInstructions[i + 1]->mSrc[1].mIntConst >>= d;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -22927,7 +22996,7 @@ void InterCodeProcedure::Close(void)
|
|||
{
|
||||
GrowingTypeArray tstack(IT_NONE);
|
||||
|
||||
CheckFunc = !strcmp(mIdent->mString, "main");
|
||||
CheckFunc = !strcmp(mIdent->mString, "test");
|
||||
CheckCase = false;
|
||||
|
||||
mEntryBlock = mBlocks[0];
|
||||
|
|
Loading…
Reference in New Issue