From 3b18880fb1ceb44d25f63a5ca57e282a7c2e6ac1 Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 4 Dec 2000 23:27:16 +0000 Subject: [PATCH] Optimize local immidiate stores git-svn-id: svn://svn.cc65.org/cc65/trunk@555 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/optimize.c | 49 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/cc65/optimize.c b/src/cc65/optimize.c index 8d24dfeac..5fa0ad561 100644 --- a/src/cc65/optimize.c +++ b/src/cc65/optimize.c @@ -1664,9 +1664,9 @@ static void OptLoads (void) * and replace it by: * * lda xx - * sta zzz - * lda yy * sta zzz+1 + * lda yy + * sta zzz * * provided that that the X register is not used later. While this is * no direct optimization, it helps with other optimizations. @@ -1678,10 +1678,47 @@ static void OptLoads (void) !RegXUsed (L2[2])) { /* Found - replace it */ - NewLineAfter (L2[1], "\tlda\t%s", L->Line+5); - L2[2]->Line[3] = 'a'; - FreeLine (L); - L = L2[2]; + L->Line[3] = 'a'; + NewLineAfter (L, "\tsta\t%s", L2[2]->Line+5); + FreeLine (L2[2]); + L = L2[1]; + + /* Search for: + * + * ldx xx + * lda yy + * ldy #$zz + * jsr staxysp + * + * and replace it by: + * + * lda xx + * ldy #$zz+1 + * sta (sp),y + * dey + * lda yy + * sta (sp),y + * + * provided that that the X register is not used later. This code + * sequence is two bytes longer, but a lot faster and it does not + * use the X register, so other loads may get removed later. + */ + } else if (LineMatch (L, "\tldx\t") && + GetNextCodeLines (L, L2, 3) && + LineMatch (L2 [0], "\tlda\t") && + LineMatch (L2 [1], "\tldy\t#$") && + LineFullMatch (L2 [2], "\tjsr\tstaxysp") && + !RegXUsed (L2[2])) { + + /* Found - replace it */ + L->Line[3] = 'a'; + L = NewLineAfter (L, "\tldy\t#$%02X", GetHexNum (L2[1]->Line+7)+1); + L = NewLineAfter (L, "\tsta\t(sp),y"); + L = NewLineAfter (L, "\tdey"); + L = NewLineAfter (L2[0], "\tsta\t(sp),y"); + + /* Remove the remaining lines */ + FreeLines (L2[1], L2[2]); } -- 2.39.5