From: uz Date: Thu, 12 Jul 2012 21:12:50 +0000 (+0000) Subject: Fixed a problem with the optimizations for shifts. X-Git-Tag: V2.14~288 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=eef430e45a35d941d4a9aa1cb18938c8ef53ef85;p=cc65 Fixed a problem with the optimizations for shifts. git-svn-id: svn://svn.cc65.org/cc65/trunk@5783 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index 4cd577879..0919002cf 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -840,13 +840,6 @@ static unsigned Opt_tosshift (StackOpData* D, const char* Name) /* Store the value into the zeropage instead of pushing it */ ReplacePushByStore (D); - /* Inline the shift */ - D->IP = D->OpIndex+1; - - /* tay */ - X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->OpEntry->LI); - InsertEntry (D, X, D->IP++); - /* If the lhs is direct (but not stack relative), we can just reload the * data later. */ @@ -856,6 +849,13 @@ static unsigned Opt_tosshift (StackOpData* D, const char* Name) CodeEntry* LoadX = D->Lhs.X.LoadEntry; CodeEntry* LoadA = D->Lhs.A.LoadEntry; + /* Inline the shift */ + D->IP = D->OpIndex+1; + + /* tay */ + X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->OpEntry->LI); + InsertEntry (D, X, D->IP++); + /* lda */ X = NewCodeEntry (OP65_LDA, LoadA->AM, LoadA->Arg, 0, D->OpEntry->LI); InsertEntry (D, X, D->IP++); @@ -874,6 +874,15 @@ static unsigned Opt_tosshift (StackOpData* D, const char* Name) AddStoreX (D); AddStoreA (D); + /* Be sure to setup IP after adding the stores, otherwise it will get + * messed up. + */ + D->IP = D->OpIndex+1; + + /* tay */ + X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->OpEntry->LI); + InsertEntry (D, X, D->IP++); + /* lda zp */ X = NewCodeEntry (OP65_LDA, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI); InsertEntry (D, X, D->IP++); @@ -888,7 +897,7 @@ static unsigned Opt_tosshift (StackOpData* D, const char* Name) X = NewCodeEntry (OP65_JSR, AM65_ABS, Name, 0, D->OpEntry->LI); InsertEntry (D, X, D->IP++); - /* Remove the push and the call to the tossubax function */ + /* Remove the push and the call to the shift function */ RemoveRemainders (D); /* We changed the sequence */