diff --git a/.github/checks/lastline.sh b/.github/checks/lastline.sh index d243a01e1..6bb6e0dc5 100755 --- a/.github/checks/lastline.sh +++ b/.github/checks/lastline.sh @@ -23,3 +23,4 @@ if [ x"$FILES"x != xx ]; then done exit -1 fi +exit 0 diff --git a/.github/checks/lineendings.sh b/.github/checks/lineendings.sh index 5b445522f..5baac514e 100755 --- a/.github/checks/lineendings.sh +++ b/.github/checks/lineendings.sh @@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then done exit -1 fi +exit 0 diff --git a/.github/checks/noexec.sh b/.github/checks/noexec.sh index c76ae481d..5e53fe869 100755 --- a/.github/checks/noexec.sh +++ b/.github/checks/noexec.sh @@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then done exit -1 fi +exit 0 diff --git a/.github/checks/sorted.sh b/.github/checks/sorted.sh index 4f53b0484..b5451a21f 100755 --- a/.github/checks/sorted.sh +++ b/.github/checks/sorted.sh @@ -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 diff --git a/.github/checks/sorted_codeopt.sh b/.github/checks/sorted_codeopt.sh index c78662b9d..cfca028dd 100755 --- a/.github/checks/sorted_codeopt.sh +++ b/.github/checks/sorted_codeopt.sh @@ -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 diff --git a/.github/checks/sorted_opcodes.sh b/.github/checks/sorted_opcodes.sh index 3e45ea752..34156bde6 100755 --- a/.github/checks/sorted_opcodes.sh +++ b/.github/checks/sorted_opcodes.sh @@ -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 diff --git a/.github/checks/spaces.sh b/.github/checks/spaces.sh index e231f6c2d..f2eea6f3f 100755 --- a/.github/checks/spaces.sh +++ b/.github/checks/spaces.sh @@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then done exit -1 fi +exit 0 diff --git a/.github/checks/tabs.sh b/.github/checks/tabs.sh index 80dac3f2d..ed8d45bac 100755 --- a/.github/checks/tabs.sh +++ b/.github/checks/tabs.sh @@ -16,3 +16,4 @@ if [ x"$FILES"x != xx ]; then done exit -1 fi +exit 0 diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index e3869d786..988e2d770 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -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 */ diff --git a/src/cc65/coptcmp.c b/src/cc65/coptcmp.c index eb138e78d..41245b58d 100644 --- a/src/cc65/coptcmp.c +++ b/src/cc65/coptcmp.c @@ -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. diff --git a/src/cc65/coptcmp.h b/src/cc65/coptcmp.h index 98e75715b..268e55be2 100644 --- a/src/cc65/coptcmp.h +++ b/src/cc65/coptcmp.h @@ -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.