From dc5114b0713fd4a8294e81dab83b8ecb59813d41 Mon Sep 17 00:00:00 2001
From: acqn <acqn163@outlook.com>
Date: Fri, 3 Jan 2020 07:43:51 +0800
Subject: [PATCH 147/170] Just disable OptPushPop if N/Z is used after the PLA.
This is a more conservative way to fix Issue #971.
---
src/cc65/coptind.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/cc65/coptind.c b/src/cc65/coptind.c
index 85901d0f..04deb011 100644
--- a/src/cc65/coptind.c
+++ b/src/cc65/coptind.c
@@ -1892,6 +1892,7 @@ unsigned OptPushPop (CodeSeg* S)
while (I < CS_GetEntryCount (S)) {
CodeEntry* X;
+ CodeEntry* N;
/* Get next entry */
CodeEntry* E = CS_GetEntry (S, I);
@@ -1944,7 +1945,9 @@ unsigned OptPushPop (CodeSeg* S)
if (E->OPC == OP65_STA &&
(E->AM == AM65_ABS || E->AM == AM65_ZP) &&
!CE_HasLabel (E) &&
- !RegAUsed (S, I+1) &&
+ ((N = CS_GetNextEntry (S, I)) == 0 ||
+ (!CE_UseLoadFlags (N) &&
+ !RegAUsed (S, I+1))) &&
!MemAccess (S, Push+1, Pop-1, E)) {
/* Insert a STA after the PHA */
@@ -1954,16 +1957,11 @@ unsigned OptPushPop (CodeSeg* S)
/* 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_DelEntry (S, Pop);
- CS_DelEntry (S, I);
+ CS_DelEntries (S, Pop, 2);
/* Correct I so we continue with the next insn */
- --I;
+ I -= 2;
/* Remember we had changes */
++Changes;
--
2.26.0