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
1210 ; Peephole 186.b optimized movc sequence
1235 ; Peephole 186.c optimized movc sequence
1244 // char indexed access to: char code table[] = {4,3,2,1};
1254 ; Peephole 186.d optimized movc sequence
1259 // char indexed access to: int code table[] = {4,3,2,1};
1274 ; Peephole 186.e optimized movc sequence (b, dptr differ)
1292 ; Peephole 187 used a instead of ar%1 for anl
1304 ; Peephole 188 removed redundant mov
1316 ; Peephole 189 removed redundant mov and anl
1321 // rules 190 & 191 need to be in order
1327 ; Peephole 190 removed redundant mov
1339 ; Peephole 191 removed redundant mov
1350 ; Peephole 192 used a instead of ar%1 as source
1367 ; Peephole 193.a optimized misc jump sequence
1377 } if labelRefCount %3 4
1391 ; Peephole 193.b optimized misc jump sequence
1401 } if labelRefCount %3 4
1415 ; Peephole 193.c optimized misc jump sequence
1425 } if labelRefCount %3 4
1436 ; Peephole 194 optimized misc jump sequence
1443 } if labelRefCount %3 4
1455 ; Peephole 195.a optimized misc jump sequence
1463 } if labelRefCount %3 3
1475 ; Peephole 195.b optimized misc jump sequence
1483 } if labelRefCount %3 3
1495 ; Peephole 195.c optimized misc jump sequence
1503 } if labelRefCount %3 3
1513 ; Peephole 196 optimized misc jump sequence
1519 } if labelRefCount %3 3
1529 ; Peephole 197.a optimized misc jump sequence
1535 } if labelRefCount %3 2
1545 ; Peephole 197.b optimized misc jump sequence
1551 } if labelRefCount %3 2
1561 ; Peephole 197.c optimized misc jump sequence
1567 } if labelRefCount %3 2
1576 ; Peephole 198 optimized misc jump sequence
1581 } if labelRefCount %3 2
1589 ; Peephole 199 optimized misc jump sequence
1593 } if labelRefCount %3 1
1599 ; Peephole 200 removed redundant sjmp
1608 ; Peephole 201 removed redundant sjmp
1618 ; Peephole 202 removed redundant push pop
1627 ; Peephole 203 removed mov r%1,_spx
1636 ; Peephole 204 removed redundant mov
1648 ; Peephole 205 optimized misc jump sequence
1652 } if labelRefCount %2 1
1657 ; Peephole 206 removed redundant mov %1,%1
1665 ; Peephole 207 removed zero add (acc not set to %1, flags undefined)
1674 ; Peephole 208 removed redundant push pop
1684 ; Peephole 209 optimized increment (acc not set to %1, flags undefined)
1690 mov dptr,#((((%1 >> 8)) <<8) + %1)
1692 ; Peephole 210 simplified expression
1700 ; Peephole 211 removed redundant push %1 pop %1
1708 ; Peephole 212 reduced add sequence to inc
1714 mov %1,#(( %2 >> 8 ) ^ 0x80)
1716 ; Peephole 213.a inserted fix
1722 mov %1,#(( %2 + %3 >> 8 ) ^ 0x80)
1724 ; Peephole 213.b inserted fix
1725 mov %1,#((%2 + %3) >> 8)
1735 ; Peephole 214 reduced some extra moves
1738 } if operandsNotSame
1745 ; Peephole 215 removed some moves
1748 } if operandsNotSame
1758 ; Peephole 216 simplified clear (2bytes)
1777 ; Peephole 217 simplified clear (3bytes)
1801 ; Peephole 218 simplified clear (4bytes)
1820 ; Peephole 219 removed redundant clear
1836 ; Peephole 219.a removed redundant clear
1849 ; Peephole 220.a removed bogus DPS set
1857 ; Peephole 220.b removed bogus DPS set
1862 mov %1 + %2,(%2 + %1)
1864 ; Peephole 221.a remove redundant move
1868 mov (%1 + %2 + %3),((%2 + %1) + %3)
1870 ; Peephole 221.b remove redundant move
1877 ; Peephole 222 removed dec/inc pair
1886 ; Peephole 223 removed redundant dph/dpl moves
1889 } if notVolatile %1 %2
1897 ; Peephole 224 removed redundant dph/dpl moves
1910 ; Peephole 225 removed redundant move to acc
1926 ; Peephole 226 removed unnecessary clr
1948 ; Peephole 227 replaced inefficient 32 bit clear
1976 ; Peephole 228 replaced inefficient 32 constant
1998 ; Peephole 229 replaced inefficient 16 bit clear
2016 ; Peephole 230 replaced inefficient 16 bit constant
2026 // this last peephole often removes the last mov from 227-230
2031 ; Peephole 231 removed redundant mov to dptr
2038 ; Peephole 232 using movc to read xdata (--xram-movc)
2046 ; Peephole 233 using _gptrgetc instead of _gptrget (--xram-movc)
2056 ; Peephole 234 loading dpl directly from a(ccumulator), r%1 not set
2069 ; Peephole 235 loading dph directly from a(ccumulator), r%1 not set
2076 // 14 rules by Fiorenzo D. Ramaglia <fd.ramaglia@tin.it>
2081 ; Peephole 236.a used r%1 instead of ar%1
2088 ; Peephole 236.b used r%1 instead of ar%1
2095 ; Peephole 236.c used r%1 instead of ar%1
2102 ; Peephole 236.d used r%1 instead of ar%1
2109 ; Peephole 236.e used r%1 instead of ar%1
2116 ; Peephole 236.f used r%1 instead of ar%1
2123 ; Peephole 236.g used r%1 instead of ar%1
2130 ; Peephole 236.h used r%1 instead of ar%1
2137 ; Peephole 236.i used r%1 instead of ar%1
2144 ; Peephole 236.j used r%1 instead of ar%1
2151 ; Peephole 236.k used r%1 instead of ar%1
2158 ; Peephole 236.l used r%1 instead of ar%1
2165 ; Peephole 236.m used r%1 instead of ar%1
2172 ; Peephole 236.n used r%1 instead of ar%1
2183 ; Peephole 237.a removed sjmp to ret
2200 ; Peephole 237.b removed sjmp to ret
2210 // applies to f.e. device/lib/log10f.c
2236 ; Peephole 238.a removed 4 redundant moves
2237 } if operandsNotSame8 %1 %2 %3 %4 %5 %6 %7 %8
2239 // applies to device/lib/log10f.c
2254 ; Peephole 238.b removed 3 redundant moves
2255 } if operandsNotSame7 %1 %2 %3 %4 %5 %6 %7
2257 // applies to f.e. device/lib/time.c
2273 ; Peephole 238.c removed 2 redundant moves
2274 } if operandsNotSame4 %1 %2 %3 %4
2276 // applies to f.e. support/regression/tests/bug-524209.c
2289 ; Peephole 238.d removed 3 redundant moves
2290 } if operandsNotSame6 %1 %2 %3 %4 %5 %6
2292 // applies to f.e. ser_ir.asm
2296 ; Peephole 239 used a instead of acc
2304 ; Peephole 240 use clr instead of addc a,#0
2309 // peepholes 241.a to 241.c and 241.d to 241.f need to be in order
2321 ; Peephole 241.a optimized compare
2332 // applies to f.e. time.c
2342 ; Peephole 241.b optimized compare
2351 // applies to f.e. malloc.c
2360 ; Peephole 241.c optimized compare
2368 // applies to f.e. j = (k!=0x1000);
2369 // with volatile idata long k;
2384 ; Peephole 241.d optimized compare
2398 // applies to f.e. j = (k!=0x1000);
2399 // with volatile idata int k;
2410 ; Peephole 241.e optimized compare
2420 // applies to f.e. vprintf.asm (--stack-auto)
2429 ; Peephole 241.f optimized compare
2437 // applies to f.e. scott-bool1.c
2444 ; Peephole 242.a avoided branch jnz to jz
2449 } if labelRefCount %1 1
2451 // applies to f.e. scott-bool1.c
2459 ; Peephole 242.b avoided branch jnz to jz
2465 } if labelRefCount %1 1
2467 // applies to f.e. logic.c
2477 ; Peephole 242.c avoided branch jnz to jz
2485 } if labelRefCount %1 1
2487 // applies to f.e. vprintf.c
2488 // this is a rare case, usually the "tail increment" is noticed earlier
2495 ; Peephole 243 avoided branch to sjmp
2502 // applies to f.e. simplefloat.c (saving 1 cycle)
2507 ; Peephole 244.a moving first to a instead of r%1
2512 // applies to f.e. _itoa.c (saving 1 cycle)
2517 ; Peephole 244.b moving first to a instead of r%1
2523 // applies to f.e. bug-460010.c (saving 1 cycle)
2528 ; Peephole 244.c loading dpl from a instead of r%1
2537 ; Peephole 244.d loading dph from a instead of r%1
2542 // this one is safe but disables 245.a 245.b
2543 // please remove 245 if 245.a 245.b are found to be safe
2544 // applies to f.e. scott-compare.c
2555 ; Peephole 245 optimized complement (r%1 and acc set needed?)
2560 } if labelRefCount %2 1
2562 // this one will not be triggered if 245 is present
2563 // please remove 245 if 245.a 245.b are found to be safe
2564 // applies to f.e. vprintf.c
2576 ; Peephole 245.a optimized conditional jump (r%1 and acc not set!)
2578 } if labelRefCount %2 1
2580 // this one will not be triggered if 245 is present
2581 // please remove 245 if 245.a 245.b are found to be safe
2582 // applies to f.e. scott-compare.c
2594 ; Peephole 245.b optimized conditional jump (r%1 and acc not set!)
2596 } if labelRefCount %2 1
2599 // rules 246.x apply to f.e. bitfields.c
2610 ; Peephole 246.a combined clr/clr
2627 ; Peephole 246.b combined set/set
2644 ; Peephole 246.c combined set/clr
2662 ; Peephole 246.d combined clr/set
2681 ; Peephole 246.e combined set/clr/clr
2700 ; Peephole 246.f combined set/clr/set
2720 ; Peephole 246.g combined clr/set/clr
2740 ; Peephole 246.h combined clr/set/set
2751 // rules 247.x apply to f.e. bitfields.c
2762 ; Peephole 247.a combined clr/clr
2779 ; Peephole 247.b combined set/set
2796 ; Peephole 247.c combined set/clr
2814 ; Peephole 247.d combined clr/set
2833 ; Peephole 247.e combined set/clr/clr
2852 ; Peephole 247.f combined set/clr/set
2872 ; Peephole 247.g combined clr/set/clr
2892 ; Peephole 247.h combined clr/set/set
2901 // Peepholes 248.x have to be compatible with the keyword volatile.
2902 // They optimize typical accesses to memory mapped I/O devices:
2903 // volatile xdata char t; t|=0x01;
2913 ; Peephole 248.a optimized or to xdata
2921 // volatile xdata char t; t&=0x01;
2931 ; Peephole 248.b optimized and to xdata
2939 // volatile xdata char t; t^=0x01;
2949 ; Peephole 248.c optimized xor to xdata
2957 // volatile xdata char t; t|=0x01; t&=~0x01; t|=0x01;
2977 ; Peephole 248.d optimized or/and/or to volatile xdata
2991 // volatile xdata char t; t&=~0x01; t|=0x01; t&=~0x01;
3011 ; Peephole 248.e optimized and/or/and to volatile xdata
3025 // volatile xdata char t; t|=0x01; t&=~0x01;
3039 ; Peephole 248.f optimized or/and to volatile xdata
3050 // volatile xdata char t; t&=~0x01; t|=0x01;
3064 ; Peephole 248.g optimized and/or to volatile xdata
3075 // volatile xdata char t; t^=0x01; t^=0x01;
3089 ; Peephole 248.h optimized xor/xor to volatile xdata
3104 ; Peephole 249a jump optimization
3105 } if labelRefCount %1 1
3111 ; Peephole 249b jump optimization
3112 } if labelRefCount %1 1
3115 // This allows non-interrupt and interrupt code to safely compete
3116 // for a resource without the non-interrupt code having to disable
3118 // volatile bit resource_is_free;
3119 // if( resource_is_free ) {
3120 // resource_is_free=0; do_something; resource_is_free=1;
3127 ; Peephole 250.a using atomic test and clear
3131 } if labelRefCount %3 0
3139 ; Peephole 250.b using atomic test and clear
3143 } if labelRefCount %2 1
3146 // not before peephole 250.b
3150 ; Peephole 251.a replaced ljmp to ret with ret
3152 } if labelIsReturnOnly
3154 // not before peephole 250.b
3158 ; Peephole 251.b replaced sjmp to ret with ret
3160 } if labelIsReturnOnly
3162 // applies to shifts.c and when accessing arrays with an unsigned integer index
3163 // saving 1 byte, 2 cycles
3173 ; Peephole 252 optimized left shift
3182 // applies to: void test( char c ) { if( c ) func1(); else func2(); }
3187 ; Peephole 253.a replaced lcall/ret with ljmp
3191 // applies to: void test( char c ) { if( c ) func1(); else func2(); }
3197 ; Peephole 253.b replaced lcall/ret with ljmp
3199 } if labelRefCount %2 0
3201 // applies to f.e. scott-bool1.c
3207 ; Peephole 253.c replaced lcall with ljmp