Rewrite the optimization step from c0a1b1b887 to

remove compares not only before RTS but also befoire function calls that don't
use the flags but destroy all of them. The latter is currently the case for
all functions called. This way the optimization covers a lot more cases than
just checking for RTS.
This commit is contained in:
Kugel Fuhr
2025-06-25 20:07:36 +02:00
parent 1feeee9ce0
commit 55d9b2dbd0
3 changed files with 53 additions and 45 deletions

View File

@@ -129,11 +129,11 @@ static OptFunc DOptBoolUnary3 = { OptBoolUnary3, "OptBoolUnary3", 40, 0,
static OptFunc DOptBranchDist = { OptBranchDist, "OptBranchDist", 0, 0, 0, 0, 0, 0 };
static OptFunc DOptBranchDist2 = { OptBranchDist2, "OptBranchDist2", 0, 0, 0, 0, 0, 0 };
static OptFunc DOptCmp1 = { OptCmp1, "OptCmp1", 42, 0, 0, 0, 0, 0 };
static OptFunc DOptCmp10 = { OptCmp10, "OptCmp10", 33, 0, 0, 0, 0, 0 };
static OptFunc DOptCmp2 = { OptCmp2, "OptCmp2", 85, 0, 0, 0, 0, 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 };
@@ -252,11 +252,11 @@ static OptFunc* OptFuncs[] = {
&DOptBranchDist,
&DOptBranchDist2,
&DOptCmp1,
&DOptCmp10,
&DOptCmp2,
&DOptCmp3,
&DOptCmp4,
&DOptCmp5,
&DOptCmp6,
&DOptCmp7,
&DOptCmp8,
&DOptCmp9,
@@ -731,7 +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, &DOptCmp10, 1); /* After OptRTSJumps1 */
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 */