Just disable OptPushPop if N/Z is used after the PLA.

This is a more conservative way to fix Issue #971.
This commit is contained in:
acqn 2020-01-03 07:43:51 +08:00 committed by Oliver Schmidt
parent 6d530931bf
commit dc5114b071
1 changed files with 6 additions and 8 deletions

View File

@ -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;