Add an optimization step that removes compare instructions preceeding an RTS.
Since nothing is passed back in the flags, these instructions have no effect. Fixes #2025.
This commit is contained in:
@@ -136,6 +136,7 @@ static OptFunc DOptCmp5 = { OptCmp5, "OptCmp5", 100, 0,
|
|||||||
static OptFunc DOptCmp7 = { OptCmp7, "OptCmp7", 85, 0, 0, 0, 0, 0 };
|
static OptFunc DOptCmp7 = { OptCmp7, "OptCmp7", 85, 0, 0, 0, 0, 0 };
|
||||||
static OptFunc DOptCmp8 = { OptCmp8, "OptCmp8", 50, 0, 0, 0, 0, 0 };
|
static OptFunc DOptCmp8 = { OptCmp8, "OptCmp8", 50, 0, 0, 0, 0, 0 };
|
||||||
static OptFunc DOptCmp9 = { OptCmp9, "OptCmp9", 85, 0, 0, 0, 0, 0 };
|
static OptFunc DOptCmp9 = { OptCmp9, "OptCmp9", 85, 0, 0, 0, 0, 0 };
|
||||||
|
static OptFunc DOptCmp10 = { OptCmp10, "OptCmp10", 33, 0, 0, 0, 0, 0 };
|
||||||
static OptFunc DOptComplAX1 = { OptComplAX1, "OptComplAX1", 65, 0, 0, 0, 0, 0 };
|
static OptFunc DOptComplAX1 = { OptComplAX1, "OptComplAX1", 65, 0, 0, 0, 0, 0 };
|
||||||
static OptFunc DOptCondBranch1 = { OptCondBranch1, "OptCondBranch1", 80, 0, 0, 0, 0, 0 };
|
static OptFunc DOptCondBranch1 = { OptCondBranch1, "OptCondBranch1", 80, 0, 0, 0, 0, 0 };
|
||||||
static OptFunc DOptCondBranch2 = { OptCondBranch2, "OptCondBranch2", 40, 0, 0, 0, 0, 0 };
|
static OptFunc DOptCondBranch2 = { OptCondBranch2, "OptCondBranch2", 40, 0, 0, 0, 0, 0 };
|
||||||
@@ -251,6 +252,7 @@ static OptFunc* OptFuncs[] = {
|
|||||||
&DOptBranchDist,
|
&DOptBranchDist,
|
||||||
&DOptBranchDist2,
|
&DOptBranchDist2,
|
||||||
&DOptCmp1,
|
&DOptCmp1,
|
||||||
|
&DOptCmp10,
|
||||||
&DOptCmp2,
|
&DOptCmp2,
|
||||||
&DOptCmp3,
|
&DOptCmp3,
|
||||||
&DOptCmp4,
|
&DOptCmp4,
|
||||||
@@ -729,6 +731,7 @@ static unsigned RunOptGroup3 (CodeSeg* S)
|
|||||||
C += RunOptFunc (S, &DOptCondBranch3, 1);
|
C += RunOptFunc (S, &DOptCondBranch3, 1);
|
||||||
C += RunOptFunc (S, &DOptCondBranchC, 1);
|
C += RunOptFunc (S, &DOptCondBranchC, 1);
|
||||||
C += RunOptFunc (S, &DOptRTSJumps1, 1);
|
C += RunOptFunc (S, &DOptRTSJumps1, 1);
|
||||||
|
C += RunOptFunc (S, &DOptCmp10, 1); /* After OptRTSJumps1 */
|
||||||
C += RunOptFunc (S, &DOptBoolCmp, 1);
|
C += RunOptFunc (S, &DOptBoolCmp, 1);
|
||||||
C += RunOptFunc (S, &DOptBoolTrans, 1);
|
C += RunOptFunc (S, &DOptBoolTrans, 1);
|
||||||
C += RunOptFunc (S, &DOptBNegA2, 1); /* After OptCondBranch's */
|
C += RunOptFunc (S, &DOptBNegA2, 1); /* After OptCondBranch's */
|
||||||
|
|||||||
@@ -741,3 +741,40 @@ unsigned OptCmp9 (CodeSeg* S)
|
|||||||
/* Return the number of changes made */
|
/* Return the number of changes made */
|
||||||
return Changes;
|
return Changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
unsigned OptCmp10 (CodeSeg* S)
|
||||||
|
/* Remove compare instructions before an RTS. This is safe since no C function
|
||||||
|
** passes back something in the flags.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
unsigned Changes = 0;
|
||||||
|
unsigned I;
|
||||||
|
|
||||||
|
/* Walk over the entries */
|
||||||
|
I = 0;
|
||||||
|
while (I < CS_GetEntryCount (S)) {
|
||||||
|
|
||||||
|
CodeEntry* N;
|
||||||
|
|
||||||
|
/* Get next entry */
|
||||||
|
CodeEntry* E = CS_GetEntry (S, I);
|
||||||
|
|
||||||
|
/* Check for a compare followed by an RTS */
|
||||||
|
if ((E->Info & OF_CMP) != 0 && /* Compare insn */
|
||||||
|
(N = CS_GetNextEntry (S, I)) != 0 && /* Next entry ... */
|
||||||
|
N->OPC == OP65_RTS) { /* ... is RTS */
|
||||||
|
|
||||||
|
/* Found, remove the compare */
|
||||||
|
CS_DelEntry (S, I);
|
||||||
|
++Changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Next entry */
|
||||||
|
++I;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the number of changes made */
|
||||||
|
return Changes;
|
||||||
|
}
|
||||||
|
|||||||
@@ -146,6 +146,11 @@ unsigned OptCmp9 (CodeSeg* S);
|
|||||||
** flag instead of the carry flag and remove the asl.
|
** flag instead of the carry flag and remove the asl.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
unsigned OptCmp10 (CodeSeg* S);
|
||||||
|
/* Remove compare instructions before an RTS. This is safe since no C function
|
||||||
|
** passes back something in the flags.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* End of coptcmp.h */
|
/* End of coptcmp.h */
|
||||||
|
|||||||
Reference in New Issue
Block a user