1 // peeph.def
- F8 peephole rules
6 ; peephole
0 removed dead load into
%2 from
%3.
7 } if
same(%1 'ld' 'ldw'), notUsed(%2), notVolatile(%3), notUsed('nf' 'zf')
12 ; peephole
0a removed dead clear of
%2.
13 } if
same(%1 'clr' 'clrw'), notUsed(%2)
19 ; peephole
0a
' removed dead pop / push pair.
26 ; peephole 0a'' removed dead popw / pushw pair.
33 ; peephole 0b cleared xl instead of x.
40 ; peephole 0c loaded xl instead of x.
41 } if notUsed('xh
'), notUsed('nf
' 'zf
')
47 ; peephole 0d loaded xl instead of x.
48 } if notUsed('xh
'), notUsed('nf
' 'zf
')
55 ; peephole 0e loaded xl directly instead of via %1
63 ; peephole 0f loaded xl directly instead of via %1
71 ; peephole 1 removed redundant %1 from (%3, sp) into %2.
72 } if same(%1 'ld
' 'ldw
'), notUsed('nf
' 'zf
')
79 ; peephole 1b removed redundant ld.
87 ; peephole 1c removed redundant ldw.
93 ; peephole 1d removed dead %1 %2.
94 } if same(%1 'tst
' 'tstw
'), notVolatile(%2), notUsed('cf
' 'zf
' 'nf
' 'of
')
101 ; peephole 1e removed redundant ldw.
102 } if same(%1 'x
' 'z
' 'sp
')
110 ; peephole 1f loaded (%2, sp) from y instead of %1.
119 ; peephole 1g loaded %1 from y instead of (%2, sp).
120 } if same(%1 'x
' 'z
')
127 ; peephole 2 removed redundant tst after %1
128 } if same(%1 'and
' 'or
' 'xor
'), notVolatile(%2)
136 ; peephole 3 tested xl instead of %1
145 ; peephole 4 tested xl instead of %1
154 ; peephole 5 tested xl instead of (%1, sp)
163 ; peephole 6 tested y instead of %1
172 ; peephole 7 tested y instead of %1
181 ; peephole 7 tested y instead of (%1, sp)
189 ; peephole 8 removed redundant tstw after %1.
190 } if same(%1 'orw
' 'xorw
'), notVolatile(%2), notUsed('cf
' 'of
')
197 ; peephole 8a removed redundant %2 %3 after %1.
198 } if same(%1 'ld
' 'ldw
'), same(%2 'tst
' 'tstw
'), notUsed('cf
' 'of
')
205 ; peephole 8b removed redundant %2 %3 after %1.
206 } if same(%1 'ld
' 'ldw
'), same(%2 'tst
' 'tstw
'), notUsed('cf
' 'of
')
217 ; peephole 9a removed tst by adjusting jump condition
218 } if notVolatile(%1), notVolatile(%2), notUsed('cf
' 'nf
' 'zf
' 'of
'), notUsedFrom(%5 'cf
' 'nf
' 'zf
' 'of
')
229 ; peephole 9b removed tst by adjusting jump condition
230 } if notVolatile(%1), notVolatile(%2), notUsed('cf
' 'nf
' 'zf
' 'of
'), notUsedFrom(%5 'cf
' 'nf
' 'zf
' 'of
')
241 ; peephole 10 removed tst by adjusting jump condition
242 } if notVolatile(%1), notUsed('cf
' 'nf
' 'zf
' 'of
'), notUsedFrom(%2 'cf
' 'nf
' 'zf
' 'of
')
249 ; peephole 11 replaced clr-srl by tst.
250 } if notVolatile(%1), notUsed(%1), notUsed('cf
' 'of
')
257 ; peephole 12 removed redundant tst.
258 } if same(%2 'da
' 'dec
' 'inc
' 'sll
' 'sra
' 'srl
' 'tst
' 'rlc
' 'rrc
'), notVolatile(%1), notUsed('cf
' 'of
')
265 ; peephole 13 removed redundant tstw.
266 } if same(%2 'adcw
' 'decw
' 'incw
' 'mul
' 'negw
' 'rlcw
' 'sbcw
' 'sllw
' 'sraw
' 'srlw
' 'rrcw
' 'sbcw
' 'tstw
'), notVolatile(%1), notUsed('cf
' 'of
')
273 ; peephole 14 removed redundant tst.
274 } if same(%2 'adc
' 'add
' 'and
' 'cp
' 'or
' 'rot
' 'sbc
' 'sub
' 'xor
'), notVolatile(%1), notUsed('cf
' 'of
')
276 ; addw sp, #d does not set flags, but there is no tstw sp, either.
282 ; peephole 15 removed redundant tstw.
283 } if same(%2 'adcw
' 'addw
' 'cpw
' 'orw
' 'sbcw
' 'sllw
' 'subw
' 'xorw
'), notVolatile(%1), notUsed('cf
' 'of
')
291 ; peephole 16 moved ldw to replace tstw.
294 } if same(%2 'jr
' 'jrc
' 'jrgt
' 'jrle
' 'jrn
' 'jrnc
' 'jrnn
' 'jrno
' 'jrnz
' 'jro
' 'jrsge
' 'jrsgt
' 'jrsle
' 'jrslt
' 'jrz
'), notUsedFrom(%3 'y
' 'cf
' 'of
'), notUsed('cf
' 'of
')
301 ; peephole 17a merged clr into clrw
309 ; peephole 17b merged clr into clrw
317 ; peephole 17c merged clr to clrw
318 } if immdInRange(1 1 '-' %2 %1 %3)
327 ; peephole 18a removed tst by using incnw.
328 } if notUsed('cf
' 'of
')
337 ; peephole 18b removed tstw by using incnw.
338 } if notUsed('cf
' 'of
')
345 ; peephole 19 reused adddress in %1.
354 ; peephole 20 used sp from y.
362 ; peephole j0 jumped to %6 directly instead of via %5.
363 } if labelIsUncondJump(), notSame(%5 %6), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
370 ; peephole j1 removed redundant jump.
371 } if labelRefCountChange(%1 -1)
380 ; peephole j2 removed redundant jump.
381 } if labelRefCountChange(%1 -1)
388 ; peephole j3a removed unreachable jump to %2.
389 } if labelRefCountChange(%2 -1)
396 ; peephole j3b removed unreachable jump to %2.
397 } if labelRefCountChange(%2 -1)
404 ; peephole j3c removed unreachable jump to %2.
405 } if labelRefCountChange(%2 -1)
412 ; peephole j3d removed unreachable jump to %2.
413 } if labelRefCountChange(%2 -1)
420 ; peephole j4 removed unreachable ret.
428 ; peephole j5 removed unreachable addw.
431 // Ensure jump-to-jump optimization of absolute jumps above is done before other jump-related optimizations.
438 ; peephole j6 changed absolute to relative unconditional jump.
439 } if labelInRange(%5)
447 ; peephole j7a removed jr by using inverse jump logic
449 } if labelRefCountChange(%1 -1)
457 ; peephole j7b removed jr by using inverse jump logic
459 } if labelRefCountChange(%1 -1)
467 ; peephole j7c removed jr by using inverse jump logic
469 } if labelRefCountChange(%1 -1)
477 ; peephole j7d removed jr by using inverse jump logic
479 } if labelRefCountChange(%1 -1)
487 ; peephole j7e removed jr by using inverse jump logic
489 } if labelRefCountChange(%1 -1)
497 ; peephole j7f removed jr by using inverse jump logic
499 } if labelRefCountChange(%1 -1)
507 ; peephole j7g removed jr by using inverse jump logic
509 } if labelRefCountChange(%1 -1)
517 ; peephole j7h removed jr by using inverse jump logic
519 } if labelRefCountChange(%1 -1)
527 ; peephole j7i removed jr by using inverse jump logic
529 } if labelRefCountChange(%1 -1)
537 ; peephole j7j removed jr by using inverse jump logic
539 } if labelRefCountChange(%1 -1)
547 ; peephole j7k removed jr by using inverse jump logic
549 } if labelRefCountChange(%1 -1)
557 ; peephole j7l removed jr by using inverse jump logic
559 } if labelRefCountChange(%1 -1)
567 ; peephole j7m removed jr by using inverse jump logic
569 } if labelRefCountChange(%1 -1)
577 ; peephole j7n removed jr by using inverse jump logic
579 } if labelRefCountChange(%1 -1)
585 ; peephole j8 jumped to %6 directly instead of via %5.
586 } if same(%1 'jr
' 'jrc
' 'jrgt
' 'jrle
' 'jrn
' 'jrnc
' 'jrnn
' 'jrno
' 'jrnz
' 'jro
' 'jrsge
' 'jrsgt
' 'jrsle
' 'jrslt
' 'jrz
'), labelIsUncondJump(), notSame(%5 %6), labelInRange(%6), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
588 // Do the jump-to-ret optimization after all jump inversion optimizations, to optimize jr z, %1; jp %retlabel; %1: into jr nz, %retlabel instead of jr z, %1; ret; %1:.
595 ; peephole j9 replaced jump by return.
596 } if labelIsReturnOnly(%5), labelRefCountChange(%5 -1)
602 ; peephole j10 replaced jump by return.
603 } if labelIsReturnOnly(%5), labelRefCountChange(%5 -1)
605 // Should be one of the last ones. Opens the code to further peephole optimization.
609 ; peephole j21 removed unused label %1.
610 } if labelRefCount(%1 0)