+ jp %3,%4
+ ; peephole 34 removed load by replacing sub with cp
+ assert a=%1
+}
+
+replace restart {
+ assert a=%1
+} by {
+}
+
+replace restart {
+ sub a,#0xFF
+ jp Z,%1
+} by {
+ inc a
+ ; peephole 35 replaced sub a,#0xFF by inc a.
+ jp Z,%1
+}
+
+replace restart {
+ sub a,#0xFF
+ jp NZ,%1
+} by {
+ inc a
+ ; peephole 36 replaced sub a,#0xFF by inc a.
+ jp NZ,%1
+}
+
+replace restart {
+ ld bc,#%1 + %2
+ ld a,c
+ add a,%3
+ ld c,a
+ ld a,b
+ adc a,%4
+ ld b,a
+} by {
+ ld a,#<(%1 + %2)
+ add a,%3
+ ld c,a
+ ld a,#>(%1 + %2)
+ ; peephole 37 directly used (%1 + %2) in calculation instead of placing it in bc first.
+ adc a,%4
+ ld b,a
+}
+
+replace restart {
+ ld de,#%1 + %2
+ ld a,e
+ add a,%3
+ ld e,a
+ ld a,d
+ adc a,%4
+ ld d,a
+} by {
+ ld a,#<(%1 + %2)
+ add a,%3
+ ld e,a
+ ld a,#>(%1 + %2)
+ ; peephole 38 directly used (%1 + %2) in calculation instead of placing it in de first.
+ adc a,%4
+ ld d,a
+}
+
+replace restart {
+ rlca
+ ld a,#0x00
+ rla
+} by {
+ rlca
+ and a,#0x01
+ ; peephole 39 replaced zero load, rla by and since rlca writes the same value to carry bit and least significant bit.
+}
+
+replace restart {
+ ld %1,%2
+ push %1
+ pop %4
+ ld %1,%3
+} by {
+ ld %4,%2
+ ; peephole 40 moved %2 directly into de instead of going through %1.
+ ld %1,%3
+}
+
+replace restart {
+ add a,#0x00
+ ld %2,a
+ ld a,%3
+ adc a,%4
+} by {
+ ; peephole 41 removed lower part of multibyte addition.
+ ld %2,a
+ ld a,%3
+ add a,%4
+}
+
+replace restart {
+ ld %1,a
+ ld a,%2
+ add a,%1
+ ld %1,a
+} by {
+ ; peephole 42 removed loads by exploiting commutativity of addition.
+ add a,%2
+ ld %1,a
+} if notVolatile(%1)
+
+// sdcc does not use the H flag. sla resets it, while add sets it.
+// To ensure that the state of the H flag is not changed by this
+// peephole uncomment the add %3, %4 at the end (since it overwrite the H flag).
+replace restart {
+ ld %1, a
+ sla %1
+ ld a, %2
+ //add %3, %4
+} by {
+ add a, a
+ ; peephole 42a shifts in accumulator insted of %1
+ ld %1, a
+ ld a, %2
+ //add %3, %4
+}
+
+replace restart {
+ ld %1,a
+ ld a,%2
+ add a,%1
+} by {
+ ld %1, a
+ ; peephole 43 removed load by exploiting commutativity of addition.
+ add a,%2
+}
+
+replace restart {
+ or a,%1
+ jp NZ,%2
+ xor a,a
+ or a,%3
+} by {
+ or a,%1
+ jp NZ,%2
+ ; peephole 44 removed redundant zeroing of a (which has just been tested to be #0x00).
+ or a,%3
+}
+
+replace restart {
+ or a,%1
+ jp NZ,%2
+ ld %3,#0x00
+} by {
+ or a,%1
+ jp NZ,%2
+ ld %3,a
+ ; peephole 45 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ and a,%1
+ jp NZ,%2
+ ld %3,#0x00
+} by {
+ and a,%1
+ jp NZ,%2
+ ld %3,a
+ ; peephole 46 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ sub a,%1
+ jp NZ,%2
+ ld %3,#0x00
+} by {
+ sub a,%1
+ jp NZ,%2
+ ld %3,a
+ ; peephole 47 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ dec a
+ jp NZ,%1
+ ld %2,#0x00
+} by {
+ dec a
+ jp NZ,%1
+ ld %2,a
+ ; peephole 48 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ or a,%1
+ jp NZ,%2
+ ld a,%3
+ or a,a
+} by {
+ or a,%1
+ jp NZ,%2
+ or a,%3
+ ; peephole 49 shortened or using a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ and a,%1
+ jp NZ,%2
+ ld a,%3
+ or a,a
+} by {
+ and a,%1
+ jp NZ,%2
+ or a,%3
+ ; peephole 50 shortened or using a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ sub a,%1
+ jp NZ,%2
+ ld a,%3
+ or a,a
+} by {
+ sub a,%1
+ jp NZ,%2
+ or a,%3
+ ; peephole 51 shortened or using a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ dec a
+ jp NZ,%1
+ ld a,%2
+ or a,a
+} by {
+ dec a
+ jp NZ,%1
+ or a,%2
+ ; peephole 52 shortened or using a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ or a,%1
+ jp NZ,%2
+ push %3
+ ld %4,#0x00
+} by {
+ or a,%1
+ jp NZ,%2
+ push %3
+ ld %4,a
+ ; peephole 53 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ and a,%1
+ jp NZ,%2
+ push %3
+ ld %4,#0x00
+} by {
+ sub a,%1
+ jp NZ,%2
+ push %3
+ ld %4,a
+ ; peephole 54 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ sub a,%1
+ jp NZ,%2
+ push %3
+ ld %4,#0x00
+} by {
+ sub a,%1
+ jp NZ,%2
+ push %3
+ ld %4,a
+ ; peephole 55 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ dec a
+ jp NZ,%1
+ push %2
+ ld %3,#0x00
+} by {
+ dec a
+ jp NZ,%1
+ push %2
+ ld %3,a
+ ; peephole 56 replaced constant #0x00 by a (which has just been tested to be #0x00).
+}
+
+replace restart {
+ ld de,#%1 + %2
+ inc de
+ inc de
+ inc de
+} by {
+ ld de,#%1 + %2 + 3
+ ; peephole 57 moved triple increment of de to constant.
+}
+
+replace restart {
+ ld de,#%1 + %2
+ inc de
+ inc de
+} by {
+ ld de,#%1 + %2 + 2
+ ; peephole 58 moved double increment of de to constant.
+}
+
+replace restart {
+ ld de,#%1 + %2
+ inc de
+} by {
+ ld de,#%1 + %2 + 1
+ ; peephole 59 moved increment of de to constant.
+}
+
+replace restart {
+ ld bc,#%1 + %2
+ inc bc
+ inc bc
+ inc bc
+} by {
+ ld bc,#%1 + %2 + 3
+ ; peephole 60 moved triple increment of bc to constant.
+}
+
+replace restart {
+ ld bc,#%1 + %2
+ inc bc
+ inc bc
+} by {
+ ld bc,#%1 + %2 + 2
+ ; peephole 61 moved double increment of bc to constant.
+}
+
+replace restart {
+ ld bc,#%1 + %2
+ inc bc
+} by {
+ ld bc,#%1 + %2 + 1
+ ; peephole 62 moved increment of bc to constant.
+}
+
+replace restart {
+ ld bc,#%1
+ ld a,c
+ add a,#0x%2
+ ld c,a
+ ld a,b
+ adc a,#0x%3
+ ld b,a
+} by {
+ ld bc,#%1 + 0x%3%2
+ ; peephole 63 moved addition of constant 0x%3%2 to bc to constant.
+}
+
+replace restart {
+ ld bc,#%1 + %4
+ ld a,c
+ add a,#0x%2
+ ld c,a
+ ld a,b
+ adc a,#0x%3
+ ld b,a
+} by {
+ ld bc,#%1 + %4 + 0x%3%2
+ ; peephole 64 moved addition of constant 0x%3%2 to bc to constant.
+}
+
+replace restart {
+ call %1
+ ret
+} by {
+ jp %1
+ ; peephole 65 replaced call at end of function by jump.
+}
+
+// Callee saves ix.
+replace restart {
+ call %1
+ pop ix
+ ret
+} by {
+ pop ix
+ jp %1
+ ; peephole 66 replaced call at end of function by jump moving call beyond pop ix.