From 9559625ee874434dff7a015191cb14e2303b96b3 Mon Sep 17 00:00:00 2001
From: acqn <acqn163@outlook.com>
Date: Tue, 31 Dec 2019 16:02:42 +0800
Subject: [PATCH 145/170] Always insert a LDA after the removed PLA during the
optimization in OptPushPop. Fixed Issue 971.
---
src/cc65/coptind.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/cc65/coptind.c b/src/cc65/coptind.c
index e35aa5be..318f9593 100644
--- a/src/cc65/coptind.c
+++ b/src/cc65/coptind.c
@@ -1948,17 +1948,22 @@ unsigned OptPushPop (CodeSeg* S)
!MemAccess (S, Push+1, Pop-1, E)) {
/* Insert a STA after the PHA */
- X = NewCodeEntry (E->OPC, E->AM, E->Arg, E->JumpTo, E->LI);
+ X = NewCodeEntry (OP65_STA, E->AM, E->Arg, E->JumpTo, E->LI);
CS_InsertEntry (S, X, Push+1);
/* Remove the PHA instead */
CS_DelEntry (S, Push);
+ /* Insert a LDA after the PLA */
+ X = NewCodeEntry (OP65_LDA, E->AM, E->Arg, E->JumpTo, CS_GetEntry (S, Pop)->LI);
+ CS_InsertEntry (S, X, Pop+1);
+
/* Remove the PLA/STA sequence */
- CS_DelEntries (S, Pop, 2);
+ CS_DelEntry (S, Pop);
+ CS_DelEntry (S, I);
/* Correct I so we continue with the next insn */
- I -= 2;
+ --I;
/* Remember we had changes */
++Changes;
--
2.26.0