+ ld %1,%1
+} by {
+ ; peephole -1 removed redundant load.
+} if notVolatile(%1)
+
+// This one doesn't work currently since the peephole optimizer can't match lines generated by multiline macros: Bug #1570701
+//replace restart {
+// pop af
+// ld sp,%1
+//} by {
+// ; peephole -1a eleminated dead pop.
+// ld sp,%1
+//} if notUsed('a')
+
+replace restart {
+ ld %1,%2
+} by {
+ ; peephole 0a removed dead load from %2 into %1.
+} if notVolatile(%1), notUsed(%1)
+// Should probably check for notVolatile(%2), too, but gives many false positives and no regression tests fail.
+
+replace restart {
+ ld %1,%2
+ ld a,%1
+} by {
+ ; peephole 0b loaded %2 into a directly instead of going through %1.
+ ld a,%2
+} if notVolatile(%1), notUsed(%1)
+
+replace restart {
+ ld %1,%2 (%3)
+ ld a,%1
+} by {
+ ; peephole 0c loaded %2 (%3) into a directly instead of going through %1.
+ ld a,%2 (%3)
+} if notVolatile(%1), notUsed(%1)
+
+replace restart {
+ ld %1,#%2
+ ld a,%3 (%1)
+} by {
+ ; peephole 0d loaded %2 into a directly instead of going through %1.
+ ld a,(#%2+%3)
+} if notUsed(%1)
+
+replace restart {
+ srl %1
+ ld a,%1
+} by {
+ ld a,%1
+ ; peephole 0e shifted in a instead of %1.
+ srl a
+} if notVolatile(%1), notUsed(%1)
+
+replace restart {
+ ld %1,(hl)
+ ld a,%2 (%3)
+ sub a,%1
+} by {
+ ld a,%2 (%3)
+ ; peephole 0f used (hl) in sub directly instead of going through %1.
+ sub a,(hl)
+} if notVolatile(%1), notUsed(%1)
+
+replace restart {
+ inc bc
+ ld l,c
+ ld h,b
+} by {
+ ld l,c
+ ld h,b
+ ; peephole 0g incremented in hl instead of bc.
+ inc hl
+} if notUsed('bc')
+
+// Catch double and triple incs before later peepholes introduce an ex de,hl in here.
+replace restart {
+ inc de
+ inc de
+ ld l,e
+ ld h,d
+} by {
+ ld l,e
+ ld h,d
+ ; peephole 0h' incremented in hl instead of de.
+ inc hl
+ inc hl
+} if notUsed('de')
+
+replace restart {
+ inc de
+ ld l,e
+ ld h,d
+} by {
+ ld l,e
+ ld h,d
+ ; peephole 0h incremented in hl instead of de.
+ inc hl
+} if notUsed('de')
+
+replace restart {
+ ld e,%1
+ ld d,%2
+ ld l,e
+ ld h,d
+} by {
+ ; peephole 0i loaded %2%1 into hl directly instead of going through de.
+ ld l,%1
+ ld h,%2
+} if notUsed('de')
+
+replace restart {
+ ld bc,#%2 + %3
+ ld a,(bc)
+ ld c,a
+} by {
+ ; peephole 0j used hl for #%2 + %3 instead of bc, not going through a.
+ ld hl,#%2 + %3
+ ld c,(hl)
+} if notUsed('a'), notUsed('hl')
+
+replace restart {
+ ld de,#%2 + %3
+ ld a,(de)
+ ld e,a
+} by {
+ ; peephole 0j' used hl for #%2 + %3 instead of de, not going through a.
+ ld hl,#%2 + %3
+ ld e,(hl)
+} if notUsed('a'), notUsed('hl')
+
+replace restart {
+ ex de,hl
+ push hl
+} by {
+ ; peephole 0k pushed de directly instead of going through hl.
+ push de
+} if notUsed('de'), notUsed('hl')
+
+replace restart {
+ ex de,hl
+ push de
+} by {
+ ; peephole 0k' pushed hl directly instead of going through de.
+ push hl
+} if notUsed('de'), notUsed('hl')
+
+replace restart {
+ ld l,%1
+ ld h,d
+ push hl
+} by {
+ ; peephole 0k'' pushed de instead of hl removing a load.
+ ld e,%1
+ push de
+} if notUsed('hl'), notUsed('e')
+
+replace restart {
+ ex de,hl
+ push bc
+ push de
+} by {
+ ; peephole 0l pushed hl directly instead of going through de.
+ push bc
+ push hl
+} if notUsed('de'), notUsed('hl')
+
+replace restart {
+ ld l,c
+ ld h,b
+ push hl
+} by {
+ ; peephole 0m pushed bc directly instead of going through hl.
+ push bc
+} if notUsed('hl')
+
+replace restart {
+ ld l,%1
+ ld h,b
+ push hl
+} by {
+ ; peephole 0m' pushed bc instead of hl removing a load.
+ ld c,%1
+ push bc
+} if notUsed('hl'), notUsed('c')
+
+replace restart {
+ ld c,a
+ push de
+ ld a,c
+} by {
+ ; peephole 0n removed redundant load of a through c.
+ push de
+} if notUsed('c')
+
+replace restart {
+ ld c,e
+ ld b,d
+ ld a,(bc)
+} by {
+ ; peephole 0o used de directly instead of going through bc.
+ ld a,(de)
+} if notUsed('bc')
+
+replace restart {
+ pop de
+ ld l,e
+ ld h,d
+} by {
+ ; peephole 0p popped hl directly instead of going through de.
+ pop hl
+} if notUsed('de')
+
+replace restart {
+ ld %1,a
+ ld %2 (%3),%1
+} by {
+ ; peephole 0q loaded a into %2 (%3) directly instead of going through %1.
+ ld %2 (%3),a
+} if notVolatile(%1), notUsed(%1)
+
+replace restart {
+ ld %1 (ix),%2
+ ld %3, %1 (ix)
+} by {
+ ; peephole 0r loaded %3 from %2 instead of going through %1 (ix).
+ ld %1 (ix),%2
+ ld %3, %2
+}
+// Don't need to check for volatile, since ix is used for the stack.
+
+replace restart {
+ ld %1, %2 (%3)
+ ld b, %1
+} by {
+ ; peephole 0s loaded b from %2 (%3) instead of going through %1.
+ ld b, %2 (%3)
+} if notVolatile(%1), notUsed(%1)
+
+// Bug #2728445
+//replace restart {
+// ld %1,a
+// ld %2,%3
+// ld %4,%1
+//} by {
+// ; peephole 0t loaded %4 from a instead of going through %1.
+// ld %1,a
+// ld %2,%3
+// ld %4,a
+//} if notVolatile(%1), operandsNotRelated(%1 %3), operandsNotRelated(%1 %2)
+
+replace restart {
+ ld %1,a
+ ld a,%2
+ adc a,#%3
+ ld %4,%1
+} by {
+ ld %1,a
+ ; peephole 0t' loaded %4 from a instead of going through %1.
+ ld %4,a
+ ld a,%2
+ adc a,#%3
+} if notVolatile(%1), operandsNotRelated(%1 %2), operandsNotRelated(%4 %2)
+
+replace restart {
+ ld %1,a
+ ld a,#%2
+ adc a,#%3
+ ld %4,%1
+} by {
+ ld %1,a
+ ; peephole 0t'' loaded %4 from a instead of going through %1.
+ ld %4,a
+ ld a,#%2
+ adc a,#%3
+} if notVolatile(%1)
+
+replace restart {
+ ld %1,(hl)
+ ld e,%1
+} by {
+ ; peephole 0u loaded e from (hl) instead of going through %1.
+ ld e,(hl)
+} if notUsed(%1)
+
+replace restart {
+ ld %1,l
+ ld %2 (%3),%1
+} by {
+ ; peephole 0v loaded %2 (%3) from l instead of going through %1.
+ ld %2 (%3),l
+} if notUsed(%1)
+
+replace restart {
+ ld l,%1 (ix)
+ ld h,%2 (ix)
+ ld %3,(hl)
+ srl %3
+ ld l,%1 (ix)
+ ld h,%2 (ix)
+ ld (hl),%3
+} by {
+ ld l,%1 (ix)
+ ld h,%2 (ix)
+ ; peephole 0w shifted (hl) in place.
+ srl (hl)
+ ld %3,(hl)
+} if notVolatile(%3)
+// Don't check for volatile since ix points to the stack.
+
+replace restart {
+ push af
+ inc sp
+ ld a,e
+ push af
+ inc sp
+} by {
+ ; peephole 0x pushed de instead of pushing a twice.
+ ld d,a
+ push de
+} if notUsed('d'), notUsed('a')
+
+replace restart {
+ push af
+ inc sp
+ ld a,c
+ push af
+ inc sp
+} by {
+ ; peephole 0y pushed bc instead of pushing a twice.
+ ld b,a
+ push bc
+} if notUsed('b'), notUsed('a')
+
+replace restart {
+ ld a,#%1
+ ld d,a
+} by {
+ ; peephole 0z loaded #%1 into d directly instead of going through a.
+ ld d,#%1
+} if notUsed('a')
+
+replace restart {
+ ld a,%1 (ix)
+ push af
+ inc sp
+ ld a,%2 (ix)
+ push af
+ inc sp
+} by {
+ ; peephole 0za pushed %1 (ix), %2(ix) through hl instead of af.
+ ld h,%1 (ix)
+ ld l,%2 (ix)
+ push hl
+} if notUsed('a'), notUsed('hl')
+
+replace restart {
+ ld c,l
+ ld b,h
+ push bc
+} by {
+ ; peephole 0zb pushed hl instead of bc.
+ push hl
+} if notUsed('bc')
+
+// Doesn'T work due to bug #1947081
+//replace restart {
+// pop %1
+// push %1
+//} by {
+// ; peephole 0zc eleminated dead pop/push pair.
+//} if notUsed(%1)
+
+replace restart {
+ ld iy,#%1
+ or a,%2 (iy)
+} by {
+ ; peephole 0zd used hl instead of iy.
+ ld hl,#%1 + %2
+ or a,(hl)
+} if notUsed('iy'), notUsed('hl')
+
+replace restart {
+ ld iy,#%1
+ ld %2,%3 (%4)
+} by {
+ ; peephole 0ze used hl instead of iy.
+ ld hl,#%1 + %3
+ ld %2,(hl)
+} if notUsed('iy'), notUsed('hl')
+
+replace restart {
+ ld iy,#%1
+ ld %2 (%3), %4
+} by {
+ ; peephole 0zf used hl instead of iy.
+ ld hl,#%1 + %2
+ ld (hl), %4
+} if notUsed('iy'), notUsed('hl'), operandsNotRelated(%4 'h'), operandsNotRelated(%4 'l')
+
+replace restart {
+ ld e,l
+ ld d,h
+ ld %1,(de)
+} by {
+ ; peephole 0zg loaded %1 from (hl) directly instead of going through (de).
+ ld %1,(hl)
+} if notUsed('de')
+
+replace restart {
+ ld c,l
+ ld b,h
+ ld %1,(bc)
+} by {
+ ; peephole 0zh loaded %1 from (hl) directly instead of going through (bc).
+ ld %1,(hl)
+} if notUsed('bc')
+
+replace restart {
+ ld c,l
+ ld b,h
+ inc bc
+} by {
+ ; peephole 0zi incremented in hl instead of bc.
+ inc hl
+ ld c,l
+ ld b,h
+} if notUsed('hl')
+
+replace restart {
+ ld a,%1 (%2)