1 // peeph-z80.def - Z80 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.
20 // This can't go into peeph.def since %1 could be (hl+) on gbz80.
25 ; peephole z0 removed dead load into %1
27 } if notVolatile(%1 %3), operandsNotSame
36 ; peephole z1 used #%2 directly instead of going through %1 using indirect addressing.
48 ; peephole z2 directly used #%2 instead of going through %1 using indirect addressing.
61 ; peephole z3 used #%2 directly instead of going through %1 using indirect addressing.
64 } if operandsNotRelated(%3 'a')
74 ; peephole z4 directly used address #%1 + %2 instead of placing it in bc first.
86 ; peephole z5 directly used address #%1 + %2 + %6 instead of placing it in bc first.
99 ; peephole z6 directly used address #%1 + %2 instead of placing it in bc first.
113 ; peephole z7 directly used address #%1 + %2 + %6 instead of placing it in bc first.
124 ; peephole z8 moved %1 directly into l instead of going through c.
136 ; peephole z9 moved hl directly to the stack instead of going through bc.
148 ; peephole z10 moved hl directly to the stack instead of going through de.
156 ; peephole z11 replaced jump by return.
157 } if labelIsReturnOnly(), labelRefCountChange(%5 -1)
163 ; peephole z11a replaced jump by return.
164 } if labelIsReturnOnly(), labelRefCountChange(%5 -1)
166 // Should be one of the last ones. Opens the code to further peephole optimization.
170 ; peephole z12 removed unused label %1.
171 } if labelRefCount(%1 0)
173 // Applying z11 or z11a followed by z12 will often leave a dead ret at the end of the function. Remove it.
179 ; peephole z13 removed unused ret.
182 // These should be the last rules, so that the peepholes above need to look at jp only.
187 ; peephole z14 changed absolute to relative unconditional jump.
194 ; peephole z15 changed absolute to relative conditional jump.
201 ; peephole z16 changed absolute to relative conditional jump.
208 ; peephole z17 changed absolute to relative conditional jump.
215 ; peephole z18 changed absolute to relative conditional jump.