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.
32 ; peephole 3 removed jp by using inverse jump logic
34 } if labelRefCountChange(%1 -1)
42 ; peephole 4 removed jp by using inverse jump logic
44 } if labelRefCountChange(%1 -1)
52 ; peephole 5 removed jp by using inverse jump logic
54 } if labelRefCountChange(%1 -1)
62 ; peephole 6 removed jp by using inverse jump logic
64 } if labelRefCountChange(%1 -1)
70 ; peephole 7 redirected jump-to-jump at %5 by jump to %6
71 } if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
77 ; peephole 8 redirected jump-to-jump at %5 by jump to %6
78 } if labelIsUncondJump(), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
87 ; peephole 9 removed jump and redundant load.
91 } if labelRefCountChange(%4 -1)
98 ; peephole 10 removed redundant load of 0 into a.
106 ; peephole 11 combined constant loads into register pair.
114 ; peephole 12 combined constant loads into register pair.
122 ; peephole 13 combined constant loads into register pair.
130 ; peephole 14 removed redundant load from %1 into a.
132 // This gives many false negatives and without the test no problems are encountered in the regression tests
133 // Maybe we can try this after 2.7.0 release
140 ; peephole 15 removed redundant load from a into %1.
142 // This gives many false negatives and without the test no problems are encountered in the regression tests
143 // Maybe we can try this after 2.7.0 release
152 ; peephole 16 moved %3 directly into a instead of going through %2.
155 } if notVolatile(%2), operandsNotSame
164 ; peephole 17 removed load by reordering or arguments.
174 ; peephole 18 used value still in a instead of loading it from %1.
182 ; peephole 19 removed redundant or after or.
190 ; peephole 20 removed redundant or after and.
198 ; peephole 21 removed redundant or after xor.
206 ; peephole 22 removed redundant load into %1.
217 ; peephole 23 load value in a first and use it next
218 } if notVolatile(%1 %2)
228 ; peephole 24 removed redundant load from %3%1 into %4%2
229 } if notVolatile(%1 %2 %3 %4)
237 ; peephole 25 removed load into b
247 ; peephole 26 removed load into c
257 ; peephole 27 removed load into d
267 ; peephole 28 removed load into e
277 ; peephole 29 removed load into h
287 ; peephole 30 removed load into l
303 ; peephole 31 moved and pushed arguments c and #%2 through bc instead of pushing them individually.
319 ; peephole 32 moved and pushed arguments e and #%2 through de instead of pushing them individually.
332 ; peephole 33 removed load by replacing sub with cp
344 ; peephole 34 removed load by replacing sub with cp
358 ; peephole 35 replaced sub a,#0xFF by inc a.
367 ; peephole 36 replaced sub a,#0xFF by inc a.
384 ; peephole 37 directly used (%1 + %2) in calculation instead of placing it in bc first.
402 ; peephole 38 directly used (%1 + %2) in calculation instead of placing it in de first.
414 ; peephole 39 replaced zero load, rla by and since rlca writes the same value to carry bit and least significant bit.
424 ; peephole 40 moved %2 directly into de instead of going through %1.
434 ; peephole 41 removed lower part of multibyte addition.
446 ; peephole 42 removed loads by exploiting commutativity of addition.
451 // sdcc does not use the H flag. sla resets it, while add sets it.
452 // To ensure that the state of the H flag is not changed by this
453 // peephole uncomment the add %3, %4 at the end (since it overwrite the H flag).
461 ; peephole 42a shifts in accumulator insted of %1
473 ; peephole 43 removed load by exploiting commutativity of addition.
485 ; peephole 44 removed redundant zeroing of a (which has just been tested to be #0x00).
497 ; peephole 45 replaced constant #0x00 by a (which has just been tested to be #0x00).
508 ; peephole 46 replaced constant #0x00 by a (which has just been tested to be #0x00).
519 ; peephole 47 replaced constant #0x00 by a (which has just been tested to be #0x00).
530 ; peephole 48 replaced constant #0x00 by a (which has just been tested to be #0x00).
542 ; peephole 49 shortened or using a (which has just been tested to be #0x00).
554 ; peephole 50 shortened or using a (which has just been tested to be #0x00).
566 ; peephole 51 shortened or using a (which has just been tested to be #0x00).
578 ; peephole 52 shortened or using a (which has just been tested to be #0x00).
591 ; peephole 53 replaced constant #0x00 by a (which has just been tested to be #0x00).
604 ; peephole 54 replaced constant #0x00 by a (which has just been tested to be #0x00).
617 ; peephole 55 replaced constant #0x00 by a (which has just been tested to be #0x00).
630 ; peephole 56 replaced constant #0x00 by a (which has just been tested to be #0x00).
640 ; peephole 57 moved triple increment of de to constant.
649 ; peephole 58 moved double increment of de to constant.
657 ; peephole 59 moved increment of de to constant.
667 ; peephole 60 moved triple increment of bc to constant.
676 ; peephole 61 moved double increment of bc to constant.
684 ; peephole 62 moved increment of bc to constant.
697 ; peephole 63 moved addition of constant 0x%3%2 to bc to constant.
709 ld bc,#%1 + %4 + 0x%3%2
710 ; peephole 64 moved addition of constant 0x%3%2 to bc to constant.
718 ; peephole 65 replaced call at end of function by jump.
729 ; peephole 66 replaced call at end of function by jump moving call beyond pop ix.