RFE #2484693 and peephole improvements
authorspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 4 Jan 2009 00:39:44 +0000 (00:39 +0000)
committerspth <spth@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 4 Jan 2009 00:39:44 +0000 (00:39 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5322 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/z80/peep.c
src/z80/peeph-z80.def

index a881bddcf6197bff00d8d12ca43a52a925c25b80..98af08314755d707e933cb6d4f2de3ac03ebc4ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-01-04 Philipp Klaus Krause <pkk AT spth.de>
+
+       * src/z80/peep.c:
+         Implemented RFE #2484693.
+       * src/z80/peeph-z80.def:
+         Some peephole improvements.
+
 2009-01-03 Borut Razem <borut.razem AT siol.net>
 
        * as/link/lklibr.c:
index 43781745ab9c2a55527be2efac4e5fd14297963a..affdf1905d45346794e8435d9a52cde803b0587a 100644 (file)
@@ -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 ||
index 6c258c09e468168acb30678f188cdd59c628ab02..c50c48e6ee548fa32898de7492986feb168a6285 100644 (file)
@@ -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 {