* src/z80/gen.c, src/z80/peeph.def: applied patch
[fw/sdcc] / src / z80 / peeph.def
index e80156af658f24913bef8ad716d4e43887e8fc36..02e485b79ef257fe8c0755dcf48f0176394fe643 100644 (file)
@@ -24,12 +24,12 @@ replace restart {
 } if notVolatile(%1)
 
 replace restart {
-       ld      %1,%2
        ld      %1,%3
+       ld      %1,%2
 } by {
        ; peephole 2 removed dead load into %1
-       ld      %1,%3
-} if notVolatile(%1)
+       ld      %1,%2
+} if notVolatile(%1 %3), operandsNotSame
 
 replace restart {
        jp      NC,%1
@@ -456,6 +456,22 @@ replace restart {
        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
@@ -702,4 +718,21 @@ replace restart {
        ; 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.
+}