5 // ; Peephole 1 removed pop %1 push %1 (not push pop)
13 // ; Peephole 2 removed pop %1 push %1 (not push pop)
18 // added by Jean Louis VERN for
24 ; Peephole 2.a removed redundant xch xch
32 ; Peephole 3.a changed mov to clr
42 ; Peephole 3.b changed mov to clr
48 // saving 1 byte, loosing 1 cycle but maybe allowing peephole 3.b to start
53 ; Peephole 3.c changed mov to clr
66 ; Peephole 100 removed redundant mov
75 ; Peephole 100.a removed redundant mov
85 ; Peephole 101 removed redundant mov
103 ; Peephole 102 removed redundant mov
125 ; Peephole 103 removed redundant mov
142 ; Peephole 104 optimized increment (acc not set to r%1, flags undefined)
151 ; Peephole 105 removed redundant mov
160 ; Peephole 106 removed redundant mov
169 ; Peephole 107 removed redundant ljmp
178 ; Peephole 108 removed ljmp by inverse jump logic
188 ; Peephole 109 removed ljmp by inverse jump logic
198 ; Peephole 110 removed ljmp by inverse jump logic
208 ; Peephole 111 removed ljmp by inverse jump logic
218 ; Peephole 112.a removed ljmp by inverse jump logic
227 ; Peephole 112.b changed ljmp to sjmp
241 ; Peephole 113 optimized misc sequence
246 } if labelRefCount %3 1
257 ; Peephole 114 optimized misc sequence
263 } if labelRefCount %3 2
272 ; Peephole 115 jump optimization
276 } if labelRefCount %3 1
286 ; Peephole 116 jump optimization
291 } if labelRefCount %3 2
302 ; Peephole 117 jump optimization
308 } if labelRefCount %3 3
320 ; Peephole 118 jump optimization
327 } if labelRefCount %3 4
336 ; Peephole 119 jump optimization
339 } if labelRefCount %3 1
349 ; Peephole 120 jump optimization
353 } if labelRefCount %3 2
364 ; Peephole 121 jump optimization
369 } if labelRefCount %3 3
381 ; Peephole 122 jump optimization
387 } if labelRefCount %3 4
396 ; Peephole 123 jump optimization
400 } if labelRefCount %3 1
410 ; Peephole 124 jump optimization
415 } if labelRefCount %3 2
426 ; Peephole 125 jump optimization
432 } if labelRefCount %3 3
444 ; Peephole 126 jump optimization
451 } if labelRefCount %3 4
464 ; Peephole 127 removed misc sequence
466 } if labelRefCount %3 0
473 ; Peephole 128 jump optimization
482 ; Peephole 129 jump optimization
489 ; Peephole 130 changed target address mode r%1 to ar%1
499 ; Peephole 131 optimized decrement (not caring for c)
511 ; Peephole 133 removed redundant moves
524 ; Peephole 134 removed redundant moves
535 ; Peephole 135 removed redundant mov
546 ; Peephole 136 removed redundant moves
552 // WTF? Doesn't look sensible to me...
562 // ; Peephole 137 optimized misc jump sequence
566 //} if labelRefCount %4 1
577 // ; Peephole 138 optimized misc jump sequence
582 //} if labelRefCount %4 1
589 ; Peephole 139 removed redundant mov
599 ; Peephole 140 removed redundant mov
608 ; Peephole 141 removed redundant mov
618 ; Peephole 142 removed redundant moves
627 ; Peephole 143 converted rlc to rl
635 ; Peephole 144 converted rrc to rc
643 ; Peephole 145 changed to add without carry
652 ; Peephole 146 changed to add without carry
660 ; Peephole 147 changed target address mode r%1 to ar%1
667 ; Peephole 148 changed target address mode r%1 to ar%1
674 ; Peephole 149 changed target address mode r%1 to ar%1
684 ; Peephole 150 removed misc moves via dpl before return
697 ; Peephole 151 removed misc moves via dph, dpl before return
709 ; Peephole 152 removed misc moves via dph, dpl before return
724 ; Peephole 153 removed misc moves via dph, dpl, b before return
737 ; Peephole 154 removed misc moves via dph, dpl, b before return
751 ; Peephole 155 removed misc moves via dph, dpl, b before return
768 ; Peephole 156 removed misc moves via dph, dpl, b, a before return
783 ; Peephole 157 removed misc moves via dph, dpl, b, a before return
797 ; Peephole 158 removed misc moves via dph, dpl, b, a before return
806 ; Peephole 159 avoided xrl during execution
815 ; Peephole 160 removed sjmp by inverse jump logic
825 ; Peephole 161 removed sjmp by inverse jump logic
835 ; Peephole 162 removed sjmp by inverse jump logic
845 ; Peephole 163 removed sjmp by inverse jump logic
855 ; Peephole 164 removed sjmp by inverse jump logic
865 ; Peephole 165 removed sjmp by inverse jump logic
875 ; Peephole 166 removed redundant mov
878 } if notVolatile %1 %2
885 ; Peephole 167 removed redundant bit moves (c not set to %1)
894 ; Peephole 168 jump optimization
904 ; Peephole 169 jump optimization
916 ; Peephole 170 jump optimization
919 } if labelRefCount %3 1
929 ; Peephole 171 jump optimization
933 } if labelRefCount %3 2
944 ; Peephole 172 jump optimization
949 } if labelRefCount %3 3
961 ; Peephole 173 jump optimization
967 } if labelRefCount %3 4
976 ; Peephole 174 optimized decrement (acc not set to %2, flags undefined)
987 ; Peephole 175 optimized increment (acc not set to %2, flags undefined)
997 ; Peephole 176 optimized increment, removed redundant mov
1002 // this one will screw assignes to volatile/sfr's
1007 ; Peephole 177.a removed redundant mov
1009 } if notVolatile %1 %2
1011 // applies to f.e. scott-add.asm (--model-large)
1016 ; Peephole 177.b removed redundant mov
1020 // applies to f.e. bug-408972.c
1025 ; Peephole 177.c removed redundant move
1027 } if notVolatile %1 %2
1029 // applies to f.e. bug-408972.c
1030 // not before peephole 177.c
1036 ; Peephole 177.d removed redundant move
1039 } if notVolatile %1 %2
1046 ; Peephole 178 removed redundant mov
1051 // rules 179-182 provided by : Frieder <fe@lake.iup.uni-heidelberg.de>
1052 // saving 2 byte, 1 cycle
1057 ; Peephole 179 changed mov to clr
1063 // volatile xdata char t; t=0x01; t=0x03;
1070 ; Peephole 180.a removed redundant mov to dptr
1076 // volatile xdata char t; t=0x01; t=0x03; t=0x01;
1085 ; Peephole 180.b removed redundant mov to dptr
1093 // saving 1 byte, 0 cycles
1097 ; Peephole 181 changed mov to clr
1101 // saving 3 bytes, 2 cycles
1102 // provided by Bernhard Held <bernhard.held@de.westinghouse.com>
1107 ; Peephole 182.a used 16 bit load of DPTR
1111 // saving 3 byte, 2 cycles, return(NULL) profits here
1116 ; Peephole 182.b used 16 bit load of dptr
1120 // saving 3 byte, 2 cycles. Probably obsoleted by 182.b
1125 ; Peephole 182.c used 16 bit load of dptr
1126 mov dptr,#(((%2)<<8) + %1)
1133 ; Peephole 183 avoided anl during execution
1142 ; Peephole 184 removed redundant mov
1148 // acc being incremented might cause problems
1152 ; Peephole 185 changed order of increment (acc incremented also!)
1177 ; Peephole 186.a optimized movc sequence
1209 ; Peephole 186.b optimized movc sequence
1234 ; Peephole 186.c optimized movc sequence
1243 // char indexed access to: char code table[] = {4,3,2,1};
1253 ; Peephole 186.d optimized movc sequence
1258 // char indexed access to: int code table[] = {4,3,2,1};
1273 ; Peephole 186.e optimized movc sequence (b, dptr differ)
1291 ; Peephole 187 used a instead of ar%1 for anl
1303 ; Peephole 188 removed redundant mov
1315 ; Peephole 189 removed redundant mov and anl
1320 // rules 190 & 191 need to be in order
1326 ; Peephole 190 removed redundant mov
1338 ; Peephole 191 removed redundant mov
1349 ; Peephole 192 used a instead of ar%1 as source
1366 ; Peephole 193.a optimized misc jump sequence
1376 } if labelRefCount %3 4
1390 ; Peephole 193.b optimized misc jump sequence
1400 } if labelRefCount %3 4
1414 ; Peephole 193.c optimized misc jump sequence
1424 } if labelRefCount %3 4
1435 ; Peephole 194 optimized misc jump sequence
1442 } if labelRefCount %3 4
1454 ; Peephole 195.a optimized misc jump sequence
1462 } if labelRefCount %3 3
1474 ; Peephole 195.b optimized misc jump sequence
1482 } if labelRefCount %3 3
1494 ; Peephole 195.c optimized misc jump sequence
1502 } if labelRefCount %3 3
1512 ; Peephole 196 optimized misc jump sequence
1518 } if labelRefCount %3 3
1528 ; Peephole 197.a optimized misc jump sequence
1534 } if labelRefCount %3 2
1544 ; Peephole 197.b optimized misc jump sequence
1550 } if labelRefCount %3 2
1560 ; Peephole 197.c optimized misc jump sequence
1566 } if labelRefCount %3 2
1575 ; Peephole 198 optimized misc jump sequence
1580 } if labelRefCount %3 2
1588 ; Peephole 199 optimized misc jump sequence
1592 } if labelRefCount %3 1
1598 ; Peephole 200 removed redundant sjmp
1607 ; Peephole 201 removed redundant sjmp
1617 ; Peephole 202 removed redundant push pop
1626 ; Peephole 203 removed mov r%1,_spx
1635 ; Peephole 204 removed redundant mov
1647 ; Peephole 205 optimized misc jump sequence
1651 } if labelRefCount %2 1
1656 ; Peephole 206 removed redundant mov %1,%1
1664 ; Peephole 207 removed zero add (acc not set to %1, flags undefined)
1673 ; Peephole 208 removed redundant push pop
1683 ; Peephole 209 optimized increment (acc not set to %1, flags undefined)
1689 mov dptr,#((((%1 >> 8)) <<8) + %1)
1691 ; Peephole 210 simplified expression
1699 ; Peephole 211 removed redundant push %1 pop %1
1707 ; Peephole 212 reduced add sequence to inc
1713 mov %1,#(( %2 >> 8 ) ^ 0x80)
1715 ; Peephole 213.a inserted fix
1721 mov %1,#(( %2 + %3 >> 8 ) ^ 0x80)
1723 ; Peephole 213.b inserted fix
1724 mov %1,#((%2 + %3) >> 8)
1734 ; Peephole 214 reduced some extra moves
1737 } if operandsNotSame
1744 ; Peephole 215 removed some moves
1747 } if operandsNotSame
1757 ; Peephole 216 simplified clear (2bytes)
1776 ; Peephole 217 simplified clear (3bytes)
1800 ; Peephole 218 simplified clear (4bytes)
1819 ; Peephole 219 removed redundant clear
1835 ; Peephole 219.a removed redundant clear
1848 ; Peephole 220.a removed bogus DPS set
1856 ; Peephole 220.b removed bogus DPS set
1861 mov %1 + %2,(%2 + %1)
1863 ; Peephole 221.a remove redundant move
1867 mov (%1 + %2 + %3),((%2 + %1) + %3)
1869 ; Peephole 221.b remove redundant move
1876 ; Peephole 222 removed dec/inc pair
1885 ; Peephole 223 removed redundant dph/dpl moves
1888 } if notVolatile %1 %2
1896 ; Peephole 224 removed redundant dph/dpl moves
1909 ; Peephole 225 removed redundant move to acc
1925 ; Peephole 226 removed unnecessary clr
1947 ; Peephole 227 replaced inefficient 32 bit clear
1975 ; Peephole 228 replaced inefficient 32 constant
1997 ; Peephole 229 replaced inefficient 16 bit clear
2015 ; Peephole 230 replaced inefficient 16 bit constant
2025 // this last peephole often removes the last mov from 227-230
2030 ; Peephole 231 removed redundant mov to dptr
2037 ; Peephole 232 using movc to read xdata (--xram-movc)
2045 ; Peephole 233 using _gptrgetc instead of _gptrget (--xram-movc)
2055 ; Peephole 234 loading dpl directly from a(ccumulator), r%1 not set
2068 ; Peephole 235 loading dph directly from a(ccumulator), r%1 not set
2075 // 14 rules by Fiorenzo D. Ramaglia <fd.ramaglia@tin.it>
2080 ; Peephole 236.a used r%1 instead of ar%1
2087 ; Peephole 236.b used r%1 instead of ar%1
2094 ; Peephole 236.c used r%1 instead of ar%1
2101 ; Peephole 236.d used r%1 instead of ar%1
2108 ; Peephole 236.e used r%1 instead of ar%1
2115 ; Peephole 236.f used r%1 instead of ar%1
2122 ; Peephole 236.g used r%1 instead of ar%1
2129 ; Peephole 236.h used r%1 instead of ar%1
2136 ; Peephole 236.i used r%1 instead of ar%1
2143 ; Peephole 236.j used r%1 instead of ar%1
2150 ; Peephole 236.k used r%1 instead of ar%1
2157 ; Peephole 236.l used r%1 instead of ar%1
2164 ; Peephole 236.m used r%1 instead of ar%1
2171 ; Peephole 236.n used r%1 instead of ar%1
2182 ; Peephole 237.a removed sjmp to ret
2199 ; Peephole 237.b removed sjmp to ret
2209 // applies to f.e. device/lib/log10f.c
2235 ; Peephole 238.a removed 4 redundant moves
2236 } if operandsNotSame8 %1 %2 %3 %4 %5 %6 %7 %8
2238 // applies to device/lib/log10f.c
2253 ; Peephole 238.b removed 3 redundant moves
2254 } if operandsNotSame7 %1 %2 %3 %4 %5 %6 %7
2256 // applies to f.e. device/lib/time.c
2272 ; Peephole 238.c removed 2 redundant moves
2273 } if operandsNotSame4 %1 %2 %3 %4
2275 // applies to f.e. support/regression/tests/bug-524209.c
2288 ; Peephole 238.d removed 3 redundant moves
2289 } if operandsNotSame6 %1 %2 %3 %4 %5 %6
2291 // applies to f.e. ser_ir.asm
2295 ; Peephole 239 used a instead of acc
2303 ; Peephole 240 use clr instead of addc a,#0
2308 // peepholes 241.a to 241.c and 241.d to 241.f need to be in order
2320 ; Peephole 241.a optimized compare
2331 // applies to f.e. time.c
2341 ; Peephole 241.b optimized compare
2350 // applies to f.e. malloc.c
2359 ; Peephole 241.c optimized compare
2367 // applies to f.e. j = (k!=0x1000);
2368 // with volatile idata long k;
2383 ; Peephole 241.d optimized compare
2397 // applies to f.e. j = (k!=0x1000);
2398 // with volatile idata int k;
2409 ; Peephole 241.e optimized compare
2419 // applies to f.e. vprintf.asm (--stack-auto)
2428 ; Peephole 241.f optimized compare
2436 // applies to f.e. scott-bool1.c
2443 ; Peephole 242.a avoided branch jnz to jz
2448 } if labelRefCount %1 1
2450 // applies to f.e. scott-bool1.c
2458 ; Peephole 242.b avoided branch jnz to jz
2464 } if labelRefCount %1 1
2466 // applies to f.e. logic.c
2476 ; Peephole 242.c avoided branch jnz to jz
2484 } if labelRefCount %1 1
2486 // applies to f.e. vprintf.c
2487 // this is a rare case, usually the "tail increment" is noticed earlier
2494 ; Peephole 243 avoided branch to sjmp
2501 // applies to f.e. simplefloat.c (saving 1 cycle)
2506 ; Peephole 244.a moving first to a instead of r%1
2511 // applies to f.e. _itoa.c (saving 1 cycle)
2516 ; Peephole 244.b moving first to a instead of r%1
2522 // applies to f.e. bug-460010.c (saving 1 cycle)
2527 ; Peephole 244.c loading dpl from a instead of r%1
2536 ; Peephole 244.d loading dph from a instead of r%1
2541 // this one is safe but disables 245.a 245.b
2542 // please remove 245 if 245.a 245.b are found to be safe
2543 // applies to f.e. scott-compare.c
2554 ; Peephole 245 optimized complement (r%1 and acc set needed?)
2559 } if labelRefCount %2 1
2561 // this one will not be triggered if 245 is present
2562 // please remove 245 if 245.a 245.b are found to be safe
2563 // applies to f.e. vprintf.c
2575 ; Peephole 245.a optimized conditional jump (r%1 and acc not set!)
2577 } if labelRefCount %2 1
2579 // this one will not be triggered if 245 is present
2580 // please remove 245 if 245.a 245.b are found to be safe
2581 // applies to f.e. scott-compare.c
2593 ; Peephole 245.b optimized conditional jump (r%1 and acc not set!)
2595 } if labelRefCount %2 1
2598 // rules 246.x apply to f.e. bitfields.c
2609 ; Peephole 246.a combined clr/clr
2626 ; Peephole 246.b combined set/set
2643 ; Peephole 246.c combined set/clr
2661 ; Peephole 246.d combined clr/set
2680 ; Peephole 246.e combined set/clr/clr
2699 ; Peephole 246.f combined set/clr/set
2719 ; Peephole 246.g combined clr/set/clr
2739 ; Peephole 246.h combined clr/set/set
2750 // rules 247.x apply to f.e. bitfields.c
2761 ; Peephole 247.a combined clr/clr
2778 ; Peephole 247.b combined set/set
2795 ; Peephole 247.c combined set/clr
2813 ; Peephole 247.d combined clr/set
2832 ; Peephole 247.e combined set/clr/clr
2851 ; Peephole 247.f combined set/clr/set
2871 ; Peephole 247.g combined clr/set/clr
2891 ; Peephole 247.h combined clr/set/set
2900 // Peepholes 248.x have to be compatible with the keyword volatile.
2901 // They optimize typical accesses to memory mapped I/O devices:
2902 // volatile xdata char t; t|=0x01;
2912 ; Peephole 248.a optimized or to xdata
2920 // volatile xdata char t; t&=0x01;
2930 ; Peephole 248.b optimized and to xdata
2938 // volatile xdata char t; t^=0x01;
2948 ; Peephole 248.c optimized xor to xdata
2956 // volatile xdata char t; t|=0x01; t&=~0x01; t|=0x01;
2976 ; Peephole 248.d optimized or/and/or to volatile xdata
2990 // volatile xdata char t; t&=~0x01; t|=0x01; t&=~0x01;
3010 ; Peephole 248.e optimized and/or/and to volatile xdata
3024 // volatile xdata char t; t|=0x01; t&=~0x01;
3038 ; Peephole 248.f optimized or/and to volatile xdata
3049 // volatile xdata char t; t&=~0x01; t|=0x01;
3063 ; Peephole 248.g optimized and/or to volatile xdata
3074 // volatile xdata char t; t^=0x01; t^=0x01;
3088 ; Peephole 248.h optimized xor/xor to volatile xdata
3103 ; Peephole 249a jump optimization
3104 } if labelRefCount %1 1
3110 ; Peephole 249b jump optimization
3111 } if labelRefCount %1 1
3114 // This allows non-interrupt and interrupt code to safely compete
3115 // for a resource without the non-interrupt code having to disable
3117 // volatile bit resource_is_free;
3118 // if( resource_is_free ) {
3119 // resource_is_free=0; do_something; resource_is_free=1;
3126 ; Peephole 250.a using atomic test and clear
3130 } if labelRefCount %3 0
3138 ; Peephole 250.b using atomic test and clear
3142 } if labelRefCount %2 1
3145 // not before peephole 250.b
3149 ; Peephole 251 replaced ljmp to ret with ret
3151 } if labelIsReturnOnly
3153 // applies to shifts.c and when accessing arrays with an unsigned integer index
3154 // saving 1 byte, 2 cycles
3164 ; Peephole 252 optimized left shift