Announce SDCC 4.5.0 RC3.
[sdcc.git] / sdcc / src / pdk / peeph.def
blob1e14f0346392dd45f133bab451ffc9f7bbf0d771
1 // peeph.def - PDK peephole rules
3 // Reads from RAM or I/O change z flag.
4 replace restart {
5 mo%3 %1, %2
6 } by {
7 ; peephole 0 removed dead load into %1 from %2.
8 } if notUsed(%1), notUsed('z'), notVolatile(%1), notVolatile(%2)
10 // Write to memory or I/O does not change z flag.
11 replace restart {
12 mo%3 %1, a
13 } by {
14 ; peephole 0a removed dead load into %1 from %2.
15 } if notUsed(%1), notVolatile(%1)
17 replace restart {
18 mo%3 %1, #%2
19 } by {
20 ; peephole 0b removed dead load into %1 from #%2.
21 } if notUsed(%1)
23 replace restart {
24 clear %1
25 } by {
26 ; peephole 1 removed dead clear of %1.
27 } if notUsed(%1)
29 replace restart {
30 mo%3 %1, a
31 mo%3 a, %1
32 } by {
33 mo%3 %1, a
34 ; peephole 2 removed redundant load from %1 into a.
35 } if notVolatile(%1), notUsed('z')
37 replace restart {
38 push %1
39 pop %1
40 } by {
41 ; peephole 3 removed redundant push / pop.
44 replace restart {
45 pop af
46 push af
47 } by {
48 ; peephole 3a removed redundant pop af / push af.
49 } if notUsed('a'), notUsed('z'), notUsed('c'), notUsed('ov')
51 replace restart {
52 mo%3 a, #%1
53 ret
54 } by {
55 ; peephole 4 moved load to ret.
56 ret #%1
59 replace restart {
60 xch a, %1
61 xch a, %1
62 } by {
63 ; peephole 5 removed redundant double exchange between a and %1.
64 } if notVolatile(%1)
66 replace restart {
67 mo%3 a, #0x00
68 slc a
69 and a, #0x01
70 } by {
71 mo%3 a, #0x00
72 slc a
73 ; peephole 6 removed redundant and.
76 replace restart {
77 mov a, %1
78 %9 %2, a
79 mov a, %1
80 } by {
81 mov a, %1
82 %9 %2, a
83 ; peephole 7 removed redundant mov a, %1
84 } if notUsed('z'), notVolatile(%1)
86 replace restart {
87 mov a, %1
88 %9 %2, a
89 %9 %3, a
90 mov a, %1
91 } by {
92 mov a, %1
93 %9 %2, a
94 %9 %3, a
95 ; peephole 8 removed redundant mov a, %1
96 } if notUsed('z'), notVolatile(%1)
98 replace restart {
99 mov a, %1
100 %9 %2, a
101 %9 %3, a
102 %9 %4, a
103 %9 %5, a
104 mov a, %1
105 } by {
106 mov a, %1
107 %9 %2, a
108 %9 %3, a
109 %9 %4, a
110 %9 %5, a
111 ; peephole 9 removed redundant mov a, %1
112 } if notUsed('z'), notVolatile(%1)
114 replace restart {
115 ret %1
117 } by {
118 ret %1
119 ; peephole j1 removed redundant ret after ret k.
122 replace restart {
123 t0sn.io %1, %2
124 goto %3
128 } by {
129 t1sn.io %1, %2
130 ; peephole j2 removed goto by inverting test condition.
134 } if labelRefCountChange(%4 -1)
136 replace restart {
137 t0sn.io %1, %2
138 goto %3
140 %5 %6
142 } by {
143 t1sn.io %1, %2
144 ; peephole j3 removed goto by inverting test condition.
146 %5 %6
148 } if labelRefCountChange(%4 -1)
150 replace restart {
151 t0sn.io %1, %2
152 goto %3
154 %5 %6, %7
156 } by {
157 t1sn.io %1, %2
158 ; peephole j4 removed goto by inverting test condition.
160 %5 %6, %7
162 } if labelRefCountChange(%4 -1)
164 replace restart {
165 t1sn.io %1, %2
166 goto %3
170 } by {
171 t0sn.io %1, %2
172 ; peephole j5 removed goto by inverting test condition.
176 } if labelRefCountChange(%4 -1)
178 replace restart {
179 t1sn.io %1, %2
180 goto %3
182 %5 %6
184 } by {
185 t0sn.io %1, %2
186 ; peephole j6 removed goto by inverting test condition.
188 %5 %6
190 } if labelRefCountChange(%4 -1)
192 replace restart {
193 t1sn.io %1, %2
194 goto %3
196 %5 %6, %7
198 } by {
199 t0sn.io %1, %2
200 ; peephole j7 removed goto by inverting test condition.
202 %5 %6, %7
204 } if labelRefCountChange(%4 -1)
206 replace restart {
207 ceqsn %1, %2
208 goto %3
212 } by {
213 cneqsn %1, %2
214 ; peephole j8 removed goto by inverting test condition.
218 } if isPort('pdk14' 'pdk15'), labelRefCountChange(%4 -1)
220 replace restart {
221 ceqsn %1, %2
222 goto %3
224 %5 %6
226 } by {
227 cneqsn %1, %2
228 ; peephole j9 removed goto by inverting test condition.
230 %5 %6
232 } if isPort('pdk14' 'pdk15'), labelRefCountChange(%4 -1)
234 replace restart {
235 ceqsn %1, %2
236 goto %3
238 %5 %6, %7
240 } by {
241 cneqsn %1, %2
242 ; peephole j10 removed goto by inverting test condition.
244 %5 %6, %7
246 } if isPort('pdk14' 'pdk15'), labelRefCountChange(%4 -1)
248 replace restart {
249 cneqsn %1, %2
250 goto %3
254 } by {
255 ceqsn %1, %2
256 ; peephole j11 removed goto by inverting test condition.
260 } if labelRefCountChange(%4 -1)
262 replace restart {
263 cneqsn %1, %2
264 goto %3
266 %5 %6
268 } by {
269 ceqsn %1, %2
270 ; peephole j12 removed goto by inverting test condition.
272 %5 %6
274 } if labelRefCountChange(%4 -1)
276 replace restart {
277 cneqsn %1, %2
278 goto %3
280 %5 %6, %7
282 } by {
283 ceqsn %1, %2
284 ; peephole j13 removed goto by inverting test condition.
286 %5 %6, %7
288 } if labelRefCountChange(%4 -1)
290 // Should be one of the last ones. Opens the code to further peephole optimization.
291 replace restart {
293 } by {
294 ; peephole j14 removed unused label %1.
295 } if labelRefCount(%1 0)
297 barrier
299 replace restart {
300 goto %1
301 } by {
303 ; peephole j15 replaced goto by ret.
304 } if labelIsReturnOnly(%1), labelRefCountChange(%1 -1)