+
+replace restart {
+ ld bc,#%1 + %2 + %6
+ ld a,%3
+ ld (bc),a
+%7:
+ ld bc,#%4 + %5
+} by {
+ ld a,%3
+ ld (#%1 + %2 + %6),a
+ ; peephole z7 directly used address #%1 + %2 + %6 instead of placing it in bc first.
+%7:
+ ld bc,#%4 + %5
+}
+
+replace restart {
+ ld c,%1
+ ld l,c
+ ret
+} by {
+ ld l,%1
+ ; peephole z8 moved %1 directly into l instead of going through c.
+ ret
+}
+
+replace restart {
+ ld b,h
+ ld c,l
+ pop af
+ push bc
+ call %1
+} by {
+ ex (sp),hl
+ ; peephole z9 moved hl directly to the stack instead of going through bc.
+ call %1
+}
+
+replace restart {
+ ld d,h
+ ld e,l
+ pop af
+ push de
+ call %1
+} by {
+ ex (sp),hl
+ ; peephole z10 moved hl directly to the stack instead of going through de.
+ call %1
+}
+
+replace restart {
+ jp %5
+} by {
+ ret
+ ; peephole z11 replaced jump by return.
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
+
+replace restart {
+ jp %1,%5
+} by {
+ ret %1
+ ; peephole z11a replaced jump by return.
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
+
+// Should be one of the last ones. Opens the code to further peephole optimization.
+replace restart {
+%1:
+} by {
+ ; peephole z12 removed unused label %1.
+} if labelRefCount(%1 0)
+
+// Applying z11 or z11a followed by z12 will often leave a dead ret at the end of the function. Remove it.
+replace {
+ jp %5
+ ret
+} by {
+ jp %5
+ ; peephole z13 removed unused ret.
+}
+
+// These should be the last rules, so that the peepholes above need to look at jp only.
+replace {
+ jp %5
+} by {
+ jr %5
+ ; peephole z14 changed absolute to relative unconditional jump.
+} if labelInRange()
+
+replace {
+ jp Z,%5
+} by {
+ jr Z,%5
+ ; peephole z15 changed absolute to relative conditional jump.
+} if labelInRange()
+
+replace {
+ jp NZ,%5
+} by {
+ jr NZ,%5
+ ; peephole z16 changed absolute to relative conditional jump.
+} if labelInRange()
+
+replace {
+ jp C,%5
+} by {
+ jr C,%5
+ ; peephole z17 changed absolute to relative conditional jump.
+} if labelInRange()
+
+replace {
+ jp NC,%5
+} by {
+ jr NC,%5
+ ; peephole z18 changed absolute to relative conditional jump.
+} if labelInRange()