1 // peeph.def
- Common Z80 and sm83 peephole rules
3 // (c
) Philipp Klaus
Krause (pkk@spth.de
, philipp@colecovision.eu
) 2006 - 2021
4 // (c
) Sebastian
'basxto' Riedel (sdcc@basxto.de
) 2020 - 2022
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 ; common peephole
0a removed redundant load from
%1 into
%1.
26 //TODO
: works for the other ports
, but slows at least some of them down
34 ; common peephole
0b removed redundant load from
%2 back into
%1.
35 }if
isPort('sm83'), notSame(%1 '(hl+)' '(hl-)'), notSame(%2 '(hl+)' '(hl-)'), operandsNotRelated(%3 %1), operandsNotRelated(%3 %2), notVolatile(%1), notVolatile(%2),
40 ; common peephole
1 removed dead load from
%2 into
%1.
41 } if
notVolatile(%1), notUsed(%1), notVolatile(%2), notSame(%1 '(hl+)' '(hl-)'), notSame(%2 '(hl+)' '(hl-)')
46 ; common peephole
2a removed
%1 hl
, %2 due to unused result.
47 } if
same(%1 'adc' 'sbc'), notUsed('hl' 'f')
52 ; common peephole
2b removed add hl
, %2 due to unused result.
53 } if
notUsed('hl' 'cf' 'nf')
58 ; common peephole
2c removed
%1 %2 due to unused result.
59 } if
same(%1 'dec' 'inc'), same(%2 'bc' 'de' 'hl' 'sp' 'ix' 'iy'), notUsed(%2)
64 ; common peephole
2d removed
%1 due to unused result.
65 } if
same(%1 'rlca' 'rla' 'rrca' 'rra'), notUsed('a' 'hf' 'nf' 'cf')
70 ; common peephole
3 removed dead load from
%2 + %3 into
%1.
71 } if
notVolatile(%1), notUsed(%1), notSame(%1 '(hl+)' '(hl-)')
72 // Should probably check for
notVolatile(%2), too
, but gives many false positives and no regression tests fail.
80 ; common peephole
3a replaced adc by add since l is unused.
81 } if
notUsed('l' 'zf')
87 ; common peephole
3b replaced adc by add since l is unused.
88 } if
notUsed('l' 'zf')
94 ; common peephole
4a made
0 offset explicit.
95 } if
same(%2 'ix' 'iy')
101 ; common peephole
4b made
0 offset explicit.
102 } if
same(%1 'ix' 'iy')
104 //remove dead
INC/DEC instructions on
16-bit registers
108 ; common peephole
5 removed dead
%1 %2.
109 } if
same(%1 'inc' 'dec'), same(%2 'bc' 'de' 'hl' 'sp' 'ix' 'iy'), notUsed(%2)
111 //remove dead
INC/DEC instructions on
8-bit registers
115 ; common peephole
6a removed dead
%1 %2
116 } if
same(%1 'inc' 'dec'), same(%2 'a' 'b' 'c' 'd' 'e' 'h' 'l' 'ixh' 'ixl' 'iyh' 'iyl'), notUsed(%2 'f')
118 //remove dead ALU instructions on
8-bit register
122 ; common peephole
6b removed dead
%1 a
, %2
123 } if
same(%1 'sub' 'sbc' 'add' 'adc' 'and' 'or' 'xor'), notUsed('af')
125 //remove dead CP instructions
129 ; common peephole
6c removed dead cp a
, %1
135 ; common peephole
6d removed dead
%1 %2
136 } if
same(%1 'rlc' 'rl' 'rrc' 'rr' 'sla' 'sra' 'srl' 'sll' 'sli'), notVolatile(%2), notUsed(%2 'f')
141 ; common peephole
7 removed dead load from
%2 (%3) into
%1.
142 } if
notUsed(%1), same(%3 'ix' 'iy')
143 // Should probably check for
notVolatile(), but gives many false positives and no regression tests fail.
149 ; common peephole
8 removed double de
/hl swap.
156 ; common peephole
9 loaded
%3 from
%2 directly instead of going through
%1.
158 } if
canAssign(%3 %2), notVolatile(%1), notUsed(%1), notSame(%3 '(hl)' '(de)' '(bc)' '(hl+)' '(hl-)'), notSame(%1 '(hl+)' '(hl-)')
164 ; common peephole
9a loaded
%3 from
%2 directly instead of going through
%1.
166 } if
canAssign(%3 %2), notVolatile(%1), notUsed(%1), canAssign('a' %1), notSame(%1 '(hl+)' '(hl-)'), operandsNotRelated(%1 %3)
172 ; common peephole
9b reused value still in hl.
174 } if
notVolatile(%1), notSame(%1 '(hl+)' '(hl-)')
182 ; common peephole
10 loaded
%5 from
%2 directly instead of going through
%1.
184 } if
canAssign(%5 %2), notVolatile(%1), operandsNotRelated(%1 %4), operandsNotRelated(%1 %3), operandsNotRelated(%3 %5), operandsNotRelated(%4 %5), notUsed(%1), notSame(%3 %4 '(hl)' '(de)' '(bc)' '(hl+)' '(hl-)'),
185 notVolatile(%5), notSame(%1 '(hl+)' '(hl-)'), notSame(%5 '(hl+)' '(hl-)')
186 // Rule OK unless both
%5 and
%4 are volatile
, but we can
't express that directly.
196 ; common peephole 11 loaded %5%6 from %1%2 directly instead of going through %3 (ix) %4 (ix).
199 } if canAssign(%5 %1), canAssign(%6 %2), notSame(%5 %2)
205 ; common peephole 12 loaded %2 (%3) into %4 directly instead of going through %1.
207 } if canAssign(%4 %2 %3), notVolatile(%1), notUsed(%1)
213 ; common peephole 13 loaded %2 into %3 (%4) directly instead of going through %1.
215 } if canAssign(%3 %4 %2), notVolatile(%1), notUsed(%1), canAssign('a
' %1)
216 // canAssign ('a
' %1) checks that %1 is an 8-bit value
224 ; common peephole 14 loaded %2 (%3) into %7 directly instead of going through %1.
226 } if canAssign(%7 %2 %3), notVolatile(%1), notUsed(%1), notSame(%1 %4), notSame(%7 %4)
234 ; common peephole 15 loaded %2 (%3) into %7 directly instead of going through %1.
236 } if canAssign(%7 %2 %3), notVolatile(%1), notUsed(%1), operandsNotRelated(%1 %5), operandsNotRelated(%7 %4), operandsNotRelated(%7 %5), notSame(%4 '(hl
)' '(de
)' '(bc
)' '(hl
+)' '(hl
-)'), notSame(%5 '(hl
)' '(de
)' '(bc
)' '(hl
+)' '(hl
-)' '(iy
)')
242 ; common peephole 16 loaded %2 into a directly instead of going through %1.
251 ; common peephole 17 loaded a from (#%1) directly instead of using hl.
258 ; common peephole 18 loaded %2 into a directly instead of using hl.
267 ; common peephole 19 loaded (#%1) from a directly instead of using hl.
275 ; common peephole 20 loaded (#%1) from a directly instead of using hl.
285 ; common peephole 21 shifted in (%2) instead of a.
286 } if same(%3 'srl
' 'sla
' 'rl
' 'rr
' 'rlc
' 'rrc
' 'sll
')
294 ; common peephole 22 used (hl) in %4 directly instead of going through %1.
296 } if notVolatile(%1), notUsed(%1), same(%4 'add
' 'adc
' 'sub
' 'sbc
' 'and
' 'or
' 'xor
')
311 ; common peephole 23 optimize 16-bit load from %3.
312 } if canJoinRegs(%2 %1 %3), notUsed(%3 'a
')
321 ; common peephole 24 incremented in hl instead of %1.
323 } if canJoinRegs(%3 %2 %4), same(%1 %4), notUsed(%1)
334 ; common peephole 25a loaded #%1 into (hl) instead of (%4).
335 } if canJoinRegs(%2 %1 %5), same(%4 %5), notUsed('a
')
347 ; common peephole 25b loaded #%1 into (%8) instead of (%4).
348 } if canJoinRegs(%2 %1 %5), same(%4 %5), canJoinRegs(%7 %6 %8)
354 ; common peephole 26a merged push and ex (sp), since %2 isn't used.
356 } if
same(%2 'hl' 'ix' 'xy'), notUsed(%2)
362 ; common peephole
26b moved push after de
/hl swap.
371 ; common peephole
26c moved push after de
/hl swap.
380 ; common peephole
26d moved push
%1 before de
/hl swap.
383 } if
notSame(%1 'hl' 'de')
389 ; common peephole
26e pushed hl directly instead of going through de.
391 } if
notUsed('de' 'hl')
398 ; common peephole
27 pushed de instead of hl removing a load.
401 } if
notUsed('hl' 'e')
403 //TODO
: remove if unused
409 ; common peephole
28 pushed hl directly instead of going through de.
412 } if
notSame(%1 'hl' 'de'), notUsed('de' 'hl')
419 ; common peephole
29 pushed
%3 directly instead of going through
%6.
421 } if
canJoinRegs(%2 %1 %3), canJoinRegs(%5 %4 %7), same(%7 %6), notUsed(%6)
429 ; common peephole
30 pushed
%7 directly instead of going through
%4.
432 } if
canJoinRegs(%3 %2 %5), same(%5 %4), canJoinRegs(%6 %5 %7), notSame(%1 %4), notUsed(%4)
439 ; common peephole
31 popped
%6 directly instead of going through
%1.
441 } if
canJoinRegs(%4 %2 %6), canJoinRegs(%5 %3 %7), same(%7 %1), notUsed(%1)
448 ; common peephole
32a removed de
/hl swap.
458 ; common peephole
32b removed de
/hl swap.
467 ; common peephole
33 loaded
%3 from
%2 instead of going through
%1 (%4).
470 } if
same(%4 'ix' 'iy'), canAssign(%3 %2), notSame(%3 'bc' 'de' 'hl' 'ix' 'iy')
471 // Don
't need to check for volatile, since ix is used for the stack.
480 ; common peephole 34 loaded %2 from a instead of %1 (%3)
482 } if same(%3 'ix
' 'iy
'), canAssign(%2 'a
')
491 ; common peephole 35 pushed de instead of pushing a twice.
494 } if notUsed('d
'), notUsed('a
')
504 ; common peephole 36 used hl instead of %2.
510 } if notUsed('hl
' %2)
519 ; common peephole 37a pushed %4 instead of pushing a twice.
523 } if unusedReg(%4 'bc
' 'de
' 'hl
'), canSplitReg(%4 %2 %3), notUsed('a
')
532 ; common peephole 37b pushed %4 instead of pushing a twice.
536 } if unusedReg(%4 'bc
' 'de
' 'hl
'), canSplitReg(%4 %2 %3), notUsed('af
')
545 ; common peephole 38 combined pushing of %3 and %5.
547 } if canSplitReg(%1 %3 %4), canSplitReg(%2 %5), canAssign(%4 %5), notUsed(%4)
553 ; common peephole 39 replaced 16-bit addition by 8-bit loads and 16-bit increment.
557 } if canSplitReg(%2 %3 %4), immdInRange(1 1 '+' %1 0 %9)
563 ; common peephole 40a combined redundant ANDs #%1 and #%2.
565 } if operandsLiteral(%1 %2), immdInRange(0x00 0xFF '&' %1 %2 %x3)
571 ; common peephole 40b combined redundant ORs #%1 and #%2.
573 } if operandsLiteral(%1 %2), immdInRange(0x00 0xFF '|
' %1 %2 %x3)
579 ; common peephole 41a remove double load to %1.
581 } if notVolatile(%1), notVolatile(%2), notSame(%1 '(hl
+)' '(hl
-)'), notSame(%2 '(hl
+)' '(hl
-)'), operandsNotRelated(%1 %3)
591 ; common peephole 42 combined pushing of a and c.
593 } if notUsed('b
'), notUsed('a
')
603 ; common peephole 43 combined pushing of %3 and %2.
605 } if notSame(%1 'iy
'), canSplitReg(%1 %3 %4), canAssign(%4 %2), notUsed(%4 'a
')
617 ; common peephole 44a combined pushing of %1 and %2 (%3).
619 } if unusedReg(%6 'bc
' 'de
' 'hl
'), canSplitReg(%6 %4 %5), canAssign(%4 %1), notUsed('a
')
633 ; common peephole 44b combined pushing of (%1) and (%2).
635 } if unusedReg(%6 'bc
' 'de
' 'hl
'), notSame(%6 %1 %2), canSplitReg(%6 %4 %5)
640 ; common peephole 45 replace 16-bit immediate load by 8-bit one.
642 } if canSplitReg(%1 %5 %3), immdInRange(0x00 0xff '&' %2 0xff %4), canAssign(%3 %4), notUsed(%5)
647 ; common peephole 46 replace 16-bit immediate load by 8-bit one.
649 } if canSplitReg(%1 %3 %5), immdInRange(0x00 0xff '/' %2 256 %4), canAssign(%3 %4), notUsed(%5)
659 ; common peephole 47a pushed %1 (%3), %2 (%3) through %6 instead of af.
663 } if unusedReg(%6 'bc
' 'de
' 'hl
'), canSplitReg(%6 %4 %5), notUsed('a
')
674 ; common peephole 47b pushed (hl), %1, (hl) through %4 instead of af.
681 } if same(%1 'inc
' 'dec
'), unusedReg(%4 'bc
' 'de
'), canSplitReg(%4 %2 %3), notUsed('a
')
691 ; common peephole 47c pushed (%5), (%6) through %4 instead of af.
697 } if same(%5 'hl
' 'hl
+' 'hl
-'), same(%6 'hl
' 'hl
+' 'hl
-'), unusedReg(%4 'bc
' 'de
'), canSplitReg(%4 %2 %3)
704 ; common peephole 48 pushed %6 instead of %3.
706 } if canJoinRegs(%2 %1 %7), same(%3 %7), canJoinRegs(%5 %4 %6), notUsed(%3)
715 ; common peephole 49 pushed %3 instead of hl.
720 } if same(%4 'inc
' 'dec
'), unusedReg(%3 'de
' 'bc
'), canSplitReg(%3 %2 %1), notUsed('hl
')
726 ; common peephole 49a pushed %2 instead of %3.
729 } if same(%3 'ix
' 'iy
'), notUsed(%3), unusedReg(%2 'bc
' 'de
' 'hl
'), canAssign(%2 %1)
735 ; common peephole 50a eliminated dead pop/push %1 pair.
742 ; common peephole 50b eliminated dead push/pop pair.
750 ; common peephole 50c eliminated dead push/inc sp pair.
758 ; common peephole 51 eliminated dead pop/push %1 pair.
760 } if notUsed(%1), operandsNotRelated(%1 %3)
767 ; common peephole 51a eliminated dead pop/push %1 pair.
769 } if notUsed(%1), operandsNotRelated(%1 %3), operandsNotRelated(%1 %2)
777 ; common peephole 52a replaced push/pop pair by loads.
778 } if canSplitReg(%1 %3 %4), canSplitReg(%2 %5 %6), notSame(%1 %2 'ix
' 'iy
'), notUsed(%1)
785 ; common peephole 52b replaced push/pop pair by load.
786 } if canSplitReg(%1 %3 %4), notUsed('f
')
796 ; common peephole 52c replaced push/pop pair by loads.
797 } if canSplitReg(%1 %3 %4), canSplitReg(%2 %5 %6), notSame(%1 %2 'ix
' 'iy
'), operandsNotRelated(%7 %1)
803 ; common peephole 53 used direct memory loading instead of indirect.
812 ; common peephole 54 used hl instead of %4.
815 } if notUsed(%4 'hl
'), same(%5 'a
' 'b
' 'c
' 'd
' 'e
' 'h
' 'l
'), same(%3 'add
' 'adc
' 'and
' 'ld
' 'or
' 'sbc
' 'sub
' 'xor
')
821 ; common peephole 55l used hl instead of %4.
830 ; common peephole 55 used hl instead of %4.
839 ; common peephole 56 used hl instead of %4.
842 } if notUsed(%4 'hl
'), notSame(%3 'h
' 'l
')
848 ; common peephole 57 used direct memory storing instead of indirect.
858 ; common peephole 58 used hl instead of %4.
863 } if operandsNotRelated(%2 'hl
'), operandsNotRelated(%3 'hl
'), immdInRange(-128 127 '+' %5 1 %7), same(%6 %7), notUsed(%4 'hl
')
870 ; common peephole 59 used hl instead of %4.
880 ; common peephole 60 used hl instead of %3.
883 } if notUsed(%3 'hl
'), operandsNotRelated(%4 'hl
')
889 ; common peephole 61 used hl instead of %4.
892 } if same(%5 'bit
' 'res
' 'set
'), notUsed(%4 'hl
')
900 ; common peephole 62 used hl instead of %4.
906 } if operandsNotRelated(%2 'hl
'), immdInRange(-128 127 '+' %5 1 %7), same(%7 %6), notUsed(%4 'hl
')
913 ; common peephole 63 used hl instead of %4.
917 } if notUsed(%4 'hl
')
925 ; common peephole 64 used hl instead of %4.
932 } if immdInRange(-128 127 '+' %2 1 %5), same(%5 %3), notUsed(%4 'a
')
940 ; common peephole 65 used hl instead of %4.
946 } if immdInRange(-128 127 '+' %5 1 %7), same(%7 %6), notUsed(%4 'hl
')
959 ; common peephole 66a used hl instead of %4.
960 } if immdInRange(-128 127 '+' %2 1 %5), same(%5 %3), notUsed(%4 'hl
')
973 ; common peephole 66b used hl instead of %4.
974 } if immdInRange(-128 127 '-' %2 1 %5), same(%5 %3), notUsed(%4 'hl
')
984 ; common peephole 67a used hl instead of %4.
985 } if same(%5 'bit
' 'res
' 'set
'), notUsed(%4 'hl
')
995 ; common peephole 67b used hl instead of %4.
996 } if same(%5 'adc
' 'add
' 'and
' 'ld
' 'or
' 'sbc
' 'sub
' 'xor
'), notUsed(%4 'hl
')
1007 ; common peephole 67c removed load back from stack.
1009 }if operandsLiteral(%1), immdInRange(0 0 '+' %1 0 %2)
1020 ; common peephole 68 reversed ld and or.
1023 // can be further optimized to (hl+) on gbz80
1029 ; common peephole 69 incremented in hl instead of %3.
1033 } if canJoinRegs(%2 %1 %4), same(%4 %3), notUsed('hl
')
1039 ; common peephole 70 %3 (hl) instead of %2 (%4).
1042 } if same(%3 'inc
' 'dec
'), notUsed(%4 'hl
')
1049 ; common peephole 71 eliminate unnecessary initialization of %1 register.
1052 } if same(%1 'c
' 'e
' 'l
' 'ixl
' 'iyl
'), canJoinRegs('' %1 %4), same(%3 %4), notUsed(%1)
1058 ; common peephole 72 tested bit %3 of %1 (%2) directly instead of going through a.
1066 ; common peephole 73 tested bit %2 of (hl) directly instead of going through %1.
1074 ; common peephole 74 tested bit %2 of %1 directly instead of going through a.
1076 } if notUsed('a
'), canAssign(%1 'b
')
1083 ; common peephole 75 %3 bit %2 of %1 directly instead of going through a.
1086 } if same(%3 'set
' 'res
'), canAssign(%1 'b
'), notSame(%1 '(hl
+)' '(hl
-)')
1087 // canAssign(%1 'b
') is true, iff set b, %1 is possible.
1094 ; common peephole 76 %4 bit %3 of %1 (%2) directly instead of going through a.
1097 } if same(%4 'set
' 'res
')
1104 ; common peephole 77a incremented immediate.
1105 } if operandsLiteral(%3), immdInRange(0 256 '+' %3 1 %4), notUsed('f
')
1112 ; common peephole 77b incremented immediate.
1113 } if operandsLiteral(%3), immdInRange(0 256 '-' %3 1 %4), notUsed('f
')
1120 ; common peephole 77c decremented immediate.
1121 } if operandsLiteral(%3), immdInRange(0 256 '-' %3 1 %4), notUsed('f
')
1128 ; common peephole 77d decremented immediate.
1129 } if operandsLiteral(%3), immdInRange(0 256 '+' %3 1 %4), notUsed('f
')
1135 ; common peephole 77e changed -0 to +0.
1143 ; common peephole 77f decremented immediate.
1146 // should improve flag based optimizations
1151 ; common peephole 78 removed redundant jp
1153 } if labelRefCountChange(%2 -1)
1161 ; common peephole 79 removed jp by using inverse jump logic
1163 } if operandsNotRelated(%2 '(hl
)' '(ix
)' '(iy
)'), labelRefCountChange(%1 -1)
1171 ; common peephole 80 removed jp by using inverse jump logic
1173 } if operandsNotRelated(%2 '(hl
)' '(ix
)' '(iy
)'), labelRefCountChange(%1 -1)
1181 ; common peephole 81 removed jp by using inverse jump logic
1183 } if operandsNotRelated(%2 '(hl
)' '(ix
)' '(iy
)'), labelRefCountChange(%1 -1)
1191 ; common peephole 82 removed jp by using inverse jump logic
1193 } if operandsNotRelated(%2 '(hl
)' '(ix
)' '(iy
)'), labelRefCountChange(%1 -1)
1199 ; common peephole 83 jumped to %6 directly instead of via %5.
1200 } if labelIsUncondJump(), notSame(%5 %6), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
1206 ; common peephole 84 jumped to %6 directly instead of via %5.
1207 } if labelIsUncondJump(), notSame(%5 %6), labelRefCountChange(%5 -1), labelRefCountChange(%6 +1)
1213 ; common peephole 85a eliminated jump.
1215 } if labelRefCountChange(%1 -1)
1222 ; common peephole 85b eliminated jump.
1225 } if labelRefCountChange(%1 -1)
1227 // A peephole that makes the code longer. Let's hope it
's worth it in speed gain and further optimization potential.
1236 ; common peephole 86 jumped directly to %3 instead of testing a first.
1240 } if labelRefCountChange(%3 +1)
1249 ; common peephole 87a removed unreachable jump to %4
1250 } if labelRefCountChange(%4 -1)
1257 ; common peephole 87b removed unreachable jump to %3
1259 } if labelRefCount(%2 0), labelRefCountChange(%3 -1)
1267 ; common peephole 89 removed impossible jump to %2.
1268 } if labelRefCountChange(%2 -1)
1276 ; common peephole 90a removed and by changing jump condition.
1278 } if notUsed('a
'), notUsedFrom(%1 'a
')
1285 ; common peephole 90b removed and by changing jump condition.
1288 } if notUsed('a
'), notUsedFrom(%1 'a
')
1294 ; common peephole 92a combined constant loads into register pair.
1296 } if canJoinRegs(%6 %5 %7), operandsLiteral(%1 %2), immdInRange(0x00 0xffff '*' %2 0x100 %3), immdInRange(0x00 0xffff '|
' %3 %1 %x4)
1303 ; common peephole 92b combined constant loads into register pair.
1305 } if canJoinRegs(%6 %5 %7), operandsLiteral(%2), immdInRange(0x00 0xffff '*' %2 0x100 %x4), notUsed('a
' 'cf
' 'zf
')
1312 ; common peephole 92c combined constant loads into register pair.
1314 } if canJoinRegs(%6 %5 %7), operandsLiteral(%1), notUsed('a
' 'cf
' 'zf
')
1320 ; common peephole 93a combined constant loads into register pair.
1322 } if canJoinRegs(%5 %6 %7), operandsLiteral(%1 %2), immdInRange(0x00 0xffff '*' %1 0x100 %3), immdInRange(0x00 0xffff '|
' %3 %2 %x4)
1329 ; common peephole 93b combined constant loads into register pair.
1331 } if canJoinRegs(%5 %6 %7), operandsLiteral(%2), notUsed('a
' 'cf
' 'zf
')
1338 ; common peephole 93c combined constant loads into register pair.
1340 } if canJoinRegs(%5 %6 %7), operandsLiteral(%1), immdInRange(0x00 0xffff '*' %1 0x100 %x4), notUsed('a
' 'cf
' 'zf
')
1349 ; common peephole 93d combined constant loads into register pair.
1350 } if canJoinRegs(%5 %6 %7), operandsLiteral(%1 %2), immdInRange(0x00 0xffff '*' %1 0x100 %3), immdInRange(0x00 0xffff '|
' %3 %2 %x4)
1356 ; common peephole 94a reused constant #0 loaded into register.
1359 } if same(%1 'a
' 'b
' 'c
' 'd
' 'e
' 'h
' 'l
'), operandsLiteral(%2), immdInRange(0 0 '+' %2 0 %3)
1368 ; common peephole 94a' reused constant #
0 in a.
1376 ; common peephole
94b reused constant #
0 loaded into register.
1380 } if
same(%1 'hl' 'hl+' 'hl-'), operandsLiteral(%2), immdInRange(0 0 '+' %2 0 %3)
1388 ; common peephole
94c reused constant #
0 loaded into register.
1393 } if
same(%1 'inc' 'dec'), operandsLiteral(%2), immdInRange(0 0 '+' %2 0 %3)
1402 ; common peephole
94d pushed register pair twice.
1415 ; common peephole
94e pushed register pair twice.
1416 }if
operandsLiteral(%2), operandsLiteral(%4), immdInRange(0 0 '-' %2 %4 %5)
1428 ; common peephole
94f pushed register pair twice.
1429 }if
operandsLiteral(%2), operandsLiteral(%4), immdInRange(0 0 '-' %2 %4 %5)
1441 ; common peephole
95a switched loads to
%4 and
%5.
1449 } if
operandsNotRelated(%4 %5 %1), operandsNotRelated(%5 %1)
1458 ; common peephole
95b switched loads to
%4 and
%5.
1464 } if
operandsNotRelated(%4 %5 %1), operandsNotRelated(%5 %1)
1466 // improves genRet
after (hl
) access
1474 ; common peephole
95c switched loads to
%4 and
%5.
1480 }if
operandsNotRelated(%4 %5 %1), operandsNotRelated(%5 %1)
1486 ; common peephole
96a move
%2 %3 before
%1
1489 } if
same(%2 'inc' 'dec'), same(%3 'hl'), same(%1 'rlca' 'rrca' 'rra' 'rla' 'cpl' 'scf' 'daa' 'ccf' 'sra' 'swap' 'nop')
1495 ; common peephole
96b move
%3 %5 before
%4 %1, %2
1498 } if
same(%3 'inc' 'dec'), same(%5 'hl'), same(%4 'ld' 'ldh' 'cp' 'add' 'adc' 'and' 'or' 'xor' 'sub' 'sbc' 'set' 'res' 'bit' 'in' 'out' 'in0' 'out0'), operandsNotRelated(%1 %5), operandsNotRelated(%2 %5)
1504 ; common peephole
96c move
%3 %4 before
%2 %1
1507 } if
same(%3 'inc' 'dec'), same(%4 'hl'), same(%2 'inc' 'dec' 'rl' 'rlc' 'rr' 'rrc' 'srl' 'sla' 'sra' 'swap'), operandsNotRelated(%1 %4), operandsNotRelated(%2 %4)
1513 ; common peephole
96d move
%3 %4 before
%2 %1
1516 } if
same(%3 'inc' 'dec'), same(%4 'hl'), same(%2 'push' 'pop'), notSame(%1 %4)
1518 // check if constant loaded
into (hl
) is the same that
's loaded into the second register
1523 ; common peephole 97a reused constant loaded into register pair. %2 %3
1526 } if same(%1 'bc
' 'de
'), operandsLiteral(%2 %3), canSplitReg(%1 %4 %5), immdInRange(0x00 0xff '&' %3 0xff %7), immdInRange(0 0 '-' %7 %2 %8)
1527 // ., ., ., ., get second byte, compare second byte with %2
1529 // check if constant loaded into (hl) is the same that's loaded into the first register
1534 ; common peephole
97b reused constant loaded into register pair.
1537 } if
same(%1 'bc' 'de'), operandsLiteral(%2 %3), canSplitReg(%1 %4 %5), immdInRange(0x00 0xff '/' %3 0xff %6), immdInRange(0x00 0xff '&' %6 0xff %7), immdInRange(0 0 '-' %7 %2 %8)
1538 // .
, .
, .
, .
, bit shift
, get second byte
, compare second byte with
%2
1545 ; common peephole
98 removed redundant load from
%1 into a.
1546 } if
notVolatile(%1), notSame(%1 '(hl+)' '(hl-)')
1547 // This gives many false negatives and without the test no problems are encountered in the regression tests
1548 // Maybe we can try this after
2.7.0 release
1555 ; common peephole
98a removed redundant load of
%1 from
%2 (ix
)
1565 ; common peephole
99 removed load by reordering or arguments.
1566 } if
notVolatile(%1), canAssign('b' %2), notSame(%1 '(hl+)' '(hl-)')
1567 // canAssign('b' %2) is true
, iff or a
,%2 is possible.
1577 ; common peephole
99a removed load by reordering or arguments.
1585 ; common peephole
99b removed redundant or argument.
1593 ; common peephole
100 removed redundant or after and.
1601 ; common peephole
100a removed redundant or after and.
1611 ; common peephole
100b removed redundant or after
%2
1613 } if
same(%2 'inc' 'dec'), notUsed('cf' 'hf' 'nf' 'sf' 'pf')
1620 ; common peephole
101 removed redundant or after xor.
1628 ; common peephole
102 removed redundant or after xor.
1635 ; common peephole
102a removed redundant or after dec.
1644 ; common peephole
102b removed redundant or after dec.
1649 //TODO
: check on other flags
1658 ; common peephole
102c removed redundant or after sbc.
1659 } if
same(%2 'NZ' 'Z')
1669 ; common peephole
102d removed redundant or after sub.
1671 } if
same(%3 'NZ' 'Z')
1679 ; common peephole
103 loaded value in a first and used it next
1680 } if
notVolatile(%1 %2), canAssign(%1 'a'), operandsNotRelated(%1 %2), notSame(%1 '(hl+)' '(hl-)'), notSame(%2 '(hl+)' '(hl-)')
1682 // Cannot
allow (hl
) for
%2, as otherwise the first ld could have a different width from the
second (8- vs
16-bit
). E.g. ld hl
, (hl
)
1687 ; common peephole
103b loaded constant in
%2 first and used it next
1690 } if
notVolatile(%2), canAssign(%3 %2), same(%2 'a' 'b' 'c' 'd' 'e' 'h' 'l')
1700 ; common peephole
104 removed redundant load from
%3%1 into
%4%2
1701 } if
notVolatile(%1 %2 %3 %4), notSame(%1 '(hl+)' '(hl-)'), notSame(%2 '(hl+)' '(hl-)'), notSame(%3 '(hl+)' '(hl-)'), notSame(%4 '(hl+)' '(hl-)')
1710 ; common peephole
104b
%3 %1 directly to remove redundant load from
%2 into
%1
1711 } if
same(%1 'a' 'b' 'c' 'd' 'e' 'h' 'l' '(hl)'), same(%3 'inc' 'dec')
1721 ; common peephole
105 pushed de
1732 ; common peephole
106 fixed stack using hl instead of iy.
1733 } if
notUsed('hl'), notUsed('iy')
1744 ; common peephole
107 removed load from
%1 into a by replacing sub with cp
1746 } if
notVolatile(%1), notUsedFrom(%4 'a'), notSame(%1 '(hl+)' '(hl-)')
1756 ; common peephole
108 removed load from
%1 into a by replacing sub with cp
1758 } if
notUsedFrom(%4 'a')
1772 ; common peephole
109 replaced zero load
, rla by and since rlca writes the same value to carry bit and least significant bit.
1782 ; common peephole
110 moved
%2 directly into de instead of going through
%1.
1792 ; common peephole
111 removed lower part of multibyte addition.
1808 ; common peephole
112 used
16-bit addition.
1812 } if
operandsLiteral(%1 %2), immdInRange(0x00 0xffff '*' %2 0x100 %3), immdInRange(0x00 0xffff '|' %3 %1 %x4
), notUsed('hl')
1824 ; common peephole
113 used
16-bit addition.
1828 } if
operandsLiteral(%1 %2), immdInRange(0x00 0xffff '*' %2 0x100 %3), immdInRange(0x00 0xffff '|' %3 %1 %x4
), notUsed('hl')
1842 ; common peephole
114 incremented
in (hl
) instead of going through a.
1851 ; common peephole
115 incremented
in (hl
) instead of going through
%1.
1860 ; common peephole
115a
used (hl
) in in
%3 instead of going through
%1.
1862 } if
notVolatile(%2), notUsed(%1), same(%3 'adc' 'and' 'add' 'cp' 'or' 'sbc' 'sub' 'xor')
1870 ; common peephole
115b
used (hl
) in subtraction instead of going through
%1.
1872 } if
notUsed(%1), same(%3 'and' 'add' 'cp' 'or' 'sub' 'xor')
1874 // TODO
: Check for volatile?
1882 ; common peephole
116 incremented in
%2 (%3) instead of going through
%1.
1883 } if
canAssign('a' %1)
1885 // TODO
: Check for volatile?
1893 ; common peephole
117 decremented in
%2 (%3) instead of going through
%1.
1894 } if
canAssign('a' %1)
1902 ; common peephole
118 removed load by exploiting commutativity of addition.
1904 } if
notSame(%2 '(bc)' '(de)'), canAssign('b' %2)
1905 // canAssign('b' %2) is true
, iff add a
,%2 is possible.
1913 ; common peephole
119 removed loads by exploiting commutativity of addition.
1924 ; common peephole
120 removed loads by exploiting commutativity of addition.
1937 ; common peephole
121a replaced constant #
0x00 by
a (which has just been tested to be #
0x00).
1948 ; common peephole
121b replaced constant #
0x00 by
a (which has just been tested to be #
0x00).
1954 ; common peephole
123 optimize ld a
, %1
1956 } if
operandsLiteral(%1), immdInRange(0 0 '+' %1 0 %2), notUsed('f')
1966 ; common peephole
124 replaced constant #
0x00 by
a (which has just been tested to be #
0x00).
1977 ; common peephole
125a replaced constant #
0x00 by
a (which has just been tested to be #
0x00).
1988 ; common peephole
125b replaced constant #
0x00 by
a (which has just been tested to be #
0x00).
2000 ; common peephole
126a shortened or using
a (which has just been tested to be #
0x00).
2001 } if
canAssign('b' %3)
2002 // canAssign('b' %2) is true
, iff or a
,%2 is possible.
2015 ; common peephole
126b shortened or using
a (which has just been tested to be #
0x00).
2016 } if
canAssign('b' %3)
2027 ; common peephole
127a shortened or using
a (which has just been tested to be #
0x00).
2028 } if
canAssign('b' %3)
2029 // canAssign('b' %2) is true
, iff or a
,%2 is possible.
2042 ; common peephole
127b shortened or using
a (which has just been tested to be #
0x00).
2043 } if
canAssign('b' %3)
2045 //TODO
: check on other flags
2060 ; common peephole
128a sped up loop body.
2063 } if
same(%4 'or' 'and'), canSplitReg(%1 %0 %0), labelRefCountChange(%2 -1)
2065 //TODO
: check on other flags
2091 ; common peephole
128b sped up loop body.
2093 } if
canSplitReg(%5 %7 %8), canSplitReg(%6 %9 %10), operandsNotRelated(%3 %5 %6), operandsNotRelated(%3 %5 %6), notSame(%3 %4), labelRefCount(%2 1)
2120 ; common peephole
128c sped up loop body.
2122 } if
canSplitReg(%5 %7 %8), canSplitReg(%6 %9 %10), operandsNotRelated(%3 %5 %6), operandsNotRelated(%3 %5 %6), notSame(%3 %4), labelRefCount(%2 1)
2131 ; common peephole
129a moved increment of hl to constant.
2132 } if
operandsLiteral(%1), immdInRange(0 0xFFFF '+' %1 1 %x3
)
2134 // breaks
130 otherwise
2142 ; common peephole
129b moved decrement of hl to constant.
2143 } if
operandsLiteral(%1), immdInRange(0 0xFFFF '-' %1 1 %x3
)
2152 ; common peephole
129c moved increment of hl to constant.
2162 ; common peephole
129d moved decrement of hl to constant.
2168 ; common peephole
130a removed unnecessary
+0 from constant
2172 //TODO
: %2 matches
4+1+1
2176 ; common peephole
130b added
+%3 to immediate
%2
2178 } if
operandsLiteral(%2 %3), immdInRange(0 0xFF '+' %2 %3 %x4
)
2183 ; common peephole
130c added
+%3 to immediate
%2
2185 } if
operandsLiteral(%2 %3), immdInRange(0 0xFFFF '+' %2 %3 %x4
), canSplitReg(%1 %0 %0)
2190 ; common peephole
130d removed unnecessary
-0 from constant
2197 ; common peephole
130e subtracted
-%3 from immediate
%2
2199 } if
operandsLiteral(%2 %3), immdInRange(0 0xFF '-' %2 %3 %x4
)
2204 ; common peephole
130f subtracted
-%3 from to immediate
%2
2206 } if
operandsLiteral(%2 %3), immdInRange(0 0xFFFF '-' %2 %3 %x4
), canSplitReg(%1 %0 %0)
2213 // ; common peephole
130g removed unnecessary
+0 to immediate
2220 ; common peephole
130h removed unnecessary
+0 to immediate
2234 ; common peephole
131a incremented in hl instead of iy.
2245 ; common peephole
131b incremented in bc instead of iy.
2256 ; common peephole
132 added in iy instead of hl.
2257 } if
notUsed('hl'), notSame(%2 'hl')
2263 ; common peephole
133 removed redundant pop af.
2271 ; common peephole
134 removed redundant inc sp.
2280 ; common peephole
135 replaced call at end of function by
jump (tail call optimization
).
2281 } if
symmParmStack(%1)
2291 ; common peephole
136 replaced call at end of function by jump moving call beyond pop
ix (tail call optimization
).
2292 } if
symmParmStack(%1)
2301 ; common peephole
137 removed load of #
%2 into
%1 since it
's still there.
2302 } if notVolatile(%1), operandsNotRelated(%3 %1), notSame(%1 '(hl
+)' '(hl
-)')
2308 ; common peephole 138 used #%1 from hl for load into de.
2322 ; common peephole 139 replaced addition by increment.
2330 ; common peephole 140 removed ex exploiting commutativity of addition.
2340 ; common peephole 140a removed ex exploiting commutativity of addition.
2350 ; common peephole 140b removed ex exploiting commutativity of addition.
2359 ; common peephole 140c removed ex before push
2361 } if notUsed('de
' 'hl
')
2367 ; common peephole 140d removed ex before push
2369 } if notUsed('de
' 'hl
')
2378 ; common peephole 141 moved increment to constant.
2384 // those might work for tlcs90 too
2389 ; common peephole 142 used ex to move hl onto the stack.
2391 } if isPort('z80
' 'ez80_z80
' 'z180
' 'z80n
'), notUsed('a
'), notUsed('hl
')
2399 ; common peephole 143 used ex to move hl onto the stack.
2401 } if isPort('z80
' 'ez80_z80
' 'z180
' 'z80n
'), notUsed('a
'), notUsed('hl
')
2411 ; common peephole 144 used ex to move #%1 onto the stack.
2413 } if isPort('z80
' 'ez80_z80
' 'z180
' 'z80n
'), notUsed('a
'), notUsed('hl
')
2425 ; common peephole 145 used ex to move %1 (ix) %2 (ix) onto the stack.
2427 } if isPort('z80
' 'ez80_z80
' 'z180
' 'z80n
'), notUsed('a
'), notUsed('hl
')
2437 ; common peephole 146 used ex to move #%1 onto the stack.
2439 } if isPort('z80
' 'ez80_z80
' 'z180
' 'z80n
'), notUsed('a
'), notUsed('hl
')
2448 ; common peephole 147 directly used #%2 instead of going through %1 using indirect addressing.
2461 ; common peephole 148 used #%2 directly instead of going through %1 using indirect addressing.
2464 } if notSame(%3 'a
')
2471 ; common peephole 149 tested bit %2 of a directly instead of going through %1.
2481 ; common peephole 150 used sign flag instead of testing bit 7.
2482 } if isPort('z80
' 'ez80_z80
' 'z180
' 'z80n
' 'tlcs90
')
2493 ; common peephole 151 used value still in a instead of reloading from %1.
2501 ; common peephole 152 removed unused ret.
2511 ; common peephole 153 removed unused ret.
2521 ; common peephole 154a removed redundant zeroing of a (which has just been tested to be #0x00).
2522 } if same(%4 'or
' 'and
'), notUsed('f
')
2531 ; common peephole 154b removed redundant zeroing of a (which has just been tested to be #0x00).
2532 } if same(%4 'inc
' 'dec
'), notUsed('f
')
2541 ; common peephole 154c reuseded zero of register (which has just been tested to be #0x00).
2543 } if same(%4 'inc
' 'dec
'), notUsed('f
')
2548 ; common peephole 155a turned add into inc.
2550 } if operandsLiteral(%1), immdInRange(1 1 '+' %1 0 %2), notUsed('cf
')
2555 ; common peephole 155b turned sub into dec.
2557 } if operandsLiteral(%1), immdInRange(1 1 '+' %1 0 %2), notUsed('cf
')
2562 ; common peephole 155c turned add into dec.
2564 } if operandsLiteral(%1), immdInRange(0xFF 0xFF '+' %1 0 %2), notUsed('cf
')
2570 ; common peephole 156a swap dec %1 / inc %1 pair.
2579 ; common peephole 156b removed inc %1 / dec %1 pair.
2580 } if same(%1 'bc
' 'de
' 'hl
' 'ix
' 'iy
' 'sp
')
2586 ; common peephole 156c removed inc %1 / dec %1 pair.
2587 } if same(%1 'a
' 'b
' 'c
' 'd
' 'e
' 'h
' 'l
' 'ixh
' 'ixl
' 'iyh
' 'iyl
'), notUsed('zf
' 'vf
' 'sf
' 'nf
' 'hf
')
2594 ; common peephole 156e removed inc %1 / dec %1 pair.
2598 } if same(%1 'bc
' 'de
' 'hl
' 'ix
' 'iy
' 'sp
'), same(%2 'bc
' 'de
' 'hl
' 'ix
' 'iy
' 'sp
'), operandsNotRelated(%1 %2)
2612 ; common peephole 168z used double assignment in case of Z condition.
2614 } if labelRefCountChange(%2 -1)
2628 ; common peephole 168nz used double assignment in case of NZ condition.
2630 } if labelRefCountChange(%2 -1)
2642 ; common peephole 169xz used double assignment in case of Z condition.
2646 } if labelRefCountChange(%2 -1)
2658 ; common peephole 169xnz used double assignment in case of NZ condition.
2662 } if labelRefCountChange(%2 -1)
2676 ; common peephole 170z used double assignment in case of Z condition.
2678 } if labelRefCountChange(%2 -1)
2692 ; common peephole 170nz used double assignment in case of NZ condition.
2694 } if labelRefCountChange(%2 -1)
2708 ; common peephole 171z used double assignment in case of Z condition.
2710 } if labelRefCountChange(%2 -1)
2724 ; common peephole 171nz used double assignment in case of NZ condition.
2726 } if labelRefCountChange(%2 -1)
2740 ; common peephole 172z used double assignment in case of Z condition.
2742 } if labelRefCountChange(%2 -1)
2756 ; common peephole 172nz used double assignment in case of NZ condition.
2758 } if labelRefCountChange(%2 -1)
2765 ; common peephole 173 eliminated assignment by pushing %6
2767 } if canJoinRegs(%2 %1 %7), same(%7 %5), canJoinRegs(%4 %3 %6), notUsed(%5)
2769 // have to be applied late, slows down asm otherwise
2777 ; common peephole 174a reused value still in %1.
2780 } if notSame(%1 'ix
' 'iy
'), notSame(%2 'ix
' 'iy
'), canSplitReg(%1 %5 %6), canSplitReg(%2 %7 %8), operandsLiteral(%3 %4), immdInRange(0 0 '-' %3 %4 %9)
2782 // special case for ix/iy, which can't load to
/from hl
2790 ; common peephole
174b reused value still in
%1.
2793 } if
notSame(%1 'hl'), notSame(%2 'hl'), canSplitReg(%1 %5 %6), canSplitReg(%2 %7 %8), operandsLiteral(%3 %4), immdInRange(0 0 '-' %3 %4 %9), notSame(%1 'ix' 'iy'), notSame(%2 'ix' 'iy')
2800 ; common peephole
176a remove unnecessary load back
2801 } if
notVolatile(%1), notVolatile(%2), notSame(%1 '(hl+)' '(hl-)'), notSame(%2 '(hl+)' '(hl-)')
2803 // dec is left there to be removed by other rules
2815 ; common peephole
176b remove unnecessary load back
2818 } if
canSplitReg(%1 %0 %0)
2825 ; common peephole
177a replace pushed register pair
2826 } if
notUsed('a'), canJoinRegs(%1 '' %2), canSplitReg(%2 %3), same(%3 %1)
2833 ; common peephole
177b bubbled down push
2844 ; common peephole
177c bubbled down push
2852 ; common peephole
178 moved increment of
%3 after ld instruction
2855 } if
operandsNotRelated(%1 %3), immdInRange(-128 127 '+' %2 1 %4)
2861 ; common peephole
179 moved decrement of
%3 after ld instruction
2864 } if
operandsNotRelated(%1 %3), immdInRange(-128 127 '-' %2 1 %4)
2866 //next rules optimize code after the call
2867 //replaces lot of `inc sp` by `ld hl
,#n
; add hl
,sp
; ld sp
,hl`
2874 ; common peephole
190: move pop instruction after register store
2877 } if
notSame(%1 %3 %4), operandsNotRelated(%1 %4)
2883 ; common peephole
191a
: move register store before stack restore
2886 } if
notSame(%2 'sp')
2893 ; common peephole
191b
: move register to register copy before SP increment
2897 } if
same(%3 'l' 'h'), notSame(%2 'l' 'h'), notUsed('hl'), operandsNotRelated(%1 %2 %3), notSame('sp' %2 %3)
2903 ; common peephole
191c
: move register store before stack restore
2906 } if
notUsed('hl'), same(%2 'h' 'l' 'sp'), notSame(%1 'h' 'l' 'sp')
2914 ; common peephole
192: increase SP by addition
2918 } if
notUsed(%3), same(%3 'hl' 'ix' 'iy'), immdInRange(0 0x7fff '+' %1 1 %2)
2927 ; common peephole
193: increase SP by addition
2933 //next rules optimized some checks
2945 ; common peephole
194-1: symplify
32-bit compare for
8 bit values
2954 } if
same(%5 'jr' 'jp' 'call'), notUsed('a'), canAssign('b' %3), canAssign('b' %3), newLabel(%9)
2967 ; common peephole
194-2: symplify
32-bit compare for
16 bit values
2977 } if
same(%5 'jr' 'jp' 'call'), notUsed('a'), canAssign('b' %3), newLabel(%9)
2984 ; common peephole
195-1: remove always true check
2985 } if
same(%2 'jr' 'jp' 'call'), notUsed('a'), labelRefCountChange(%3 -1)
2994 ; common peephole
195-2: remove always true check
2995 } if
same(%3 'jr' 'jp' 'call'), notUsed('a'), labelRefCountChange(%4 -1)
2997 // These ex
-generating rules should be among the last ones since ex counts as a read from both hl and de for
notUsed().
3004 ; common peephole
156 used ex to load hl into de.
3006 } if
isPort('z80' 'ez80_z80' 'z180' 'z80n' 'r2k' 'r2ka' 'r3ka' 'tlcs90'), notUsed('hl')
3012 ; common peephole
157 used ex to load de into hl.
3014 } if
isPort('z80' 'ez80_z80' 'z180' 'z80n' 'r2k' 'r2ka' 'r3ka' 'tlcs90'), notUsed('de')
3016 // We want this one
, even if it doesn
't trigger in regression tests, since it is geh last line
3017 // of defence against ld r, r in the compiler. ld r, r is not just an inefficiency, but dangerous
3018 // for Rabbits. ld r, r support is inconsistent among Rabbits, and even otherwise binary-compatible
3019 // Rabbits differ in their support for it.
3024 ; common peephole 158 removed redundant ld %1, %1.
3025 } if notVolatile(%1)
3029 // Should be one of the last ones. Opens the code to further peephole optimization.
3033 ; common peephole 159 removed unused label %1.
3034 } if labelRefCount(%1 0)
3036 // Ensure that all rules above see only jp, not jr.
3037 // Also do all jump optimizations before replacing by ret.
3044 ; common peephole 160 replaced jump by return.
3045 } if labelIsReturnOnly(%5), labelRefCountChange(%5 -1)
3047 // SM83 doesn't have ret cc for all flags
, but it does for all flags for which is has JP CC.
3048 // This rules can be dangerous for Rabbits
: it might trigger a hardware bug in the Rabbit
5000.
3053 ; common peephole
161 replaced jump by return.
3054 } if
labelIsReturnOnly(%5), labelRefCountChange(%5 -1)
3056 // Replace jp by ret before replacing jp by jr
, since using ret can reduce the number of references to jump labels.
3059 // On Z80 and Z80N
, jr is smaller
, but slower than jp.
3063 ; common peephole
162 changed absolute to relative unconditional jump.
3065 } if
optimizeFor('!code-speed'), labelInRange(%5)
3067 // On Z180
, eZ80
, Rabbit and TLCS
-90, jr is smaller
, and at least as fast as jp.
3071 ; common peephole
162a changed absolute to relative unconditional jump.
3073 } if
isPort('z180' 'ez80_z80' 'r2k' 'r2ka' 'r3ka' 'tlcs90' 'sm83' 'r800'), labelInRange(%5)
3078 ; common peephole
163 changed absolute to relative conditional jump.
3080 } if
same(%1 'C' 'NC' 'NZ' 'Z'), labelInRange(%5)
3086 ; common peephole
164 eliminated relative conditional jump.
3087 } if
labelRefCountChange(%5 -1)
3093 ; common peephole
167 used djnz
3095 } if
isPort('z80' 'ez80_z80' 'z180' 'z80n' 'r2k' 'r2ka' 'r3ka' 'tlcs90')