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
69 ; Peephole 3.d removed redundant clr
83 ; Peephole 3.e removed redundant clr
99 ; Peephole 3.f removed redundant clr
117 ; Peephole 3.g removed redundant clr
129 ; Peephole 3.h changed mov %3,#0x00 to ...,a
144 ; Peephole 3.i changed mov %4,#0x00 to ...,a
161 ; Peephole 3.j changed mov %5,#0x00 to ...,a
180 ; Peephole 3.k changed mov %6,#0x00 to ...,a
192 ; Peephole 100 removed redundant mov
206 ; Peephole 101 removed redundant mov
221 ; Peephole 102 removed redundant mov
243 ; Peephole 103 removed redundant mov
260 ; Peephole 104 optimized increment (acc not set to r%1, flags undefined)
270 ; Peephole 105 removed redundant mov
280 ; Peephole 106 removed redundant mov
287 ; Peephole 107 removed redundant ljmp
289 } if labelRefCountChange(%1 -1)
296 ; Peephole 108.a removed ljmp by inverse jump logic
299 } if labelInRange(), labelRefCountChange(%1 -1)
306 ; Peephole 108.b removed ljmp by inverse jump logic
309 } if labelInRange(), labelRefCountChange(%1 -1)
316 ; Peephole 108.c removed ljmp by inverse jump logic
319 } if labelInRange(), labelRefCountChange(%1 -1)
326 ; Peephole 108.d removed ljmp by inverse jump logic
329 } if labelInRange(), labelRefCountChange(%2 -1)
336 ; Peephole 108.e removed ljmp by inverse jump logic
339 } if labelInRange(), labelRefCountChange(%2 -1)
345 ; Peephole 112.b changed ljmp to sjmp
358 ; Peephole 113.a optimized misc sequence
363 } if labelRefCount %3 1
374 ; Peephole 113.b optimized misc sequence
380 } if labelRefCount %3 2
389 ; Peephole 115.a jump optimization (acc not set)
393 } if labelRefCount %3 1
402 ; Peephole 115.b jump optimization
405 } if labelRefCountChange(%2 -1)
415 ; Peephole 115.c jump optimization (acc not set)
420 } if labelRefCount %3 2
431 ; Peephole 115.d jump optimization (acc not set)
437 } if labelRefCount %3 3
449 ; Peephole 115.e jump optimization (acc not set)
456 } if labelRefCount %3 4
465 ; Peephole 115.f jump optimization (acc not set)
468 } if labelRefCount(%3 1), labelRefCountChange(%3 -1)
478 ; Peephole 115.g jump optimization (acc not set)
482 } if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%4 1)
493 ; Peephole 115.h jump optimization (acc not set)
498 } if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%4 2)
510 ; Peephole 115.i jump optimization (acc not set)
516 } if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%4 3)
525 ; Peephole 115.j jump optimization (acc not set)
529 } if labelRefCount %3 1
539 ; Peephole 115.k jump optimization (acc not set)
544 } if labelRefCount %3 2
555 ; Peephole 115.l jump optimization (acc not set)
561 } if labelRefCount %3 3
573 ; Peephole 115.m jump optimization (acc not set)
580 } if labelRefCount %3 4
593 ; Peephole 127 removed misc sequence
595 } if labelRefCount %3 0
602 ; Peephole 128 jump optimization
606 // applies to: bug-524691.c --model-large: while (uRight - uLeft > 1)
612 ; Peephole 129.a jump optimization
616 // applies to: _fsdiv.c --xstack: if (mant1 < mant2)
623 ; Peephole 129.b optimized condition
628 // applies to: time.c --xstack: while((days += (LEAP_YEAR(year) ? 366 : 365)) <= epoch)
636 ; Peephole 129.c optimized condition
640 } if notVolatile %1 %2
642 // applies to: _memmove.c --xstack: if (((int)src < (int)dst) && ((((int)src)+acount) > (int)dst))
651 ; Peephole 129.d optimized condition
656 } if notVolatile %1 %2 %3
661 ; Peephole 130 changed target address mode r%1 to ar%1
671 ; Peephole 131 optimized decrement (not caring for c)
676 // ideally the optimizations of rules 132.x should be done in genCmpXX
683 ; Peephole 132.a optimized genCmpGt by inverse logic (acc differs)
695 ; Peephole 132.b optimized genCmpGt by inverse logic (acc differs)
707 ; Peephole 132.c optimized genCmpGt by inverse logic (acc differs)
719 ; Peephole 132.d optimized genCmpGt by inverse logic
723 } if operandsNotRelated('0x00' %2)
725 //This peephole caused bug #1453093
732 // ; Peephole 132.e optimized genCmpLt by inverse logic (carry differs)
736 //} if operandsNotRelated('0x00' %2)
744 ; Peephole 132.f optimized genCmpLt by inverse logic (carry differs)
748 } if operandsNotRelated('0x00' %2)
759 ; Peephole 133 removed redundant moves
772 ; Peephole 134 removed redundant moves
783 ; Peephole 135 removed redundant mov
796 ; Peephole 136 removed redundant move
799 // WTF? Doesn't look sensible to me...
809 // ; Peephole 137 optimized misc jump sequence
813 //} if labelRefCount %4 1
824 // ; Peephole 138 optimized misc jump sequence
829 //} if labelRefCount %4 1
836 ; Peephole 139.a removed redundant mov
846 ; Peephole 139.b removed redundant mov
855 ; Peephole 139.c removed redundant mov
865 ; Peephole 142 removed redundant moves
874 ; Peephole 143.a converted rlc to rl
882 ; Peephole 143.b converted rrc to rc
890 ; Peephole 145.a changed to add without carry
899 ; Peephole 145.b changed to add without carry
904 // 147: Fix compiler output to comply with 8051 instruction set.
908 ; Peephole 147.a changed target address mode r%1 to ar%1
915 ; Peephole 147.b changed target address mode r%1 to ar%1
922 ; Peephole 147.c changed target address mode r%1 to ar%1
932 ; Peephole 150.a removed misc moves via dpl before return
945 ; Peephole 150.b removed misc moves via dph, dpl before return
957 ; Peephole 150.c removed misc moves via dph, dpl before return
972 ; Peephole 150.d removed misc moves via dph, dpl, b before return
985 ; Peephole 150.e removed misc moves via dph, dpl, b before return
999 ; Peephole 150.f removed misc moves via dph, dpl, b before return
1016 ; Peephole 150.g removed misc moves via dph, dpl, b, a before return
1031 ; Peephole 150.h removed misc moves via dph, dpl, b, a before return
1045 ; Peephole 150.i removed misc moves via dph, dpl, b, a before return
1050 // peephole 213.a might revert this
1055 ; Peephole 159 avoided xrl during execution
1064 ; Peephole 160.a removed sjmp by inverse jump logic
1067 } if labelRefCountChange(%1 -1)
1074 ; Peephole 160.b removed sjmp by inverse jump logic
1077 } if labelRefCountChange(%1 -1)
1084 ; Peephole 160.c removed sjmp by inverse jump logic
1087 } if labelRefCountChange(%1 -1)
1094 ; Peephole 160.d removed sjmp by inverse jump logic
1097 } if labelRefCountChange(%1 -1)
1104 ; Peephole 160.e removed sjmp by inverse jump logic
1107 } if labelRefCountChange(%1 -1)
1114 ; Peephole 160.f removed sjmp by inverse jump logic
1117 } if labelRefCountChange(%1 -1)
1126 ; Peephole 166 removed redundant mov
1127 } if notVolatile %1 %2
1134 ; Peephole 167 removed redundant bit moves (c not set to %1)
1143 ; Peephole 168 jump optimization
1146 } if labelRefCountChange(%2 -1)
1153 ; Peephole 169 jump optimization
1156 } if labelRefCountChange(%2 -1)
1165 ; Peephole 170 jump optimization
1168 } if labelRefCount(%3 1), labelRefCountChange(%3 -1)
1178 ; Peephole 171 jump optimization
1182 } if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%4 1)
1193 ; Peephole 172 jump optimization
1198 } if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%4 2)
1210 ; Peephole 173 jump optimization
1216 } if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%4 3)
1226 ; Peephole 174.a optimized decrement (acc not set to %2, flags undefined)
1237 ; Peephole 174.b optimized increment (acc not set to %2, flags undefined)
1246 ; Peephole 174.c optimized increment, removed redundant mov
1251 // this one will screw assignes to volatile/sfr's
1257 ; Peephole 177.a removed redundant mov
1258 } if notVolatile %1 %2
1260 // applies to f.e. scott-add.asm (--model-large)
1266 ; Peephole 177.b removed redundant mov
1269 // applies to f.e. bug-408972.c
1274 ; Peephole 177.c removed redundant move
1276 } if notVolatile %1 %2
1278 // applies to f.e. bug-408972.c
1279 // not before peephole 177.c
1287 ; Peephole 177.d removed redundant move
1288 } if notVolatile(%1 %2),operandsNotRelated(%1 %2 %3)
1290 // applies to f.e. bug-607243.c
1291 // also check notVolatile %3, as it will return FALSE if it's @r%1
1296 ; peephole 177.e removed redundant move
1298 } if notVolatile %2 %3
1304 ; peephole 177.f removed redundant move
1312 ; peephole 177.g optimized mov sequence
1321 ; peephole 177.h optimized mov sequence
1331 ; Peephole 178 removed redundant mov
1336 // rules 179-182 provided by : Frieder <fe@lake.iup.uni-heidelberg.de>
1337 // saving 2 byte, 1 cycle
1342 ; Peephole 179 changed mov to clr
1348 // volatile xdata char t; t=0x01; t=0x03;
1358 ; Peephole 180.a removed redundant mov to dptr
1361 // volatile xdata char t; t=0x01; t=0x03; t=0x01;
1375 ; Peephole 180.b removed redundant mov to dptr
1378 // saving 1 byte, 0 cycles
1382 ; Peephole 181 changed mov to clr
1386 // saving 3 bytes, 2 cycles
1387 // provided by Bernhard Held <bernhard.held@de.westinghouse.com>
1392 ; Peephole 182.a used 16 bit load of DPTR
1396 // saving 3 byte, 2 cycles, return(NULL) profits here
1401 ; Peephole 182.b used 16 bit load of dptr
1405 // saving 3 byte, 2 cycles. Probably obsoleted by 182.b
1410 ; Peephole 182.c used 16 bit load of dptr
1411 mov dptr,#(((%2)<<8) + %1)
1414 // applies to return 0.0; in f.e. sincosf.c
1420 ; Peephole 182.d used 16 bit load of dptr
1421 mov dptr,#(%1&0x00ff)
1429 ; Peephole 183 avoided anl during execution
1438 ; Peephole 184 removed redundant mov
1444 // acc being incremented might cause problems
1448 ; Peephole 185 changed order of increment (acc incremented also!)
1473 ; Peephole 186.a optimized movc sequence
1506 ; Peephole 186.b optimized movc sequence
1531 ; Peephole 186.c optimized movc sequence
1540 // disabled due to bug #1434401
1541 //// char indexed access to: char code table[] = {4,3,2,1};
1546 // addc a,#(%1 >> 8)
1551 // ; Peephole 186.d optimized movc sequence
1556 // char indexed access to: int code table[] = {4,3,2,1};
1571 ; Peephole 186.e optimized movc sequence (b, dptr differ)
1589 ; Peephole 187 used a instead of ar%1 for anl
1601 ; Peephole 188 removed redundant mov
1615 ; Peephole 189 removed redundant mov and anl
1618 // rules 190 & 191 need to be in order
1626 ; Peephole 190 removed redundant mov
1640 ; Peephole 191 removed redundant mov
1648 ; Peephole 192 used a instead of ar%1 as source
1664 ; Peephole 193.a optimized misc jump sequence
1674 } if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
1688 ; Peephole 193.b optimized misc jump sequence
1698 } if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
1712 ; Peephole 193.c optimized misc jump sequence
1722 } if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
1733 ; Peephole 194 optimized misc jump sequence
1740 } if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
1752 ; Peephole 195.a optimized misc jump sequence
1760 } if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
1772 ; Peephole 195.b optimized misc jump sequence
1780 } if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
1792 ; Peephole 195.c optimized misc jump sequence
1800 } if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
1810 ; Peephole 196 optimized misc jump sequence
1816 } if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
1826 ; Peephole 197.a optimized misc jump sequence
1832 } if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
1842 ; Peephole 197.b optimized misc jump sequence
1848 } if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
1858 ; Peephole 197.c optimized misc jump sequence
1864 } if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
1873 ; Peephole 198.a optimized misc jump sequence
1878 } if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
1886 ; Peephole 198.b optimized misc jump sequence
1890 } if labelRefCount(%3 1), labelRefCountChange(%3 -1)
1896 ; Peephole 200.a removed redundant sjmp
1898 } if labelRefCountChange(%1 -1)
1905 ; Peephole 200.b removed redundant sjmp
1908 } if labelRefCountChange(%1 -1)
1915 ; Peephole 202 removed redundant push pop
1924 ; Peephole 203 removed mov r%1,_spx
1933 ; Peephole 204 removed redundant mov
1945 ; Peephole 205 optimized misc jump sequence
1949 } if labelRefCount(%2 1), labelRefCountChange(%2 -1), labelRefCountChange(%3 -1)
1954 ; Peephole 206 removed redundant mov %1,%1
1962 ; Peephole 207 removed zero add (acc not set to %1, flags undefined)
1971 ; Peephole 208 removed redundant push pop
1981 ; Peephole 209 optimized increment (acc not set to %1, flags undefined)
1987 mov dptr,#((((%1 >> 8)) <<8) + %1)
1989 ; Peephole 210 simplified expression
1997 ; Peephole 211 removed redundant push %1 pop %1
2005 ; Peephole 212 reduced add sequence to inc
2010 // reverts peephole 159? asx8051 cannot handle, too complex?
2012 mov %1,#(( %2 >> 8 ) ^ 0x80)
2014 ; Peephole 213.a inserted fix
2020 mov %1,#(( %2 + %3 >> 8 ) ^ 0x80)
2022 ; Peephole 213.b inserted fix
2023 mov %1,#((%2 + %3) >> 8)
2034 ; Peephole 214 reduced some extra moves
2036 } if operandsNotSame
2043 ; Peephole 215 removed some moves
2046 } if operandsNotSame
2058 ; Peephole 216.a simplified clear (2 bytes)
2077 ; Peephole 216.b simplified clear (3 bytes)
2101 ; Peephole 216.c simplified clear (4 bytes)
2118 ; Peephole 219.a removed redundant clear
2139 ; Peephole 219.b removed redundant clear
2147 ; Peephole 220.a removed bogus DPS set
2155 ; Peephole 220.b removed bogus DPS set
2160 mov %1 + %2,(%2 + %1)
2162 ; Peephole 221.a remove redundant move
2166 mov (%1 + %2 + %3),((%2 + %1) + %3)
2168 ; Peephole 221.b remove redundant move
2175 ; Peephole 222 removed dec/inc pair
2186 ; Peephole 223.a removed redundant dph/dpl moves
2187 } if notVolatile %1 %2
2197 ; Peephole 223.b removed redundant dph/dpl moves
2213 ; Peephole 225 removed redundant move to acc
2225 ; Peephole 226.a removed unnecessary clr
2241 ; Peephole 226.b removed unnecessary clr
2260 ; Peephole 227.a replaced inefficient 32 bit clear
2287 ; Peephole 227.b replaced inefficient 32 constant
2310 ; Peephole 227.c replaced inefficient 16 bit clear
2327 ; Peephole 227.d replaced inefficient 16 bit constant
2336 // this last peephole often removes the last mov from 227.a - 227.d
2341 ; Peephole 227.e removed redundant mov to dptr
2348 ; Peephole 232 using movc to read xdata (--xram-movc)
2356 ; Peephole 233 using _gptrgetc instead of _gptrget (--xram-movc)
2366 ; Peephole 234.a loading dpl directly from a(ccumulator), r%1 not set
2379 ; Peephole 234.b loading dph directly from a(ccumulator), r%1 not set
2386 // 14 rules by Fiorenzo D. Ramaglia <fd.ramaglia@tin.it>
2391 ; Peephole 236.a used r%1 instead of ar%1
2398 ; Peephole 236.b used r%1 instead of ar%1
2405 ; Peephole 236.c used r%1 instead of ar%1
2412 ; Peephole 236.d used r%1 instead of ar%1
2419 ; Peephole 236.e used r%1 instead of ar%1
2426 ; Peephole 236.f used r%1 instead of ar%1
2433 ; Peephole 236.g used r%1 instead of ar%1
2440 ; Peephole 236.h used r%1 instead of ar%1
2447 ; Peephole 236.i used r%1 instead of ar%1
2454 ; Peephole 236.j used r%1 instead of ar%1
2461 ; Peephole 236.k used r%1 instead of ar%1
2468 ; Peephole 236.l used r%1 instead of ar%1
2475 ; Peephole 236.m used r%1 instead of ar%1
2482 ; Peephole 236.n used r%1 instead of ar%1
2493 ; Peephole 237.a removed sjmp to ret
2499 } if labelRefCountChange(%1 -1)
2510 ; Peephole 237.b removed sjmp to ret
2518 } if labelRefCountChange(%1 -1)
2520 // applies to f.e. device/lib/log10f.c
2546 ; Peephole 238.a removed 4 redundant moves
2547 } if operandsNotSame8 %1 %2 %3 %4 %5 %6 %7 %8
2549 // applies to device/lib/log10f.c
2564 ; Peephole 238.b removed 3 redundant moves
2565 } if operandsNotSame7 %1 %2 %3 %4 %5 %6 %7
2567 // applies to f.e. device/lib/time.c
2583 ; Peephole 238.c removed 2 redundant moves
2584 } if operandsNotSame4 %1 %2 %3 %4
2586 // applies to f.e. support/regression/tests/bug-524209.c
2599 ; Peephole 238.d removed 3 redundant moves
2600 } if operandsNotSame6 %1 %2 %3 %4 %5 %6
2602 // applies to f.e. ser_ir.asm
2606 ; Peephole 239 used a instead of acc
2614 ; Peephole 240 use clr instead of addc a,#0
2619 // peepholes 241.a to 241.d and 241.e to 241.h need to be in order
2631 ; Peephole 241.a optimized compare
2640 } if labelRefCountChange(%1 -1)
2642 // applies to generic pointer compare
2653 ; Peephole 241.b optimized compare
2661 } if labelRefCountChange(%1 -1)
2663 // applies to f.e. time.c
2673 ; Peephole 241.c optimized compare
2680 } if labelRefCountChange(%1 -1)
2682 // applies to f.e. malloc.c
2691 ; Peephole 241.d optimized compare
2697 } if labelRefCountChange(%1 -1)
2699 // applies to f.e. j = (k!=0x1000);
2700 // with volatile idata long k;
2715 ; Peephole 241.e optimized compare
2727 } if labelRefCountChange(%2 -1)
2729 // applies to f.e. j = (p!=NULL);
2730 // with volatile idata char *p;
2743 ; Peephole 241.f optimized compare
2753 } if labelRefCountChange(%2 -1)
2755 // applies to f.e. j = (k!=0x1000);
2756 // with volatile idata int k;
2767 ; Peephole 241.g optimized compare
2775 } if labelRefCountChange(%2 -1)
2777 // applies to f.e. vprintf.asm (--stack-auto)
2786 ; Peephole 241.h optimized compare
2792 } if labelRefCountChange(%2 -1)
2794 // applies to f.e. scott-bool1.c
2803 ; Peephole 242.a avoided branch jnz to jz
2806 } if labelRefCount %1 1
2808 // applies to f.e. scott-bool1.c
2819 ; Peephole 242.b avoided branch jnz to jz
2822 } if labelRefCount %1 1
2824 // applies to f.e. logic.c
2839 ; Peephole 242.c avoided branch jnz to jz
2842 } if labelRefCount %1 1
2844 // applies to f.e. vprintf.c
2845 // this is a rare case, usually the "tail increment" is noticed earlier
2852 ; Peephole 243 avoided branch to sjmp
2857 } if labelInRange(), labelRefCountChange(%3 -1), labelRefCountChange(%5 1)
2859 // applies to f.e. simplefloat.c (saving 1 cycle)
2864 ; Peephole 244.a moving first to a instead of r%1
2869 // applies to f.e. _itoa.c (saving 1 cycle)
2874 ; Peephole 244.b moving first to a instead of r%1
2880 // applies to f.e. bug-460010.c (saving 1 cycle)
2886 ; Peephole 244.c loading dpl from a instead of r%1
2895 ; Peephole 244.d loading dph from a instead of r%1
2899 // this one is safe but disables 245.a 245.b
2900 // please remove 245 if 245.a 245.b are found to be safe
2901 // applies to f.e. scott-compare.c
2912 ; Peephole 245 optimized complement (r%1 and acc set needed?)
2917 } if labelRefCount(%2 1), labelRefCountChange(%2 -1)
2919 // this one will not be triggered if 245 is present
2920 // please remove 245 if 245.a 245.b are found to be safe
2921 // applies to f.e. vprintf.c
2933 ; Peephole 245.a optimized conditional jump (r%1 and acc not set!)
2935 } if labelRefCount(%2 1), labelRefCountChange(%2 -1)
2937 // this one will not be triggered if 245 is present
2938 // please remove 245 if 245.a 245.b are found to be safe
2939 // applies to f.e. scott-compare.c
2951 ; Peephole 245.b optimized conditional jump (r%1 and acc not set!)
2953 } if labelRefCount(%2 1), labelRefCountChange(%2 -1)
2956 // rules 246.x apply to f.e. bitfields.c
2969 ; Peephole 246.a combined clr/clr
2986 ; Peephole 246.b combined set/set
3004 ; Peephole 246.c combined set/clr
3022 ; Peephole 246.d combined clr/set
3041 ; Peephole 246.e combined set/clr/clr
3061 ; Peephole 246.f combined set/clr/set
3081 ; Peephole 246.g combined clr/set/clr
3100 ; Peephole 246.h combined clr/set/set
3108 // rules 247.x apply to f.e. bitfields.c
3121 ; Peephole 247.a combined clr/clr
3138 ; Peephole 247.b combined set/set
3156 ; Peephole 247.c combined set/clr
3174 ; Peephole 247.d combined clr/set
3193 ; Peephole 247.e combined set/clr/clr
3213 ; Peephole 247.f combined set/clr/set
3233 ; Peephole 247.g combined clr/set/clr
3252 ; Peephole 247.h combined clr/set/set
3258 // Peepholes 248.x have to be compatible with the keyword volatile.
3259 // They optimize typical accesses to memory mapped I/O devices:
3260 // volatile xdata char t; t|=0x01;
3273 ; Peephole 248.a optimized or to xdata
3278 // volatile xdata char t; t&=0x01;
3291 ; Peephole 248.b optimized and to xdata
3296 // volatile xdata char t; t^=0x01;
3309 ; Peephole 248.c optimized xor to xdata
3314 // volatile xdata char t; t|=0x01; t&=~0x01; t|=0x01;
3336 ; Peephole 248.d optimized or/and/or to volatile xdata
3348 // volatile xdata char t; t&=~0x01; t|=0x01; t&=~0x01;
3370 ; Peephole 248.e optimized and/or/and to volatile xdata
3382 // volatile xdata char t; t|=0x01; t&=~0x01;
3398 ; Peephole 248.f optimized or/and to volatile xdata
3407 // volatile xdata char t; t&=~0x01; t|=0x01;
3423 ; Peephole 248.g optimized and/or to volatile xdata
3432 // volatile xdata char t; t^=0x01; t^=0x01;
3448 ; Peephole 248.h optimized xor/xor to volatile xdata
3457 // Peeepholes 248.i to 248.m are like 248.d to 248.h except they apply to bitfields:
3458 // xdata struct { unsigned b0:1; unsigned b1:1; unsigned b2:1; } xport;
3459 // xport.b0=1; xport.b0=0; xport.b0=1;
3480 ; Peephole 248.i optimized or/and/or to xdata bitfield
3509 ; Peephole 248.j optimized and/or/and to xdata bitfield
3533 ; Peephole 248.k optimized or/and to xdata bitfield
3554 ; Peephole 248.l optimized and/or to xdata bitfield
3575 ; Peephole 248.m optimized xor/xor to xdata bitfield
3586 ; Peephole 249.a jump optimization
3587 } if labelRefCount(%1 1), labelRefCountChange(%1 -1)
3593 ; Peephole 249.b jump optimization
3594 } if labelRefCount(%1 1), labelRefCountChange(%1 -1)
3597 // This allows non-interrupt and interrupt code to safely compete
3598 // for a resource without the non-interrupt code having to disable
3600 // volatile bit resource_is_free;
3601 // if( resource_is_free ) {
3602 // resource_is_free=0; do_something; resource_is_free=1;
3609 ; Peephole 250.a using atomic test and clear
3613 } if labelRefCount(%3 0), labelRefCountChange(%3 1)
3621 ; Peephole 250.b using atomic test and clear
3625 } if labelRefCount %2 1
3628 // not before peephole 250.b
3632 ; Peephole 251.a replaced ljmp to ret with ret
3634 } if labelIsReturnOnly(), labelRefCountChange(%5 -1)
3636 // not before peephole 250.b
3640 ; Peephole 251.b replaced sjmp to ret with ret
3642 } if labelIsReturnOnly(), labelRefCountChange(%5 -1)
3644 // applies to shifts.c and when accessing arrays with an unsigned integer index
3645 // saving 1 byte, 2 cycles
3655 ; Peephole 252 optimized left shift
3664 // applies to: void test( char c ) { if( c ) func1(); else func2(); }
3669 ; Peephole 253.a replaced lcall/ret with ljmp
3673 // applies to: void test( char c ) { if( c ) func1(); else func2(); }
3679 ; Peephole 253.b replaced lcall/ret with ljmp
3682 } if labelRefCount %2 0
3684 // applies to f.e. scott-bool1.c
3690 ; Peephole 253.c replaced lcall with ljmp
3697 // applies to f.e. funptrs.c
3698 // saves one byte if %1 is a register or @register
3704 ; Peephole 254 optimized left shift
3708 // applies to f.e. switch.c
3721 ; Peephole 255 optimized jump table index calculation
3723 cjne a,#(%1+0x01),.+1
3732 // applies to f.e. jump tables and scott-bool1.c.
3733 // similar peepholes can be constructed for other instructions
3734 // after which a flag or a register is known (like: djnz, cjne, jnc)
3742 ; Peephole 256.a removed redundant clr c
3743 } if labelRefCount %2 0
3745 // applies to f.e. logf.c
3753 ; Peephole 256.b removed redundant clr a
3754 } if labelRefCount %2 0
3756 // applies to f.e. bug-905492.c
3764 ; Peephole 256.c loading %3 with zero from a
3766 } if labelRefCount %2 0
3768 // applies to f.e. malloc.c
3778 ; Peephole 256.d loading %3 with zero from a
3780 } if labelRefCount(%2 0),operandsNotRelated('a' %4)
3793 ; Peephole 256.e loading %3 with zero from a
3795 } if labelRefCount(%2 0),operandsNotRelated('a' %4 %6)
3810 ; Peephole 256.f loading %2 with zero from a
3812 } if labelRefCount(%2 0),operandsNotRelated('a' %4 %6 %8)
3815 // unsigned char i=8; do{ } while(--i != 0);
3816 // this currently only applies if i is kept in a register
3821 ; Peephole 257 optimized decrement with compare
3826 // in_byte<<=1; if(in_bit) in_byte|=1;
3827 // helps f.e. reading data on a 3-wire (SPI) bus
3838 ; Peephole 258.a optimized bitbanging
3844 } if notVolatile(%1), labelRefCountChange(%3 -1)
3846 // in_byte<<=1; if(in_bit) in_byte|=1;
3857 ; Peephole 258.b optimized bitbanging
3863 } if labelRefCountChange(%3 -1)
3865 // in_byte>>=1; if(in_bit) in_byte|=0x80;
3877 ; Peephole 258.c optimized bitbanging
3883 } if notVolatile(%1), labelRefCountChange(%3 -1)
3885 // in_byte>>=1; if(in_bit) in_byte|=0x80;
3897 ; Peephole 258.d optimized bitbanging
3903 } if labelRefCountChange(%3 -1)
3905 // out_bit=out_byte&0x80; out_byte<<=1;
3906 // helps f.e. writing data on a 3-wire (SPI) bus
3916 ; Peephole 258.e optimized bitbanging
3922 // out_bit=out_byte&0x01; out_byte>>=1;
3933 ; Peephole 258.f optimized bitbanging
3940 // Peepholes 259.x rely on the correct labelRefCount. Otherwise they are
3941 // not compatible with peepholes 250.x
3942 // Peepholes 250.x add jumps to a previously unused label. If the
3943 // labelRefCount is not increased, peepholes 259.x are (mistakenly) applied.
3944 // (Mail on sdcc-devel 2004-10-25)
3946 // applies to f.e. vprintf.c
3953 ; Peephole 259.a removed redundant label %2 and ret
3955 } if labelRefCount %2 0
3957 // applies to f.e. gets.c
3964 ; Peephole 259.b removed redundant label %2 and ret
3966 } if labelRefCount %2 0
3968 // optimizing jumptables
3969 // Please note: to enable peephole 260.x you currently have to set
3970 // the environment variable SDCC_SJMP_JUMPTABLE
3982 ; Peephole 260.a used sjmp in jumptable
3993 // optimizing jumptables
4006 ; Peephole 260.b used sjmp in jumptable
4018 // optimizing jumptables
4032 ; Peephole 260.c used sjmp in jumptable
4045 // optimizing jumptables
4060 ; Peephole 260.d used sjmp in jumptable
4074 // optimizing jumptables
4090 ; Peephole 260.e used sjmp in jumptable
4105 // optimizing jumptables
4123 ; Peephole 260.f used sjmp in jumptable
4140 // optimizing jumptables
4159 ; Peephole 260.g used sjmp in jumptable
4177 // optimizing jumptables
4197 ; Peephole 260.h used sjmp in jumptable
4216 // optimizing jumptables
4237 ; Peephole 260.i used sjmp in jumptable
4257 // optimizing jumptables
4279 ; Peephole 260.j used sjmp in jumptable
4300 // optimizing jumptables
4323 ; Peephole 260.k used sjmp in jumptable
4345 // optimizing jumptables
4369 ; Peephole 260.l used sjmp in jumptable
4392 // optimizing jumptables
4417 ; Peephole 260.m used sjmp in jumptable
4441 // applies to: a = (a << 1) | (a >> 15);
4455 ; Peephole 261.a optimized left rol
4463 // applies to: a = (a << 15) | (a >> 1);
4477 ; Peephole 261.b optimized right rol
4489 ; Peephole 262 removed redundant cpl c
4498 ; Peephole 263.a optimized loading const
4507 ; Peephole 263.b optimized loading const
4515 ; Peephole 263.c optimized loading const
4519 // should be one of the last peepholes
4523 ; Peephole 300 removed redundant label %1
4524 } if labelRefCount(%1 0)