1 // Due to major changes in the Z80 peepholes the old peepholes from peeph.def have been moved here.
2 // All new peepholes went into peeph-z80.def. A GBZ80 expert should look into this files and peeph-z80.def
3 // And move peepholes that are useful and correct for both Z80 and GBZ80 into peeph.def.
5 // peeph.def - Common Z80 and gbz80 peephole rules
8 // (c) Philipp Klaus Krause (pkk@spth.de, philipp@colecovision.eu) 2006 - 2007
10 // This program is free software; you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 2, or (at your option) any
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ; peephole 1 removed redundant load.
36 ; peephole 3 removed jp by using inverse jump logic
38 } if labelRefCountChange(%1 -1)
46 ; peephole 4 removed jp by using inverse jump logic
48 } if labelRefCountChange(%1 -1)
56 ; peephole 5 removed jp by using inverse jump logic
58 } if labelRefCountChange(%1 -1)
66 ; peephole 6 removed jp by using inverse jump logic
68 } if labelRefCountChange(%1 -1)
74 ; peephole 7 redirected jump-to-jump at %5 by jump to %6
75 } if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
81 ; peephole 8 redirected jump-to-jump at %5 by jump to %6
82 } if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
91 ; peephole 9 removed jump and redundant load.
95 } if labelRefCountChange(%4 -1)
102 ; peephole 10 removed redundant load of 0 into a.
110 ; peephole 11 combined constant loads into register pair.
118 ; peephole 12 combined constant loads into register pair.
126 ; peephole 13 combined constant loads into register pair.
134 ; peephole 14 removed redundant load from %1 into a.
136 // This gives many false negatives and without the test no problems are encountered in the regression tests
137 // Maybe we can try this after 2.7.0 release
144 ; peephole 15 removed redundant load from a into %1.
146 // This gives many false negatives and without the test no problems are encountered in the regression tests
147 // Maybe we can try this after 2.7.0 release
156 ; peephole 16 moved %3 directly into a instead of going through %2.
159 } if notVolatile(%2), operandsNotSame
168 ; peephole 17 removed load by reordering or arguments.
178 ; peephole 18 used value still in a instead of loading it from %1.
186 ; peephole 19 removed redundant or after or.
194 ; peephole 20 removed redundant or after and.
202 ; peephole 21 removed redundant or after xor.
210 ; peephole 22 removed redundant load into %1.
221 ; peephole 23 load value in a first and use it next
222 } if notVolatile(%1 %2)
232 ; peephole 24 removed redundant load from %3%1 into %4%2
233 } if notVolatile(%1 %2 %3 %4)
241 ; peephole 25 removed load into b
251 ; peephole 26 removed load into c
261 ; peephole 27 removed load into d
271 ; peephole 28 removed load into e
281 ; peephole 29 removed load into h
291 ; peephole 30 removed load into l
307 ; peephole 31 moved and pushed arguments c and #%2 through bc instead of pushing them individually.
323 ; peephole 32 moved and pushed arguments e and #%2 through de instead of pushing them individually.
336 ; peephole 33 removed load by replacing sub with cp
348 ; peephole 34 removed load by replacing sub with cp
362 ; peephole 35 replaced sub a,#0xFF by inc a.
371 ; peephole 36 replaced sub a,#0xFF by inc a.
388 ; peephole 37 directly used (%1 + %2) in calculation instead of placing it in bc first.
406 ; peephole 38 directly used (%1 + %2) in calculation instead of placing it in de first.
418 ; peephole 39 replaced zero load, rla by and since rlca writes the same value to carry bit and least significant bit.
428 ; peephole 40 moved %2 directly into de instead of going through %1.
438 ; peephole 41 removed lower part of multibyte addition.
450 ; peephole 42 removed loads by exploiting commutativity of addition.
455 // sdcc does not use the H flag. sla resets it, while add sets it.
456 // To ensure that the state of the H flag is not changed by this
457 // peephole uncomment the add %3, %4 at the end (since it overwrite the H flag).
465 ; peephole 42a shifts in accumulator insted of %1
477 ; peephole 43 removed load by exploiting commutativity of addition.
489 ; peephole 44 removed redundant zeroing of a (which has just been tested to be #0x00).
501 ; peephole 45 replaced constant #0x00 by a (which has just been tested to be #0x00).
512 ; peephole 46 replaced constant #0x00 by a (which has just been tested to be #0x00).
523 ; peephole 47 replaced constant #0x00 by a (which has just been tested to be #0x00).
534 ; peephole 48 replaced constant #0x00 by a (which has just been tested to be #0x00).
546 ; peephole 49 shortened or using a (which has just been tested to be #0x00).
558 ; peephole 50 shortened or using a (which has just been tested to be #0x00).
570 ; peephole 51 shortened or using a (which has just been tested to be #0x00).
582 ; peephole 52 shortened or using a (which has just been tested to be #0x00).
595 ; peephole 53 replaced constant #0x00 by a (which has just been tested to be #0x00).
608 ; peephole 54 replaced constant #0x00 by a (which has just been tested to be #0x00).
621 ; peephole 55 replaced constant #0x00 by a (which has just been tested to be #0x00).
634 ; peephole 56 replaced constant #0x00 by a (which has just been tested to be #0x00).
644 ; peephole 57 moved triple increment of de to constant.
653 ; peephole 58 moved double increment of de to constant.
661 ; peephole 59 moved increment of de to constant.
671 ; peephole 60 moved triple increment of bc to constant.
680 ; peephole 61 moved double increment of bc to constant.
688 ; peephole 62 moved increment of bc to constant.
701 ; peephole 63 moved addition of constant 0x%3%2 to bc to constant.
713 ld bc,#%1 + %4 + 0x%3%2
714 ; peephole 64 moved addition of constant 0x%3%2 to bc to constant.
722 ; peephole 65 replaced call at end of function by jump.
733 ; peephole 66 replaced call at end of function by jump moving call beyond pop ix.
736 // Old gbz80 rules from here onward