From 0ba44bb2d4b3203f322170b51792ac98bab1a23e Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 21 Nov 2002 01:08:14 +0000 Subject: [PATCH] Small but significant shift optimization git-svn-id: svn://svn.cc65.org/cc65/trunk@1559 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codeopt.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index a1d824d0a..01bba7b42 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -138,13 +138,18 @@ static unsigned OptShift1 (CodeSeg* S) static unsigned OptShift2 (CodeSeg* S) /* A call to the shraxN routine may get replaced by one or more lsr insns - * if the value of X is not used later. + * if the value of X is not used later, or if the value of X is known and + * zero. */ { unsigned Changes = 0; + unsigned I; + + /* Generate register info */ + CS_GenRegInfo (S); /* Walk over the entries */ - unsigned I = 0; + I = 0; while (I < CS_GetEntryCount (S)) { /* Get next entry */ @@ -155,13 +160,13 @@ static unsigned OptShift2 (CodeSeg* S) strncmp (E->Arg, "shrax", 5) == 0 && strlen (E->Arg) == 6 && IsDigit (E->Arg[5]) && - !RegXUsed (S, I+1)) { + (E->RI->In.RegX == 0 || !RegXUsed (S, I+1))) { /* Insert shift insns */ unsigned Count = E->Arg[5] - '0'; while (Count--) { CodeEntry* X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, E->LI); - CS_InsertEntry (S, X, I+1); + CS_InsertEntry (S, X, I+1); } /* Delete the call to shlax */ @@ -177,6 +182,9 @@ static unsigned OptShift2 (CodeSeg* S) } + /* Free the register info */ + CS_FreeRegInfo (S); + /* Return the number of changes made */ return Changes; } -- 2.39.5