Merge pull request #2735 from kugelfuhr/kugelfuhr/fix-2025
Add an optimization that removes compare instructions preceeding RTS or function calls
This commit is contained in:
1
.github/checks/lastline.sh
vendored
1
.github/checks/lastline.sh
vendored
@@ -23,3 +23,4 @@ if [ x"$FILES"x != xx ]; then
|
||||
done
|
||||
exit -1
|
||||
fi
|
||||
exit 0
|
||||
|
||||
1
.github/checks/lineendings.sh
vendored
1
.github/checks/lineendings.sh
vendored
@@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then
|
||||
done
|
||||
exit -1
|
||||
fi
|
||||
exit 0
|
||||
|
||||
1
.github/checks/noexec.sh
vendored
1
.github/checks/noexec.sh
vendored
@@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then
|
||||
done
|
||||
exit -1
|
||||
fi
|
||||
exit 0
|
||||
|
||||
1
.github/checks/sorted.sh
vendored
1
.github/checks/sorted.sh
vendored
@@ -36,3 +36,4 @@ function checkarray_quoted_name
|
||||
for N in `grep -rl "BEGIN SORTED.SH" "$CHECK_DIR"`; do
|
||||
checkarray_quoted_name $N
|
||||
done
|
||||
exit 0
|
||||
|
||||
5
.github/checks/sorted_codeopt.sh
vendored
5
.github/checks/sorted_codeopt.sh
vendored
@@ -63,6 +63,7 @@ function checkarray
|
||||
}
|
||||
|
||||
|
||||
for N in `grep -rl "BEGIN DECL SORTED_CODEOPT.SH" "$CHECK_DIR"`; do
|
||||
checkarray $N
|
||||
find "$CHECK_DIR" -name \*.\[ch\] -print | while read N; do
|
||||
grep -q "BEGIN DECL SORTED_CODEOPT.SH" "$N" && checkarray $N
|
||||
done
|
||||
exit 0
|
||||
|
||||
2
.github/checks/sorted_opcodes.sh
vendored
2
.github/checks/sorted_opcodes.sh
vendored
@@ -37,4 +37,4 @@ function checkarray_quoted_name
|
||||
for N in `grep -rl "BEGIN SORTED_OPCODES.SH" "$CHECK_DIR"`; do
|
||||
checkarray_quoted_name $N
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
||||
1
.github/checks/spaces.sh
vendored
1
.github/checks/spaces.sh
vendored
@@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then
|
||||
done
|
||||
exit -1
|
||||
fi
|
||||
exit 0
|
||||
|
||||
1
.github/checks/tabs.sh
vendored
1
.github/checks/tabs.sh
vendored
@@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then
|
||||
done
|
||||
exit -1
|
||||
fi
|
||||
exit 0
|
||||
|
||||
@@ -133,6 +133,7 @@ static OptFunc DOptCmp2 = { OptCmp2, "OptCmp2", 85, 0,
|
||||
static OptFunc DOptCmp3 = { OptCmp3, "OptCmp3", 75, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptCmp4 = { OptCmp4, "OptCmp4", 75, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptCmp5 = { OptCmp5, "OptCmp5", 100, 0, 0, 0, 0, 0 };
|
||||
static OptFunc DOptCmp6 = { OptCmp6, "OptCmp6", 33, 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 DOptCmp9 = { OptCmp9, "OptCmp9", 85, 0, 0, 0, 0, 0 };
|
||||
@@ -255,6 +256,7 @@ static OptFunc* OptFuncs[] = {
|
||||
&DOptCmp3,
|
||||
&DOptCmp4,
|
||||
&DOptCmp5,
|
||||
&DOptCmp6,
|
||||
&DOptCmp7,
|
||||
&DOptCmp8,
|
||||
&DOptCmp9,
|
||||
@@ -729,6 +731,7 @@ static unsigned RunOptGroup3 (CodeSeg* S)
|
||||
C += RunOptFunc (S, &DOptCondBranch3, 1);
|
||||
C += RunOptFunc (S, &DOptCondBranchC, 1);
|
||||
C += RunOptFunc (S, &DOptRTSJumps1, 1);
|
||||
C += RunOptFunc (S, &DOptCmp6, 1); /* After OptRTSJumps1 */
|
||||
C += RunOptFunc (S, &DOptBoolCmp, 1);
|
||||
C += RunOptFunc (S, &DOptBoolTrans, 1);
|
||||
C += RunOptFunc (S, &DOptBNegA2, 1); /* After OptCondBranch's */
|
||||
|
||||
@@ -503,6 +503,51 @@ unsigned OptCmp5 (CodeSeg* S)
|
||||
|
||||
|
||||
|
||||
unsigned OptCmp6 (CodeSeg* S)
|
||||
/* Remove compare instructions before an RTS or an subroutine call that doesn't
|
||||
** use 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 something else.
|
||||
** Note: The test could be improved by checking the flag usage of the
|
||||
** function explicitly against the flags set by the compare instruction.
|
||||
** For current code generation this makes no difference, however.
|
||||
*/
|
||||
if ((E->Info & OF_CMP) != 0 &&
|
||||
(N = CS_GetNextEntry (S, I)) != 0 &&
|
||||
(N->OPC == OP65_RTS || /* Either RTS, or ... */
|
||||
(N->OPC == OP65_JSR && /* ... or JSR ... */
|
||||
N->JumpTo == 0 && /* ... to external ... */
|
||||
(N->Use & PSTATE_ALL) == 0 && /* ... with no flags used ... */
|
||||
(N->Chg & PSTATE_ALL) == PSTATE_ALL))) { /* ... but all destroyed */
|
||||
|
||||
/* Found, remove the compare */
|
||||
CS_DelEntry (S, I);
|
||||
++Changes;
|
||||
}
|
||||
|
||||
/* Next entry */
|
||||
++I;
|
||||
}
|
||||
|
||||
/* Return the number of changes made */
|
||||
return Changes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned OptCmp7 (CodeSeg* S)
|
||||
/* Search for a sequence ldx/txa/branch and remove the txa if A is not
|
||||
** used later.
|
||||
|
||||
@@ -123,6 +123,11 @@ unsigned OptCmp5 (CodeSeg* S);
|
||||
** jne/jeq L2
|
||||
*/
|
||||
|
||||
unsigned OptCmp6 (CodeSeg* S);
|
||||
/* Remove compare instructions before an RTS or an exit by jumping to some
|
||||
** other function.
|
||||
*/
|
||||
|
||||
unsigned OptCmp7 (CodeSeg* S);
|
||||
/* Search for a sequence ldx/txa/branch and remove the txa if A is not
|
||||
** used later.
|
||||
|
||||
Reference in New Issue
Block a user