Skip to content

Commit 7d24127

Browse files
committed
fix: fixes -O2 optimizer
Do not move pop XX instructions up when the are after an LD SP, NN
1 parent 24e5c52 commit 7d24127

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/arch/z80/peephole/opts/028_o2_pop_up.opt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ REPLACE {{
1818
}}
1919

2020
IF {{
21-
!(INSTR($2) IN (jp, jr, ret, call, djnz, rst)) && !NEEDS($2, (sp, $1)) && !IS_LABEL($2)
21+
!(INSTR($2) IN (jp, jr, ret, call, djnz, rst)) && !NEEDS($2, (sp, $1)) && !IS_LABEL($2) &&
22+
OP1($2) <> "sp" && OP2($2) <> "sp"
2223
}}
2324

2425
WITH {{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push iy
5+
ld iy, 0x5C3A ; ZX Spectrum ROM variables address
6+
ld hl, 0
7+
add hl, sp
8+
ld (.core.__CALL_BACK__), hl
9+
ei
10+
jp .core.__MAIN_PROGRAM__
11+
.core.__CALL_BACK__:
12+
DEFW 0
13+
.core.ZXBASIC_USER_DATA:
14+
; Defines USER DATA Length in bytes
15+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
16+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
17+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
18+
.core.ZXBASIC_USER_DATA_END:
19+
.core.__MAIN_PROGRAM__:
20+
ld hl, 0
21+
ld b, h
22+
ld c, l
23+
.core.__END_PROGRAM:
24+
di
25+
ld hl, (.core.__CALL_BACK__)
26+
ld sp, hl
27+
pop iy
28+
ei
29+
ret
30+
;; --- end of user code ---
31+
END
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REM Test empty program for prologue and epilogue
2+
REM for ZX Next using O2 optimizer

0 commit comments

Comments
 (0)