From: spth Date: Sun, 4 Jan 2009 00:39:44 +0000 (+0000) Subject: RFE #2484693 and peephole improvements X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c04cbf8f911eb7d49d830339f2f820ecce377125;p=fw%2Fsdcc RFE #2484693 and peephole improvements git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5322 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index a881bddc..98af0831 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-01-04 Philipp Klaus Krause + + * src/z80/peep.c: + Implemented RFE #2484693. + * src/z80/peeph-z80.def: + Some peephole improvements. + 2009-01-03 Borut Razem * as/link/lklibr.c: diff --git a/src/z80/peep.c b/src/z80/peep.c index 43781745..affdf190 100644 --- a/src/z80/peep.c +++ b/src/z80/peep.c @@ -192,15 +192,23 @@ findLabel (const lineNode *pl) return NULL; } +/* Check if reading arg implies reading what. */ +static bool argCont(const char *arg, const char *what) +{ + if(arg[0] == '#') + return FALSE; + return(strstr(arg, what));; +} + static bool z80MightRead(const lineNode *pl, const char *what) { - if(strcmp(pl->line, "call\t__initrleblock") == 0) - return TRUE; - if(strcmp(what, "iyl") == 0 || strcmp(what, "iyh") == 0) what = "iy"; + if(strcmp(pl->line, "call\t__initrleblock") == 0) + return TRUE; + if(strncmp(pl->line, "call\t", 5) == 0 && strchr(pl->line, ',') == 0) return FALSE; @@ -224,14 +232,22 @@ z80MightRead(const lineNode *pl, const char *what) if(strncmp(pl->line, "adc\t", 4) == 0 || strncmp(pl->line, "add\t", 4) == 0 || strncmp(pl->line, "and\t", 4) == 0 || - strncmp(pl->line, "or\t", 3) == 0 || strncmp(pl->line, "sbc\t", 4) == 0 || strncmp(pl->line, "sub\t", 4) == 0 || strncmp(pl->line, "xor\t", 4) == 0) { - if( strstr(pl->line + 3, what) != 0) + if(argCont(pl->line + 4, what)) return TRUE; - if( strstr(pl->line + 3, "hl") == 0 && strcmp("a", what) == 0) + if(strstr(pl->line + 4, "hl") == 0 && strcmp("a", what) == 0) + return TRUE; + return FALSE; + } + + if(strncmp(pl->line, "or\t", 3) == 0) + { + if(argCont(pl->line + 3, what)) + return TRUE; + if(strcmp("a", what) == 0) return TRUE; return FALSE; } @@ -245,13 +261,20 @@ z80MightRead(const lineNode *pl, const char *what) if( strncmp(pl->line, "dec\t", 4) == 0 || strncmp(pl->line, "inc\t", 4) == 0 || - strncmp(pl->line, "rl\t", 3) == 0 || - strncmp(pl->line, "rr\t", 3) == 0 || + strncmp(pl->line, "rl\t", 4) == 0 || + strncmp(pl->line, "rr\t", 4) == 0 || strncmp(pl->line, "sla\t", 4) == 0 || strncmp(pl->line, "sra\t", 4) == 0 || strncmp(pl->line, "srl\t", 4) == 0) { - return (strstr(pl->line + 3, what) != 0); + return (argCont(pl->line + 4, what)); + } + + if( + strncmp(pl->line, "rl\t", 3) == 0 || + strncmp(pl->line, "rr\t", 3) == 0) + { + return (argCont(pl->line + 3, what)); } if(strncmp(pl->line, "jp\t", 3) == 0 || diff --git a/src/z80/peeph-z80.def b/src/z80/peeph-z80.def index 6c258c09..c50c48e6 100644 --- a/src/z80/peeph-z80.def +++ b/src/z80/peeph-z80.def @@ -141,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 @@ -240,6 +250,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 @@ -533,7 +569,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 {