From bbebbe3a1b86ae04b49f0fc37f3b9ecc86a955fb Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 26 Jul 2001 06:40:06 +0000 Subject: [PATCH] More optimizations git-svn-id: svn://svn.cc65.org/cc65/trunk@824 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codeopt.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index b9eb3d118..3f1fd1913 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -923,6 +923,50 @@ static unsigned OptCmp5 (CodeSeg* S) +static unsigned OptCmp6 (CodeSeg* S) +/* Search for a sequence ldx/txa/branch and remove the txa if A is not + * used later. + */ +{ + unsigned Changes = 0; + + /* Walk over the entries */ + unsigned I = 0; + while (I < CS_GetEntryCount (S)) { + + CodeEntry* L[2]; + + /* Get next entry */ + CodeEntry* E = CS_GetEntry (S, I); + + /* Check for the sequence */ + if ((E->OPC == OP65_LDX || E->OPC == OP65_TAX) && + CS_GetEntries (S, L, I+1, 2) && + L[0]->OPC == OP65_TXA && + !CE_HasLabel (L[0]) && + (L[1]->Info & OF_FBRA) != 0 && + !CE_HasLabel (L[1]) && + !RegAUsed (S, I+3)) { + + /* Remove the txa */ + CS_DelEntry (S, I+1); + + /* Remember, we had changes */ + ++Changes; + + } + + /* Next entry */ + ++I; + + } + + /* Return the number of changes made */ + return Changes; +} + + + /*****************************************************************************/ /* Optimize tests */ /*****************************************************************************/ @@ -1428,6 +1472,7 @@ static OptFunc OptFuncs [] = { { OptCmp3, "OptCmp3", 0 }, { OptCmp4, "OptCmp4", 0 }, { OptCmp5, "OptCmp5", 0 }, + { OptCmp6, "OptCmp6", 0 }, /* Optimize tests */ { OptTest1, "OptTest1", 0 }, /* Remove unused loads */ -- 2.39.5