1 // peeph.def - Common Z80 and gbz80 peephole rules
4 // (c) Philipp Klaus Krause (pkk@spth.de, philipp@colecovision.eu) 2006 - 2007
6 // This program is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option) any
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 ; peephole 1 removed redundant load.
30 ; peephole 2 removed dead load into %1
32 } if notVolatile(%1 %3), operandsNotSame
40 ; peephole 3 removed jp by using inverse jump logic
42 } if labelRefCountChange(%1 -1)
50 ; peephole 4 removed jp by using inverse jump logic
52 } if labelRefCountChange(%1 -1)
60 ; peephole 5 removed jp by using inverse jump logic
62 } if labelRefCountChange(%1 -1)
70 ; peephole 6 removed jp by using inverse jump logic
72 } if labelRefCountChange(%1 -1)
78 ; peephole 7 redirected jump-to-jump at %5 by jump to %6
79 } if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
85 ; peephole 8 redirected jump-to-jump at %5 by jump to %6
86 } if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
95 ; peephole 9 removed jump and redundant load.
99 } if labelRefCountChange(%4 -1)
106 ; peephole 10 removed redundant load of 0 into a.
114 ; peephole 11 combined constant loads into register pair.
122 ; peephole 12 combined constant loads into register pair.
130 ; peephole 13 combined constant loads into register pair.
138 ; peephole 14 removed redundant load from %1 into a.
140 // This gives many false negatives and without the test no problems are encountered in the regression tests
141 // Maybe we can try this after 2.7.0 release
148 ; peephole 15 removed redundant load from a into %1.
150 // This gives many false negatives and without the test no problems are encountered in the regression tests
151 // Maybe we can try this after 2.7.0 release
160 ; peephole 16 moved %3 directly into a instead of going through %2.
163 } if notVolatile(%2), operandsNotSame
172 ; peephole 17 removed load by reordering or arguments.
182 ; peephole 18 used value still in a instead of loading it from %1.
190 ; peephole 19 removed redundant or after or.
198 ; peephole 20 removed redundant or after and.
206 ; peephole 21 removed redundant or after xor.
214 ; peephole 22 removed redundant load into %1.
225 ; peephole 23 load value in a first and use it next
226 } if notVolatile(%1 %2)
236 ; peephole 24 removed redundant load from %3%1 into %4%2
237 } if notVolatile(%1 %2 %3 %4)
245 ; peephole 25 removed load into b
255 ; peephole 26 removed load into c
265 ; peephole 27 removed load into d
275 ; peephole 28 removed load into e
285 ; peephole 29 removed load into h
295 ; peephole 30 removed load into l
311 ; peephole 31 moved and pushed arguments c and #%2 through bc instead of pushing them individually.
327 ; peephole 32 moved and pushed arguments e and #%2 through de instead of pushing them individually.
340 ; peephole 33 removed load by replacing sub with cp
352 ; peephole 34 removed load by replacing sub with cp
366 ; peephole 35 replaced sub a,#0xFF by inc a.
375 ; peephole 36 replaced sub a,#0xFF by inc a.
392 ; peephole 37 directly used (%1 + %2) in calculation instead of placing it in bc first.
410 ; peephole 38 directly used (%1 + %2) in calculation instead of placing it in de first.
422 ; peephole 39 replaced zero load, rla by and since rlca writes the same value to carry bit and least significant bit.
432 ; peephole 40 moved %2 directly into de instead of going through %1.
442 ; peephole 41 removed lower part of multibyte addition.
454 ; peephole 42 removed loads by exploiting commutativity of addition.
459 // sdcc does not use the H flag. sla resets it, while add sets it.
460 // To ensure that the state of the H flag is not changed by this
461 // peephole uncomment the add %3, %4 at the end (since it overwrite the H flag).
469 ; peephole 42a shifts in accumulator insted of %1
481 ; peephole 43 removed load by exploiting commutativity of addition.
493 ; peephole 44 removed redundant zeroing of a (which has just been tested to be #0x00).
505 ; peephole 45 replaced constant #0x00 by a (which has just been tested to be #0x00).
516 ; peephole 46 replaced constant #0x00 by a (which has just been tested to be #0x00).
527 ; peephole 47 replaced constant #0x00 by a (which has just been tested to be #0x00).
538 ; peephole 48 replaced constant #0x00 by a (which has just been tested to be #0x00).
550 ; peephole 49 shortened or using a (which has just been tested to be #0x00).
562 ; peephole 50 shortened or using a (which has just been tested to be #0x00).
574 ; peephole 51 shortened or using a (which has just been tested to be #0x00).
586 ; peephole 52 shortened or using a (which has just been tested to be #0x00).
599 ; peephole 53 replaced constant #0x00 by a (which has just been tested to be #0x00).
612 ; peephole 54 replaced constant #0x00 by a (which has just been tested to be #0x00).
625 ; peephole 55 replaced constant #0x00 by a (which has just been tested to be #0x00).
638 ; peephole 56 replaced constant #0x00 by a (which has just been tested to be #0x00).
648 ; peephole 57 moved triple increment of de to constant.
657 ; peephole 58 moved double increment of de to constant.
665 ; peephole 59 moved increment of de to constant.
675 ; peephole 60 moved triple increment of bc to constant.
684 ; peephole 61 moved double increment of bc to constant.
692 ; peephole 62 moved increment of bc to constant.
705 ; peephole 63 moved addition of constant 0x%3%2 to bc to constant.
717 ld bc,#%1 + %4 + 0x%3%2
718 ; peephole 64 moved addition of constant 0x%3%2 to bc to constant.
726 ; peephole 65 replaced call at end of function by jump.
737 ; peephole 66 replaced call at end of function by jump moving call beyond pop ix.