X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fz80%2Fpeeph-z80.def;h=6d43c9b2439c503ca1d660a50ee2256ddffc6695;hb=80972b2e54c9b88f11c27b878874fd2a6a681391;hp=b34a6b0dd1457912282bf438875f225836f20465;hpb=0a04254e69623ab8772a291cac7e3a09fb7d7f7a;p=fw%2Fsdcc diff --git a/src/z80/peeph-z80.def b/src/z80/peeph-z80.def index b34a6b0d..6d43c9b2 100644 --- a/src/z80/peeph-z80.def +++ b/src/z80/peeph-z80.def @@ -62,7 +62,7 @@ replace restart { ld a,%3 (%1) } by { ; peephole 0d loaded %2 into a directly instead of going through %1. - ld a,(#%2 + %3) + ld a,(#%2+%3) } if notUsed(%1) replace restart { @@ -84,6 +84,18 @@ replace restart { 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 @@ -92,7 +104,7 @@ replace restart { } by { ld l,e ld h,d - ; peephole 0g incremented in hl instead of de. + ; peephole 0h' incremented in hl instead of de. inc hl inc hl } if notUsed('de') @@ -129,6 +141,16 @@ replace restart { 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 @@ -137,6 +159,24 @@ replace restart { 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 @@ -156,6 +196,16 @@ replace restart { 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 @@ -220,6 +270,32 @@ replace restart { 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 @@ -341,7 +417,7 @@ replace restart { ; peephole 0zf used hl instead of iy. ld hl,#%1 + %2 ld (hl), %4 -} if notUsed('iy'), notUsed('hl') +} if notUsed('iy'), notUsed('hl'), operandsNotRelated(%4 'h'), operandsNotRelated(%4 'l') replace restart { ld e,l @@ -389,6 +465,17 @@ replace restart { ld hl, #%1 + %2 } if notUsed('bc') +replace restart { + ld c, %1 (%2) + ld b, %3 (%4) + ld l,c + ld h,b +} by { + ; peephole 0zk' stored %1 (%2) %3 (%4) into hl directly instead of going through bc. + ld l, %1 (%2) + ld h, %3 (%4) +} if notUsed('bc') + replace restart { jp NC,%1 jp %2 @@ -502,7 +589,17 @@ replace restart { } by { ld %1,a or a,%2 - ; peephole 17 removed load by reordering or arguments. + ; peephole 17a removed load by reordering or arguments. +} if notVolatile(%1) + +replace restart { + ld %1,a + ld a,%2 (ix) + or a,%1 +} by { + ld %1,a + or a,%2 (ix) + ; peephole 17b removed load by reordering or arguments. } if notVolatile(%1) replace restart { @@ -762,12 +859,60 @@ replace restart { //add %3, %4 } by { add a, a - ; peephole 42b shifts in accumulator insted of %1 + ; peephole 42b shifted in accumulator insted of %1 ld %1, a ld a, %2 //add %3, %4 } +// 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 + sla %1 + ld a, %2 + //add %3, %4 +} by { + add a, a + add a, a + ; peephole 42b' shifted in accumulator insted of %1 + ld %1, a + ld a, %2 + //add %3, %4 +} + +replace restart { + ld l,%1 (ix) + ld h,%2 (ix) + ld a,(hl) + inc a + ld l,%1 (ix) + ld h,%2 (ix) + ld (hl),a +} by { + ld l,%1 (ix) + ld h,%2 (ix) + inc (hl) + ; peephole 42c incremented in (hl) instead of going through a. +} if notUsed('a') + +replace restart { + ld l,%1 (ix) + ld h,%2 (ix) + ld a,(hl) + dec a + ld l,%1 (ix) + ld h,%2 (ix) + ld (hl),a +} by { + ld l,%1 (ix) + ld h,%2 (ix) + dec (hl) + ; peephole 42d decremented in (hl) instead of going through a. +} if notUsed('a') + replace restart { ld %1,a ld a,%2 @@ -891,17 +1036,18 @@ replace restart { // ; peephole 50 shortened or using a (which has just been tested to be #0x00). //} if operandsNotSame3(%3 '(bc)' '(de)') -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). -} +// Commented out sine it triggers for %3 od the form (#...) +//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). +//} //if operandsNotSame3(%3 '(bc)' '(de)') replace restart { @@ -1102,12 +1248,70 @@ replace restart { } if operandsNotRelated('h' %3) // Don't check for volatile since ix points to the stack. +replace restart { + ld %1, a + ld a, %2 (%3) + adc a, #%4 + ld l, %1 +} by { + ld l, a + ld a, %2 (%3) + adc a, #%4 + ; peephole 76 loaded l from a directly instead of going through %1. +} if notUsed(%1) + +replace restart { + ld %1, a + ld a, #%2 + adc a, #%3 + ld l, %1 +} by { + ld l, a + ld a, #%2 + adc a, #%3 + ; peephole 77 loaded l from a directly instead of going through %1. +} if notUsed(%1) + +replace restart { + ld hl, #%1 + add hl, %2 + ex de, hl + ld hl, #%3 + add hl, de +} by { + ld hl, #%1+%3 + add hl, %2 + ; peephole 78 removed addition and loads exploiting commutativity of addition. +} if notUsed('de') + +replace restart { + ex de, hl + ld hl, #%1 + add hl, de +} by { + ; peephole 78a removed ex exploiting commutativity of addition. + ld de, #%1 + add hl, de +} if notUsed('de') + +replace restart { + ld hl, #%1 + add hl, %2 + ex de, hl + inc de +} by { + ld hl, #%1+1 + ; peephole 79 moved increment to constant. + add hl, %2 + ex de, hl +} if notUsed('hl') + // These ex-generating rules should be among the last ones since ex counts as a read from both hl and de for notUsed(). replace restart { ld d,h ld e,l } by { - ; peephole 73 used ex to load hl into de. + ; peephole 80 used ex to load hl into de. ex de,hl } if notUsed('hl') @@ -1115,7 +1319,7 @@ replace restart { ld e,l ld d,h } by { - ; peephole 74 used ex to load hl into de. + ; peephole 81 used ex to load hl into de. ex de,hl } if notUsed('hl') @@ -1123,7 +1327,7 @@ replace restart { ld l,e ld h,d } by { - ; peephole 75 used ex to load de into hl. + ; peephole 82 used ex to load de into hl. ex de,hl } if notUsed('de')