+// peeph.def - Common Z80 and gbz80 peephole rules
+//
+//
+// (c) Philipp Klaus Krause (pkk@spth.de, philipp@colecovision.eu) 2006 - 2007
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option) any
+// later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+replace restart {
+ ld %1,%1
+} by {
+ ; peephole 1 removed redundant load.
+} if notVolatile(%1)
+
+replace restart {
+ jp NC,%1
+ jp %2
+%1:
+} by {
+ jp C,%2
+ ; peephole 3 removed jp by using inverse jump logic
+%1:
+} if labelRefCountChange(%1 -1)
+
+replace restart {
+ jp C,%1
+ jp %2
+%1:
+} by {
+ jp NC,%2
+ ; peephole 4 removed jp by using inverse jump logic
+%1:
+} if labelRefCountChange(%1 -1)
+
+replace restart {
+ jp NZ,%1
+ jp %2
+%1:
+} by {
+ jp Z,%2
+ ; peephole 5 removed jp by using inverse jump logic
+%1:
+} if labelRefCountChange(%1 -1)
+
+replace restart {
+ jp Z,%1
+ jp %2
+%1:
+} by {
+ jp NZ,%2
+ ; peephole 6 removed jp by using inverse jump logic
+%1:
+} if labelRefCountChange(%1 -1)
+
+replace restart {
+ jp %5
+} by {
+ jp %6
+ ; peephole 7 redirected jump-to-jump at %5 by jump to %6
+} if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
+
+replace restart {
+ jp %1,%5
+} by {
+ jp %1,%6
+ ; peephole 8 redirected jump-to-jump at %5 by jump to %6
+} if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
+
+replace restart {
+ ld %2,%3
+ jp %4
+%5:
+ ld %2,%3
+%4:
+} by {
+ ; peephole 9 removed jump and redundant load.
+%5:
+ ld %2,%3
+%4:
+} if labelRefCountChange(%4 -1)
+
+replace restart {
+ xor a,a
+ ld a,#0x00
+} by {
+ xor a,a
+ ; peephole 10 removed redundant load of 0 into a.
+}
+
+replace {
+ ld e,#0x%1
+ ld d,#0x%2
+} by {
+ ld de,#0x%2%1
+ ; peephole 11 combined constant loads into register pair.
+}
+