Update svn merge history.
[sdcc.git] / sdcc / src / ds390 / peeph.def
blob7bfb9d3e5d4617f8887126ec7be7524f6f081022
1 //replace restart {
2 // pop %1
3 // push %1
4 //} by {
5 // ; Peephole 1 removed pop %1 push %1 (not push pop)
6 //}
8 //replace restart {
9 // pop %1
10 // mov %2,%3
11 // push %1
12 //} by {
13 // ; Peephole 2 removed pop %1 push %1 (not push pop)
14 // mov %2,%3
15 //}
18 // added by Jean Louis VERN for
19 // his shift stuff
20 replace restart {
21 xch a,%1
22 xch a,%1
23 } by {
24 ; Peephole 2.a removed redundant xch xch
27 replace restart {
28 // saving 2 byte
29 mov %1,#0x00
30 mov a,#0x00
31 } by {
32 ; Peephole 3.a changed mov to clr
33 clr a
34 mov %1,a
37 replace restart {
38 // saving 1 byte
39 mov %1,#0x00
40 clr a
41 } by {
42 ; Peephole 3.b changed mov to clr
43 clr a
44 mov %1,a
47 replace restart {
48 // saving 1 byte, loosing 1 cycle but maybe allowing peephole 3.b to start
49 mov %1,#0x00
50 mov %2,#0x00
51 mov a,%3
52 } by {
53 ; Peephole 3.c changed mov to clr
54 clr a
55 mov %1,a
56 mov %2,a
57 mov a,%3
60 replace restart {
61 mov a,#0
62 } by {
63 ; Peephole 3.d changed mov to clr
64 clr a
67 replace {
68 mov %1,a
69 mov dptr,#%2
70 mov a,%1
71 movx @dptr,a
72 } by {
73 ; Peephole 100 removed redundant mov
74 mov %1,a
75 mov dptr,#%2
76 movx @dptr,a
79 replace {
80 mov a,acc
81 } by {
82 ; Peephole 100.a removed redundant mov
85 replace {
86 mov a,%1
87 movx @dptr,a
88 inc dptr
89 mov a,%1
90 movx @dptr,a
91 } by {
92 ; Peephole 101 removed redundant mov
93 mov a,%1
94 movx @dptr,a
95 inc dptr
96 movx @dptr,a
99 replace {
100 mov %1,%2
101 ljmp %3
103 mov %1,%5
105 mov dpl,%1
107 mov sp,bp
108 pop bp
109 } by {
110 ; Peephole 102 removed redundant mov
111 mov dpl,%2
112 ljmp %3
114 mov dpl,%5
117 mov sp,bp
118 pop bp
121 replace {
122 mov %1,%2
123 ljmp %3
125 mov a%1,%5
127 mov dpl,%1
129 mov sp,bp
130 pop bp
131 } by {
132 ; Peephole 103 removed redundant mov
133 mov dpl,%2
134 ljmp %3
136 mov dpl,%5
139 mov sp,bp
140 pop bp
143 replace {
144 mov a,bp
145 clr c
146 add a,#0x01
147 mov r%1,a
148 } by {
149 ; Peephole 104 optimized increment (acc not set to r%1, flags undefined)
150 mov r%1,bp
151 inc r%1
154 replace {
155 mov %1,a
156 mov a,%1
157 } by {
158 ; Peephole 105 removed redundant mov
159 mov %1,a
162 replace {
163 mov %1,a
164 clr c
165 mov a,%1
166 } by {
167 ; Peephole 106 removed redundant mov
168 mov %1,a
169 clr c
172 replace {
173 ljmp %1
175 } by {
176 ; Peephole 107 removed redundant ljmp
180 replace {
181 jc %1
182 ljmp %5
184 } by {
185 ; Peephole 108 removed ljmp by inverse jump logic
186 jnc %5
188 } if labelInRange(%5)
190 replace {
191 jz %1
192 ljmp %5
194 } by {
195 ; Peephole 109 removed ljmp by inverse jump logic
196 jnz %5
198 } if labelInRange(%5)
200 replace {
201 jnz %1
202 ljmp %5
204 } by {
205 ; Peephole 110 removed ljmp by inverse jump logic
206 jz %5
208 } if labelInRange(%5)
210 replace {
211 jb %1,%2
212 ljmp %5
214 } by {
215 ; Peephole 111 removed ljmp by inverse jump logic
216 jnb %1,%5
218 } if labelInRange(%5)
220 replace {
221 jnb %1,%2
222 ljmp %5
224 } by {
225 ; Peephole 112 removed ljmp by inverse jump logic
226 jb %1,%5
228 } if labelInRange(%5)
230 replace {
231 ljmp %5
233 } by {
234 ; Peephole 132 changed ljmp to sjmp
235 sjmp %5
237 } if labelInRange(%5)
240 replace {
241 clr a
242 cjne %1,%2,%3
243 cpl a
245 rrc a
246 mov %4,c
247 } by {
248 ; Peephole 113 optimized misc sequence
249 clr %4
250 cjne %1,%2,%3
251 setb %4
253 } if labelRefCount %3 1
255 replace {
256 clr a
257 cjne %1,%2,%3
258 cjne %10,%11,%3
259 cpl a
261 rrc a
262 mov %4,c
263 } by {
264 ; Peephole 114 optimized misc sequence
265 clr %4
266 cjne %1,%2,%3
267 cjne %10,%11,%3
268 setb %4
270 } if labelRefCount %3 2
272 replace {
273 clr a
274 cjne %1,%2,%3
275 cpl a
277 jnz %4
278 } by {
279 ; Peephole 115 jump optimization
280 cjne %1,%2,%3
281 sjmp %4
283 } if labelRefCount %3 1
285 replace {
286 clr a
287 cjne %1,%2,%3
288 cjne %9,%10,%3
289 cpl a
291 jnz %4
292 } by {
293 ; Peephole 116 jump optimization
294 cjne %1,%2,%3
295 cjne %9,%10,%3
296 sjmp %4
298 } if labelRefCount %3 2
300 replace {
301 clr a
302 cjne %1,%2,%3
303 cjne %9,%10,%3
304 cjne %11,%12,%3
305 cpl a
307 jnz %4
308 } by {
309 ; Peephole 117 jump optimization
310 cjne %1,%2,%3
311 cjne %9,%10,%3
312 cjne %11,%12,%3
313 sjmp %4
315 } if labelRefCount %3 3
317 replace {
318 clr a
319 cjne %1,%2,%3
320 cjne %9,%10,%3
321 cjne %11,%12,%3
322 cjne %13,%14,%3
323 cpl a
325 jnz %4
326 } by {
327 ; Peephole 118 jump optimization
328 cjne %1,%2,%3
329 cjne %9,%10,%3
330 cjne %11,%12,%3
331 cjne %13,%14,%3
332 sjmp %4
334 } if labelRefCount %3 4
336 replace {
337 mov a,#0x01
338 cjne %1,%2,%3
339 clr a
341 jnz %4
342 } by {
343 ; Peephole 119 jump optimization
344 cjne %1,%2,%4
346 } if labelRefCount %3 1
348 replace {
349 mov a,#0x01
350 cjne %1,%2,%3
351 cjne %10,%11,%3
352 clr a
354 jnz %4
355 } by {
356 ; Peephole 120 jump optimization
357 cjne %1,%2,%4
358 cjne %10,%11,%4
360 } if labelRefCount %3 2
362 replace {
363 mov a,#0x01
364 cjne %1,%2,%3
365 cjne %10,%11,%3
366 cjne %12,%13,%3
367 clr a
369 jnz %4
370 } by {
371 ; Peephole 121 jump optimization
372 cjne %1,%2,%4
373 cjne %10,%11,%4
374 cjne %12,%13,%4
376 } if labelRefCount %3 3
378 replace {
379 mov a,#0x01
380 cjne %1,%2,%3
381 cjne %10,%11,%3
382 cjne %12,%13,%3
383 cjne %14,%15,%3
384 clr a
386 jnz %4
387 } by {
388 ; Peephole 122 jump optimization
389 cjne %1,%2,%4
390 cjne %10,%11,%4
391 cjne %12,%13,%4
392 cjne %14,%15,%4
394 } if labelRefCount %3 4
396 replace {
397 mov a,#0x01
398 cjne %1,%2,%3
399 clr a
401 jz %4
402 } by {
403 ; Peephole 123 jump optimization
404 cjne %1,%2,%3
405 smp %4
407 } if labelRefCount %3 1
409 replace {
410 mov a,#0x01
411 cjne %1,%2,%3
412 cjne %10,%11,%3
413 clr a
415 jz %4
416 } by {
417 ; Peephole 124 jump optimization
418 cjne %1,%2,%3
419 cjne %10,%11,%3
420 sjmp %4
422 } if labelRefCount %3 2
424 replace {
425 mov a,#0x01
426 cjne %1,%2,%3
427 cjne %10,%11,%3
428 cjne %12,%13,%3
429 clr a
431 jz %4
432 } by {
433 ; Peephole 125 jump optimization
434 cjne %1,%2,%3
435 cjne %10,%11,%3
436 cjne %12,%13,%3
437 sjmp %4
439 } if labelRefCount %3 3
441 replace {
442 mov a,#0x01
443 cjne %1,%2,%3
444 cjne %10,%11,%3
445 cjne %12,%13,%3
446 cjne %14,%15,%3
447 clr a
449 jz %4
450 } by {
451 ; Peephole 126 jump optimization
452 cjne %1,%2,%3
453 cjne %10,%11,%3
454 cjne %12,%13,%3
455 cjne %14,%15,%3
456 sjmp %4
458 } if labelRefCount %3 4
460 replace {
461 push psw
462 mov psw,%1
463 push bp
464 mov bp,%2
466 mov %2,bp
467 pop bp
468 pop psw
470 } by {
471 ; Peephole 127 removed misc sequence
473 } if labelRefCount %3 0
475 replace {
476 clr a
477 rlc a
478 jz %1
479 } by {
480 ; Peephole 128 jump optimization
481 jnc %1
484 replace {
485 clr a
486 rlc a
487 jnz %1
488 } by {
489 ; Peephole 129 jump optimization
490 jc %1
493 replace {
494 mov r%1,@r%2
495 } by {
496 ; Peephole 130 changed target address mode r%1 to ar%1
497 mov ar%1,@r%2
500 replace {
501 mov a,%1
502 subb a,#0x01
503 mov %2,a
504 mov %1,%2
505 } by {
506 ; Peephole 131 optimized decrement (not caring for c)
507 dec %1
508 mov %2,%1
511 replace {
512 mov r%1,%2
513 mov ar%3,@r%1
514 inc r%3
515 mov r%4,%2
516 mov @r%4,ar%3
517 } by {
518 ; Peephole 133 removed redundant moves
519 mov r%1,%2
520 inc @r%1
521 mov ar%3,@r%1
524 replace {
525 mov r%1,%2
526 mov ar%3,@r%1
527 dec r%3
528 mov r%4,%2
529 mov @r%4,ar%3
530 } by {
531 ; Peephole 134 removed redundant moves
532 mov r%1,%2
533 dec @r%1
534 mov ar%3,@r%1
537 replace {
538 mov r%1,a
539 mov a,r%2
540 orl a,r%1
541 } by {
542 ; Peephole 135 removed redundant mov
543 mov r%1,a
544 orl a,r%2
547 replace {
548 mov %1,a
549 mov dpl,%2
550 mov dph,%3
551 mov dpx,%4
552 mov a,%1
553 } by {
554 ; Peephole 136a removed redundant moves
555 mov %1,a
556 mov dpl,%2
557 mov dph,%3
558 mov dpx,%4
559 } if 24bitMode
561 replace {
562 mov %1,a
563 mov dpl,%2
564 mov dph,%3
565 mov a,%1
566 } by {
567 ; Peephole 136 removed redundant moves
568 mov %1,a
569 mov dpl,%2
570 mov dph,%3
573 // WTF? Doesn't look sensible to me...
574 //replace {
575 // mov b,#0x00
576 // mov a,%1
577 // cjne %2,%3,%4
578 // mov b,#0x01
579 //%4:
580 // mov a,b
581 // jz %5
582 //} by {
583 // ; Peephole 137 optimized misc jump sequence
584 // mov a,%1
585 // cjne %2,%3,%5
586 //%4:
587 //} if labelRefCount %4 1
589 //replace {
590 // mov b,#0x00
591 // mov a,%1
592 // cjne %2,%3,%4
593 // mov b,#0x01
594 //%4:
595 // mov a,b
596 // jnz %5
597 //} by {
598 // ; Peephole 138 optimized misc jump sequence
599 // mov a,%1
600 // cjne %2,%3,%4
601 // sjmp %5
602 //%4:
603 //} if labelRefCount %4 1
605 replace {
606 mov r%1,a
607 anl ar%1,%2
608 mov a,r%1
609 } by {
610 ; Peephole 139 removed redundant mov
611 anl a,%2
612 mov r%1,a
615 replace {
616 mov r%1,a
617 orl ar%1,%2
618 mov a,r%1
619 } by {
620 ; Peephole 140 removed redundant mov
621 orl a,%2
622 mov r%1,a }
624 replace {
625 mov r%1,a
626 xrl ar%1,%2
627 mov a,r%1
628 } by {
629 ; Peephole 141 removed redundant mov
630 xrl a,%2
631 mov r%1,a
634 replace {
635 mov r%1,a
636 mov r%2,ar%1
637 mov ar%1,@r%2
638 } by {
639 ; Peephole 142 removed redundant moves
640 mov r%2,a
641 mov ar%1,@r%2
644 replace {
645 rlc a
646 mov acc.0,c
647 } by {
648 ; Peephole 143 converted rlc to rl
649 rl a
652 replace {
653 rrc a
654 mov acc.7,c
655 } by {
656 ; Peephole 144 converted rrc to rc
657 rr a
660 replace {
661 clr c
662 addc a,%1
663 } by {
664 ; Peephole 145 changed to add without carry
665 add a,%1
668 replace {
669 clr c
670 mov a,%1
671 addc a,%2
672 } by {
673 ; Peephole 146 changed to add without carry
674 mov a,%1
675 add a,%2
678 replace {
679 orl r%1,a
680 } by {
681 ; Peephole 147 changed target address mode r%1 to ar%1
682 orl ar%1,a
685 replace {
686 anl r%1,a
687 } by {
688 ; Peephole 148 changed target address mode r%1 to ar%1
689 anl ar%1,a
692 replace {
693 xrl r%1,a
694 } by {
695 ; Peephole 149 changed target address mode r%1 to ar%1
696 xrl ar%1,a
699 replace {
700 mov %1,dpl
701 mov dpl,%1
704 } by {
705 ; Peephole 150 removed misc moves via dpl before return
710 replace {
711 mov %1,dpl
712 mov %2,dph
713 mov dpl,%1
714 mov dph,%2
717 } by {
718 ; Peephole 151 removed misc moves via dph, dpl before return
723 replace {
724 mov %1,dpl
725 mov %2,dph
726 mov dpl,%1
729 } by {
730 ; Peephole 152 removed misc moves via dph, dpl before return
735 replace {
736 mov %1,dpl
737 mov %2,dph
738 mov %3,b
739 mov dpl,%1
740 mov dph,%2
741 mov b,%3
744 } by {
745 ; Peephole 153 removed misc moves via dph, dpl, b before return
750 replace {
751 mov %1,dpl
752 mov %2,dph
753 mov %3,b
754 mov dpl,%1
757 } by {
758 ; Peephole 154 removed misc moves via dph, dpl, b before return
763 replace {
764 mov %1,dpl
765 mov %2,dph
766 mov %3,b
767 mov dpl,%1
768 mov dph,%2
771 } by {
772 ; Peephole 155 removed misc moves via dph, dpl, b before return
777 replace {
778 mov %1,dpl
779 mov %2,dph
780 mov %3,b
781 mov %4,a
782 mov dpl,%1
783 mov dph,%2
784 mov b,%3
785 mov a,%4
788 } by {
789 ; Peephole 156 removed misc moves via dph, dpl, b, a before return
794 replace {
795 mov %1,dpl
796 mov %2,dph
797 mov %3,b
798 mov %4,a
799 mov dpl,%1
800 mov dph,%2
803 } by {
804 ; Peephole 157 removed misc moves via dph, dpl, b, a before return
809 replace {
810 mov %1,dpl
811 mov %2,dph
812 mov %3,b
813 mov %4,a
814 mov dpl,%1
816 ret } by {
817 ; Peephole 158 removed misc moves via dph, dpl, b, a before return
819 ret }
821 replace {
822 mov %1,#%2
823 xrl %1,#0x80
824 } by {
825 ; Peephole 159 avoided xrl during execution
826 mov %1,#(%2 ^ 0x80)
829 replace {
830 jnc %1
831 sjmp %2
833 } by {
834 ; Peephole 160 removed sjmp by inverse jump logic
835 jc %2
836 %1:}
838 replace {
839 jc %1
840 sjmp %2
842 } by {
843 ; Peephole 161 removed sjmp by inverse jump logic
844 jnc %2
845 %1:}
847 replace {
848 jnz %1
849 sjmp %2
851 } by {
852 ; Peephole 162 removed sjmp by inverse jump logic
853 jz %2
854 %1:}
856 replace {
857 jz %1
858 sjmp %2
860 } by {
861 ; Peephole 163 removed sjmp by inverse jump logic
862 jnz %2
863 %1:}
865 replace {
866 jnb %3,%1
867 sjmp %2
869 } by {
870 ; Peephole 164 removed sjmp by inverse jump logic
871 jb %3,%2
875 replace {
876 jb %3,%1
877 sjmp %2
879 } by {
880 ; Peephole 165 removed sjmp by inverse jump logic
881 jnb %3,%2
885 replace {
886 mov %1,%2
887 mov %3,%1
888 mov %2,%1
889 } by {
890 ; Peephole 166 removed redundant mov
891 mov %1,%2
892 mov %3,%1 }
894 replace {
895 mov c,%1
896 cpl c
897 mov %1,c
898 } by {
899 ; Peephole 167 removed redundant bit moves (c not set to %1)
900 cpl %1 }
902 replace {
903 jnb %1,%2
904 sjmp %3
905 %2:} by {
906 ; Peephole 168 jump optimization
907 jb %1,%3
908 %2:}
910 replace {
911 jb %1,%2
912 sjmp %3
913 %2:} by {
914 ; Peephole 169 jump optimization
915 jnb %1,%3
916 %2:}
918 replace {
919 clr a
920 cjne %1,%2,%3
921 cpl a
923 jz %4
924 } by {
925 ; Peephole 170 jump optimization
926 cjne %1,%2,%4
928 } if labelRefCount %3 1
930 replace {
931 clr a
932 cjne %1,%2,%3
933 cjne %9,%10,%3
934 cpl a
936 jz %4
937 } by {
938 ; Peephole 171 jump optimization
939 cjne %1,%2,%4
940 cjne %9,%10,%4
942 } if labelRefCount %3 2
944 replace {
945 clr a
946 cjne %1,%2,%3
947 cjne %9,%10,%3
948 cjne %11,%12,%3
949 cpl a
951 jz %4
952 } by {
953 ; Peephole 172 jump optimization
954 cjne %1,%2,%4
955 cjne %9,%10,%4
956 cjne %11,%12,%4
958 } if labelRefCount %3 3
960 replace {
961 clr a
962 cjne %1,%2,%3
963 cjne %9,%10,%3
964 cjne %11,%12,%3
965 cjne %13,%14,%3
966 cpl a
968 jz %4
969 } by {
970 ; Peephole 173 jump optimization
971 cjne %1,%2,%4
972 cjne %9,%10,%4
973 cjne %11,%12,%4
974 cjne %13,%14,%4
976 } if labelRefCount %3 4
978 replace {
979 mov r%1,%2
980 clr c
981 mov a,r%1
982 subb a,#0x01
983 mov %2,a
984 } by {
985 ; Peephole 174 optimized decrement (acc not set to %2, flags undefined)
986 mov r%1,%2
987 dec %2
991 replace {
992 mov r%1,%2
993 mov a,r%1
994 add a,#0x01
995 mov %2,a
996 } by {
997 ; Peephole 175 optimized increment (acc not set to %2, flags undefined)
998 mov r%1,%2
999 inc %2
1002 replace {
1003 mov %1,@r%2
1004 inc %1
1005 mov @r%2,%1
1006 } by {
1007 ; Peephole 176 optimized increment, removed redundant mov
1008 inc @r%2
1009 mov %1,@r%2
1012 // this one will screw assigns to volatile/sfr's
1013 //replace {
1014 // mov %1,%2
1015 // mov %2,%1
1016 //} by {
1017 // ; Peephole 177 removed redundant mov
1018 // mov %1,%2
1021 replace {
1022 mov a,%1
1023 mov b,a
1024 mov a,%2
1025 } by {
1026 ; Peephole 178 removed redundant mov
1027 mov b,%1
1028 mov a,%2
1031 // rules 179-182 provided by : Frieder <fe@lake.iup.uni-heidelberg.de>
1032 // saving 2 byte, 1 cycle
1033 replace {
1034 mov b,#0x00
1035 mov a,#0x00
1036 } by {
1037 ; Peephole 179 changed mov to clr
1038 clr a
1039 mov b,a
1042 // saving 1 byte, 0 cycles
1043 replace {
1044 mov a,#0x00
1045 } by {
1046 ; Peephole 180 changed mov to clr
1047 clr a
1050 replace {
1051 mov dpl,#0x00
1052 mov dph,#0x00
1053 mov dpx,#0x00
1054 } by {
1055 ; Peephole 181a used 24 bit load of dptr
1056 mov dptr,#0x0000
1057 } if 24bitMode
1059 // saving 3 byte, 2 cycles, return(NULL) profits here
1060 replace {
1061 mov dpl,#0x00
1062 mov dph,#0x00
1063 } by {
1064 ; Peephole 181 used 16 bit load of dptr
1065 mov dptr,#0x0000
1068 replace {
1069 mov dpl,#%1
1070 mov dph,#(%1 >> 8)
1071 mov dpx,#(%1 >> 16)
1072 } by {
1073 ; Peephole 182b used 24 bit load of DPTR
1074 mov dptr,#%1
1077 // saves 2 bytes, ?? cycles.
1078 replace {
1079 mov dpl,#0x%1
1080 mov dph,#0x%2
1081 mov dpx,#0x%3
1082 } by {
1083 ; Peephole 182a used 24 bit load of dptr
1084 mov dptr,#0x%3%2%1
1085 } if 24bitMode(), isPort('ds390' 'ds400')
1087 // saves 2 bytes, ?? cycles.
1088 replace {
1089 mov dpl,#%1
1090 mov dph,#%2
1091 mov dpx,#%3
1092 } by {
1093 ; Peephole 182b used 24 bit load of dptr
1094 mov dptr,#((%3 << 16) + (%2 << 8) + %1)
1095 } if 24bitMode(), isPort('ds390' 'ds400')
1097 // saving 3 byte, 2 cycles, return(float_constant) profits here
1098 replace {
1099 mov dpl,#0x%1
1100 mov dph,#0x%2
1101 } by {
1102 ; Peephole 182c used 16 bit load of dptr
1103 mov dptr,#0x%2%1
1106 // saving 3 byte, 2 cycles, return(float_constant) profits here
1107 replace {
1108 mov dpl,#%1
1109 mov dph,#%2
1110 } by {
1111 ; Peephole 182 used 16 bit load of dptr
1112 mov dptr,#(((%2)<<8) + %1)
1115 replace {
1116 anl %1,#%2
1117 anl %1,#%3
1118 } by {
1119 ; Peephole 183 avoided anl during execution
1120 anl %1,#(%2 & %3)
1123 replace {
1124 mov %1,a
1125 cpl a
1126 mov %1,a
1127 } by {
1128 ; Peephole 184 removed redundant mov
1129 cpl a
1130 mov %1,a
1133 replace {
1134 // acc being incremented might cause problems
1135 mov %1,a
1136 inc %1
1137 } by {
1138 ; Peephole 185 changed order of increment (acc incremented also!)
1139 inc a
1140 mov %1,a
1143 // char indexed access to: long code table[] = {4,3,2,1};
1144 replace restart {
1145 add a,#%1
1146 mov dpl,a
1147 clr a
1148 addc a,#(%1 >> 8)
1149 mov dph,a
1150 clr a
1151 movc a,@a+dptr
1152 mov %2,a
1153 inc dptr
1154 clr a
1155 movc a,@a+dptr
1156 mov %3,a
1157 inc dptr
1158 clr a
1159 movc a,@a+dptr
1160 mov %4,a
1161 inc dptr
1162 clr a
1163 movc a,@a+dptr
1164 } by {
1165 ; Peephole 186.a optimized movc sequence
1166 mov b,a
1167 mov dptr,#%1
1168 movc a,@a+dptr
1169 mov %2,a
1170 inc dptr
1171 mov a,b
1172 movc a,@a+dptr
1173 mov %3,a
1174 inc dptr
1175 mov a,b
1176 movc a,@a+dptr
1177 mov %4,a
1178 inc dptr
1179 mov a,b
1180 movc a,@a+dptr
1183 // char indexed access to: void* code table[] = {4,3,2,1};
1184 replace restart {
1185 add a,#%1
1186 mov dpl,a
1187 clr a
1188 addc a,#(%1 >> 8)
1189 mov dph,a
1190 clr a
1191 movc a,@a+dptr
1192 mov %2,a
1193 inc dptr
1194 clr a
1195 movc a,@a+dptr
1196 mov %3,a
1197 inc dptr
1198 clr a
1199 movc a,@a+dptr
1200 } by {
1201 ; Peephole 186.b optimized movc sequence
1202 mov b,a
1203 mov dptr,#%1
1204 movc a,@a+dptr
1205 mov %2,a
1206 inc dptr
1207 mov a,b
1208 movc a,@a+dptr
1209 mov %3,a
1210 inc dptr
1211 mov a,b
1212 movc a,@a+dptr
1215 // char indexed access to: int code table[] = {4,3,2,1};
1216 replace restart {
1217 add a,#%1
1218 mov dpl,a
1219 clr a
1220 addc a,#(%1 >> 8)
1221 mov dph,a
1222 clr a
1223 movc a,@a+dptr
1224 mov %2,a
1225 inc dptr
1226 clr a
1227 movc a,@a+dptr
1228 } by {
1229 ; Peephole 186.c optimized movc sequence
1230 mov %2,a
1231 mov dptr,#%1
1232 movc a,@a+dptr
1233 xch a,%2
1234 inc dptr
1235 movc a,@a+dptr
1238 // char indexed access to: char code table[] = {4,3,2,1};
1239 replace {
1240 add a,#%1
1241 mov dpl,a
1242 clr a
1243 addc a,#(%1 >> 8)
1244 mov dph,a
1245 clr a
1246 movc a,@a+dptr
1247 } by {
1248 ; Peephole 186.d optimized movc sequence
1249 mov dptr,#%1
1250 movc a,@a+dptr
1253 replace {
1254 mov r%1,%2
1255 anl ar%1,#%3
1256 mov a,r%1
1257 } by {
1258 ; Peephole 187 used a instead of ar%1 for anl
1259 mov a,%2
1260 anl a,#%3
1261 mov r%1,a
1264 replace {
1265 mov %1,a
1266 mov dptr,%2
1267 movc a,@a+dptr
1268 mov %1,a
1269 } by {
1270 ; Peephole 188 removed redundant mov
1271 mov dptr,%2
1272 movc a,@a+dptr
1273 mov %1,a
1276 replace {
1277 anl a,#0x0f
1278 mov %1,a
1279 mov a,#0x0f
1280 anl a,%1
1281 } by {
1282 ; Peephole 189 removed redundant mov and anl
1283 anl a,#0x0f
1284 mov %1,a
1287 // rules 190 & 191 need to be in order
1288 replace {
1289 mov a,%1
1290 lcall __gptrput
1291 mov a,%1
1292 } by {
1293 ; Peephole 190 removed redundant mov
1294 mov a,%1
1295 lcall __gptrput
1298 replace {
1299 mov %1,a
1300 mov dpl,%2
1301 mov dph,%3
1302 mov b,%4
1303 mov a,%1
1304 } by {
1305 ; Peephole 191 removed redundant mov
1306 mov %1,a
1307 mov dpl,%2
1308 mov dph,%3
1309 mov b,%4
1312 replace {
1313 mov r%1,a
1314 mov @r%2,ar%1
1315 } by {
1316 ; Peephole 192 used a instead of ar%1 as source
1317 mov r%1,a
1318 mov @r%2,a
1321 replace {
1322 jnz %3
1323 mov a,%4
1324 jnz %3
1325 mov a,%9
1326 jnz %3
1327 mov a,%12
1328 cjne %13,%14,%3
1329 sjmp %7
1331 sjmp %8
1332 } by {
1333 ; Peephole 193.a optimized misc jump sequence
1334 jnz %8
1335 mov a,%4
1336 jnz %8
1337 mov a,%9
1338 jnz %8
1339 mov a,%12
1340 cjne %13,%14,%8
1341 sjmp %7
1342 ;%3:
1343 } if labelRefCount %3 4
1345 replace {
1346 cjne %1,%2,%3
1347 mov a,%4
1348 cjne %5,%6,%3
1349 mov a,%9
1350 cjne %10,%11,%3
1351 mov a,%12
1352 cjne %13,%14,%3
1353 sjmp %7
1355 sjmp %8
1356 } by {
1357 ; Peephole 193 optimized misc jump sequence
1358 cjne %1,%2,%8
1359 mov a,%4
1360 cjne %5,%6,%8
1361 mov a,%9
1362 cjne %10,%11,%8
1363 mov a,%12
1364 cjne %13,%14,%8
1365 sjmp %7
1366 ;%3:
1367 } if labelRefCount %3 4
1369 replace {
1370 cjne @%1,%2,%3
1371 inc %1
1372 cjne @%1,%6,%3
1373 inc %1
1374 cjne @%1,%11,%3
1375 inc %1
1376 cjne @%1,%14,%3
1377 sjmp %7
1379 sjmp %8
1380 } by {
1381 ; Peephole 193.a optimized misc jump sequence
1382 cjne @%1,%2,%8
1383 inc %1
1384 cjne @%1,%6,%8
1385 inc %1
1386 cjne @%1,%11,%8
1387 inc %1
1388 cjne @%1,%14,%8
1389 sjmp %7
1390 ;%3:
1391 } if labelRefCount %3 4
1393 replace {
1394 cjne %1,%2,%3
1395 cjne %5,%6,%3
1396 cjne %10,%11,%3
1397 cjne %13,%14,%3
1398 sjmp %7
1400 sjmp %8
1401 } by {
1402 ; Peephole 194 optimized misc jump sequence
1403 cjne %1,%2,%8
1404 cjne %5,%6,%8
1405 cjne %10,%11,%8
1406 cjne %13,%14,%8
1407 sjmp %7
1408 ;%3:
1409 } if labelRefCount %3 4
1411 replace {
1412 jnz %3
1413 mov a,%4
1414 jnz %3
1415 mov a,%9
1416 cjne %10,%11,%3
1417 sjmp %7
1419 sjmp %8
1420 } by {
1421 ; Peephole 195.a optimized misc jump sequence
1422 jnz %8
1423 mov a,%4
1424 jnz %8
1425 mov a,%9
1426 cjne %10,%11,%8
1427 sjmp %7
1428 ;%3:
1429 } if labelRefCount %3 3
1431 replace {
1432 cjne %1,%2,%3
1433 mov a,%4
1434 cjne %5,%6,%3
1435 mov a,%9
1436 cjne %10,%11,%3
1437 sjmp %7
1439 sjmp %8
1440 } by {
1441 ; Peephole 195 optimized misc jump sequence
1442 cjne %1,%2,%8
1443 mov a,%4
1444 cjne %5,%6,%8
1445 mov a,%9
1446 cjne %10,%11,%8
1447 sjmp %7
1448 ;%3:
1449 } if labelRefCount %3 3
1451 replace {
1452 cjne @%1,%2,%3
1453 inc %1
1454 cjne @%1,%6,%3
1455 inc %1
1456 cjne @%1,%11,%3
1457 sjmp %7
1459 sjmp %8
1460 } by {
1461 ; Peephole 195.a optimized misc jump sequence
1462 cjne @%1,%2,%8
1463 inc %1
1464 cjne @%1,%6,%8
1465 inc %1
1466 cjne @%1,%11,%8
1467 sjmp %7
1468 ;%3:
1469 } if labelRefCount %3 3
1471 replace {
1472 cjne %1,%2,%3
1473 cjne %5,%6,%3
1474 cjne %10,%11,%3
1475 sjmp %7
1477 sjmp %8
1478 } by {
1479 ; Peephole 196 optimized misc jump sequence
1480 cjne %1,%2,%8
1481 cjne %5,%6,%8
1482 cjne %10,%11,%8
1483 sjmp %7
1484 ;%3:
1485 } if labelRefCount %3 3
1487 replace {
1488 jnz %3
1489 mov a,%4
1490 cjne %5,%6,%3
1491 sjmp %7
1493 sjmp %8
1494 } by {
1495 ; Peephole 197.a optimized misc jump sequence
1496 jnz %8
1497 mov a,%4
1498 cjne %5,%6,%8
1499 sjmp %7
1500 ;%3:
1501 } if labelRefCount %3 2
1503 replace {
1504 cjne %1,%2,%3
1505 mov a,%4
1506 cjne %5,%6,%3
1507 sjmp %7
1509 sjmp %8
1510 } by {
1511 ; Peephole 197 optimized misc jump sequence
1512 cjne %1,%2,%8
1513 mov a,%4
1514 cjne %5,%6,%8
1515 sjmp %7
1516 ;%3:
1517 } if labelRefCount %3 2
1519 replace {
1520 cjne @%1,%2,%3
1521 inc %1
1522 cjne @%1,%6,%3
1523 sjmp %7
1525 sjmp %8
1526 } by {
1527 ; Peephole 197.a optimized misc jump sequence
1528 cjne @%1,%2,%8
1529 inc %1
1530 cjne @%1,%6,%8
1531 sjmp %7
1532 ;%3:
1533 } if labelRefCount %3 2
1535 replace {
1536 cjne %1,%2,%3
1537 cjne %5,%6,%3
1538 sjmp %7
1540 sjmp %8
1541 } by {
1542 ; Peephole 198 optimized misc jump sequence
1543 cjne %1,%2,%8
1544 cjne %5,%6,%8
1545 sjmp %7
1546 ;%3:
1547 } if labelRefCount %3 2
1549 replace {
1550 cjne %1,%2,%3
1551 sjmp %4
1553 sjmp %5
1554 } by {
1555 ; Peephole 199 optimized misc jump sequence
1556 cjne %1,%2,%5
1557 sjmp %4
1558 ;%3:
1559 } if labelRefCount %3 1
1561 replace {
1562 sjmp %1
1564 } by {
1565 ; Peephole 200 removed redundant sjmp
1569 replace {
1570 sjmp %1
1573 } by {
1574 ; Peephole 201 removed redundant sjmp
1579 replace {
1580 push acc
1581 mov dptr,%1
1582 pop acc
1583 } by {
1584 ; Peephole 202 removed redundant push pop
1585 mov dptr,%1
1588 replace {
1589 push acc
1590 pop acc
1591 } by {
1592 ; Peephole 202b removed redundant push pop
1595 replace {
1596 mov r%1,_spx
1597 lcall %2
1598 mov r%1,_spx
1599 } by {
1600 ; Peephole 203 removed mov r%1,_spx
1601 lcall %2
1604 replace {
1605 mov %1,a
1606 add a,acc
1607 mov %1,a
1608 } by {
1609 ; Peephole 204 removed redundant mov
1610 add a,acc
1611 mov %1,a
1614 replace {
1615 djnz %1,%2
1616 sjmp %3
1618 sjmp %4
1620 } by {
1621 ; Peephole 205 optimized misc jump sequence
1622 djnz %1,%4
1625 } if labelRefCount %2 1
1627 replace {
1628 mov %1,%1
1629 } by {
1630 ; Peephole 206 removed redundant mov %1,%1
1633 replace {
1634 mov a,_bp
1635 add a,#0x00
1636 mov %1,a
1637 } by {
1638 ; Peephole 207 removed zero add (acc not set to %1, flags undefined)
1639 mov %1,_bp
1642 replace {
1643 push acc
1644 mov r%1,_bp
1645 pop acc
1646 } by {
1647 ; Peephole 208 removed redundant push pop
1648 mov r%1,_bp
1651 replace {
1652 mov a,_bp
1653 add a,#0x00
1654 inc a
1655 mov %1,a
1656 } by {
1657 ; Peephole 209 optimized increment (acc not set to %1, flags undefined)
1658 mov %1,_bp
1659 inc %1
1662 replace {
1663 mov dptr,#((((%1 >> 16)) <<16) + (((%1 >> 8)) <<8) + %1)
1664 } by {
1665 ; Peephole 210a simplified expression
1666 mov dptr,#%1
1667 } if 24bitMode
1669 replace {
1670 mov dptr,#((((%1 >> 8)) <<8) + %1)
1671 } by {
1672 ; Peephole 210 simplified expression
1673 mov dptr,#%1
1676 replace restart {
1677 push ar%1
1678 pop ar%1
1679 } by {
1680 ; Peephole 211 removed redundant push r%1 pop r%1
1683 replace {
1684 mov a,_bp
1685 add a,#0x01
1686 mov r%1,a
1687 } by {
1688 ; Peephole 212 reduced add sequence to inc
1689 mov r%1,_bp
1690 inc r%1
1693 replace {
1694 mov %1,#(( %2 >> 8 ) ^ 0x80)
1695 } by {
1696 ; Peephole 213.a inserted fix
1697 mov %1,#(%2 >> 8)
1698 xrl %1,#0x80
1699 } if isPort('ds390' 'ds400')
1701 replace {
1702 mov %1,#(( %2 >> 16 ) ^ 0x80)
1703 } by {
1704 ; Peephole 213.b inserted fix
1705 mov %1,#(%2 >> 16)
1706 xrl %1,#0x80
1707 } if isPort('ds390' 'ds400')
1709 replace {
1710 mov %1,#(( %2 + %3 >> 8 ) ^ 0x80)
1711 } by {
1712 ; Peephole 213.c inserted fix
1713 mov %1,#((%2 + %3) >> 8)
1714 xrl %1,#0x80
1715 } if isPort('ds390' 'ds400')
1717 replace {
1718 mov %1,a
1719 mov a,%2
1720 add a,%1
1721 } by {
1722 ; Peephole 214 reduced some extra movs
1723 mov %1,a
1724 add a,%2
1725 } if notSame(%1 %2)
1727 replace {
1728 mov %1,a
1729 add a,%2
1730 mov %1,a
1731 } by {
1732 ; Peephole 215 removed some movs
1733 add a,%2
1734 mov %1,a
1735 } if notSame(%1 %2)
1737 replace {
1738 mov r%1,%2
1739 clr a
1740 inc r%1
1741 mov @r%1,a
1742 dec r%1
1743 mov @r%1,a
1744 } by {
1745 ; Peephole 216 simplified clear (2bytes)
1746 mov r%1,%2
1747 clr a
1748 mov @r%1,a
1749 inc r%1
1750 mov @r%1,a
1753 replace {
1754 mov r%1,%2
1755 clr a
1756 inc r%1
1757 inc r%1
1758 mov @r%1,a
1759 dec r%1
1760 mov @r%1,a
1761 dec r%1
1762 mov @r%1,a
1763 } by {
1764 ; Peephole 217 simplified clear (3bytes)
1765 mov r%1,%2
1766 clr a
1767 mov @r%1,a
1768 inc r%1
1769 mov @r%1,a
1770 inc r%1
1771 mov @r%1,a
1774 replace {
1775 mov r%1,%2
1776 clr a
1777 inc r%1
1778 inc r%1
1779 inc r%1
1780 mov @r%1,a
1781 dec r%1
1782 mov @r%1,a
1783 dec r%1
1784 mov @r%1,a
1785 dec r%1
1786 mov @r%1,a
1787 } by {
1788 ; Peephole 218 simplified clear (4bytes)
1789 mov r%1,%2
1790 clr a
1791 mov @r%1,a
1792 inc r%1
1793 mov @r%1,a
1794 inc r%1
1795 mov @r%1,a
1796 inc r%1
1797 mov @r%1,a
1800 replace {
1801 clr a
1802 movx @dptr,a
1803 mov dptr,%1
1804 clr a
1805 movx @dptr,a
1806 } by {
1807 ; Peephole 219 removed redundant clear
1808 clr a
1809 movx @dptr,a
1810 mov dptr,%1
1811 movx @dptr,a
1814 replace {
1815 clr a
1816 movx @dptr,a
1817 mov dptr,%1
1818 movx @dptr,a
1819 mov dptr,%2
1820 clr a
1821 movx @dptr,a
1822 } by {
1823 ; Peephole 219a removed redundant clear
1824 clr a
1825 movx @dptr,a
1826 mov dptr,%1
1827 movx @dptr,a
1828 mov dptr,%2
1829 movx @dptr,a
1832 replace {
1833 mov dps, #0
1834 mov dps, #1
1835 } by {
1836 ; Peephole 220a removed bogus DPS set
1837 mov dps, #1
1840 replace {
1841 mov dps, #1
1842 mov dps, #0
1843 } by {
1844 ; Peephole 220b removed bogus DPS set
1845 mov dps, #0
1848 replace {
1849 mov dps, #0
1850 mov dps, #0x01
1851 } by {
1852 ; Peephole 220c removed bogus DPS set
1855 replace {
1856 mov dps,#1
1857 inc dptr
1858 mov dps,#1
1859 } by {
1860 ; Peephole 220d removed bogus DPS set
1861 mov dps,#1
1862 inc dptr
1865 replace {
1866 mov %1 + %2,(%2 + %1)
1867 } by {
1868 ; Peephole 221a remove redundant move
1871 replace {
1872 mov (%1 + %2 + %3),((%2 + %1) + %3)
1873 } by {
1874 ; Peephole 221b remove redundant move
1877 replace {
1878 dec r%1
1879 inc r%1
1880 } by {
1881 ; removed dec/inc pair
1884 replace {
1885 mov dps, #0
1886 mov %1,a
1887 mov dps, #1
1888 } by {
1889 ; Peephole 222 removed DPS abuse.
1890 mov %1,a
1891 mov dps, #1
1894 replace {
1895 mov dps, #0
1896 xch a, ap
1897 mov %1, ap
1898 mov dps, #1
1899 } by {
1900 ; Peephole 222a removed DPS abuse.
1901 xch a, ap
1902 mov %1, ap
1903 mov dps, #1
1906 replace {
1907 mov dps, #%1
1908 inc dptr
1909 movx a,@dptr
1910 mov %2,a
1911 mov dps, #%1
1912 } by {
1913 mov dps, #%1
1914 inc dptr
1915 movx a,@dptr
1916 mov %2,a
1917 ; Peephole 223: yet more DPS abuse removed.
1920 replace {
1921 mov dps, #0
1922 inc dps
1923 } by {
1924 mov dps, #1
1927 replace {
1928 mov dps, #%1
1929 mov dptr, %2
1930 mov dps, #%1
1931 } by {
1932 mov dps, #%1
1933 mov dptr, %2
1936 replace {
1937 mov dps, #1
1938 mov dptr, %1
1939 mov dps, #0
1940 mov dptr, %2
1941 inc dps
1942 } by {
1943 mov dps, #0
1944 mov dptr, %2
1945 inc dps
1946 mov dptr, %1
1947 ; Peephole 224a: DPS usage re-arranged.
1950 replace {
1951 mov dps, #%1
1952 mov dptr, %2
1953 mov dps, #%3
1954 mov dptr, %4
1955 mov dps, #%1
1956 } by {
1957 mov dps, #%3
1958 mov dptr, %4
1959 mov dps, #%1
1960 mov dptr, %2
1961 ; Peephole 224: DPS usage re-arranged.
1964 replace {
1965 mov dps, #1
1966 mov dptr, %1
1967 mov dps, #0
1968 } by {
1969 mov dps, #1
1970 mov dptr, %1
1971 dec dps
1974 replace {
1975 xch a, ap
1976 add a, ap
1977 } by {
1978 add a, ap
1981 replace {
1982 xch a, ap
1983 addc a, ap
1984 } by {
1985 addc a, ap
1988 replace {
1989 inc dps
1990 mov dps, #%1
1991 } by {
1992 mov dps, #%1
1995 replace {
1996 dec dps
1997 mov dps, #%1
1998 } by {
1999 mov dps, #%1
2003 // char indexed access to: long code table[] = {4,3,2,1};
2004 replace restart {
2005 add a,#%1
2006 mov dpl,a
2007 clr a
2008 addc a,#(%1 >> 8)
2009 mov dph,a
2010 clr a
2011 addc a,#(%1 >> 16)
2012 mov dpx,a
2013 clr a
2014 movc a,@a+dptr
2015 inc dptr
2016 mov %2,a
2017 clr a
2018 movc a,@a+dptr
2019 inc dptr
2020 mov %3,a
2021 clr a
2022 movc a,@a+dptr
2023 inc dptr
2024 mov %4,a
2025 clr a
2026 movc a,@a+dptr
2027 } by {
2028 ; Peephole 227.a movc optimize
2029 mov b,a
2030 mov dptr,#%1
2031 movc a,@a+dptr
2032 inc dptr
2033 mov %2,a
2034 mov a,b
2035 movc a,@a+dptr
2036 inc dptr
2037 mov %3,a
2038 mov a,b
2039 movc a,@a+dptr
2040 inc dptr
2041 mov %4,a
2042 mov a,b
2043 movc a,@a+dptr
2046 // char indexed access to: void* code table[] = {4,3,2,1};
2047 replace restart {
2048 add a,#%1
2049 mov dpl,a
2050 clr a
2051 addc a,#(%1 >> 8)
2052 mov dph,a
2053 clr a
2054 addc a,#(%1 >> 16)
2055 mov dpx,a
2056 clr a
2057 movc a,@a+dptr
2058 inc dptr
2059 mov %2,a
2060 clr a
2061 movc a,@a+dptr
2062 inc dptr
2063 mov %3,a
2064 clr a
2065 movc a,@a+dptr
2066 } by {
2067 ; Peephole 227.b movc optimize
2068 mov b,a
2069 mov dptr,#%1
2070 movc a,@a+dptr
2071 inc dptr
2072 mov %2,a
2073 mov a,b
2074 movc a,@a+dptr
2075 inc dptr
2076 mov %3,a
2077 mov a,b
2078 movc a,@a+dptr
2081 // char indexed access to: int code table[] = {4,3,2,1};
2082 replace restart {
2083 add a,#%1
2084 mov dpl,a
2085 clr a
2086 addc a,#(%1 >> 8)
2087 mov dph,a
2088 clr a
2089 addc a,#(%1 >> 16)
2090 mov dpx,a
2091 clr a
2092 movc a,@a+dptr
2093 inc dptr
2094 mov %2,a
2095 clr a
2096 movc a,@a+dptr
2097 } by {
2098 ; Peephole 227.c movc optimize
2099 mov %2,a
2100 mov dptr,#%1
2101 movc a,@a+dptr
2102 inc dptr
2103 xch a,%2
2104 movc a,@a+dptr
2107 // char indexed access to: char code table[] = {4,3,2,1};
2108 replace {
2109 add a,#%1
2110 mov dpl,a
2111 clr a
2112 addc a,#(%1 >> 8)
2113 mov dph,a
2114 clr a
2115 addc a,#(%1 >> 16)
2116 mov dpx,a
2117 clr a
2118 movc a,@a+dptr
2119 } by {
2120 ; Peephole 227.d movc optimize
2121 mov dptr,#%1
2122 movc a,@a+dptr
2125 replace {
2126 mov r%1,%2
2127 mov ar%1,%3
2128 } by {
2129 ; Peephole 228 redundant move
2130 mov ar%1,%3
2133 replace {
2134 mov r%1,a
2135 dec r%1
2136 mov a,r%1
2137 } by {
2138 ; Peephole 229.a redundant move
2139 dec a
2140 mov r%1,a
2143 replace {
2144 mov r%1,a
2145 mov r%2,b
2146 mov a,r%1
2147 } by {
2148 ; Peephole 229.b redundant move
2149 mov r%1,a
2150 mov r%2,b
2153 replace {
2154 mov r%1,a
2155 mov r%2,b
2156 add a,#%3
2157 mov r%1,a
2158 mov a,r%2
2159 addc a,#(%3 >> 8)
2160 mov r%2,a
2161 } by {
2162 ; Peephole 229.c redundant move
2163 add a,#%3
2164 mov r%1,a
2165 mov a,b
2166 addc a,#(%3 >> 8)
2167 mov r%2,a
2170 replace {
2171 mov a,%1
2172 mov b,a
2173 movx a,%2
2174 } by {
2175 ; Peephole 229.d redundant move
2176 mov b,%1
2177 movx a,%2
2180 replace {
2181 mov dpl,r%1
2182 mov dph,r%2
2183 mov dpx,r%3
2184 movx a,@dptr
2185 mov r%4,a
2186 add a,#0x01
2187 mov r%5,a
2188 mov dpl,r%1
2189 mov dph,r%2
2190 mov dpx,r%3
2191 movx @dptr,a
2192 } by {
2193 ; Peephole 230.a save reload dptr
2194 mov dpl,r%1
2195 mov dph,r%2
2196 mov dpx,r%3
2197 movx a,@dptr
2198 mov r%4,a
2199 add a,#0x01
2200 mov r%5,a
2201 movx @dptr,a
2204 replace {
2205 mov dpl,r%1
2206 mov dph,r%2
2207 mov dpx,r%3
2208 movx a,@dptr
2209 mov r%4,a
2210 dec r%4
2211 mov dpl,r%1
2212 mov dph,r%2
2213 mov dpx,r%3
2214 mov a,r%4
2215 movx @dptr,a
2216 } by {
2217 ; Peephole 230.b save reload dptr
2218 mov dpl,r%1
2219 mov dph,r%2
2220 mov dpx,r%3
2221 movx a,@dptr
2222 dec a
2223 mov r%4,a
2224 movx @dptr,a
2227 replace {
2228 mov dpl,r%1
2229 mov dph,r%2
2230 mov dpx,r%3
2231 movx a,@dptr
2232 inc a
2233 mov r%4,a
2234 mov dpl,r%1
2235 mov dph,r%2
2236 mov dpx,r%3
2237 mov a,r%4
2238 movx @dptr,a
2239 } by {
2240 ; Peephole 230.c save reload dptr
2241 mov dpl,r%1
2242 mov dph,r%2
2243 mov dpx,r%3
2244 movx a,@dptr
2245 inc a
2246 mov r%4,a
2247 movx @dptr,a
2250 replace {
2251 mov r%1,dpl
2252 mov r%2,dph
2253 mov r%3,dpx
2254 mov dpl,r%1
2255 mov dph,r%2
2256 mov dpx,r%3
2257 } by {
2258 ; Peephole 230.d save reload dptr
2259 mov r%1,dpl
2260 mov r%2,dph
2261 mov r%3,dpx
2264 replace {
2265 mov dpl,r%1
2266 mov dph,r%2
2267 mov dpx,r%3
2268 movx a,@dptr
2269 mov r%4,a
2270 orl ar%4,#%5
2271 mov dpl,r%1
2272 mov dph,r%2
2273 mov dpx,r%3
2274 mov a,r1
2275 movx @dptr,a
2276 } by {
2277 ; Peephole 230.e save reload dptr
2278 mov dpl,r%1
2279 mov dph,r%2
2280 mov dpx,r%3
2281 movx a,@dptr
2282 orl a,#%5
2283 mov r%4,a
2284 movx @dptr,a
2287 replace {
2288 mov dpl,r%1
2289 mov dph,r%2
2290 mov dpx,r%3
2291 movx a,@dptr
2292 mov r%4,a
2293 anl ar%4,#%5
2294 mov dpl,r%1
2295 mov dph,r%2
2296 mov dpx,r%3
2297 mov a,r1
2298 movx @dptr,a
2299 } by {
2300 ; Peephole 230.e save reload dptr
2301 mov dpl,r%1
2302 mov dph,r%2
2303 mov dpx,r%3
2304 movx a,@dptr
2305 anl a,#%5
2306 mov r%4,a
2307 movx @dptr,a
2310 replace {
2311 mov r%1,dpl
2312 mov r%2,dph
2313 mov r%3,dpx
2314 mov a,r%4
2315 inc dps
2316 movx @dptr,a
2317 inc dptr
2318 mov dps,#0
2319 mov dpl,r%1
2320 mov dph,r%2
2321 mov dpx,r%3
2322 } by {
2323 ; Peephole 230.f save reload dptr
2324 mov r%1,dpl
2325 mov r%2,dph
2326 mov r%3,dpx
2327 mov a,r%4
2328 inc dps
2329 movx @dptr,a
2330 inc dptr
2331 mov dps,#0
2334 replace {
2335 mov ar%1,r%2
2336 mov ar%3,r%1
2337 mov r%1,#0x00
2338 mov ar%2,r%4
2339 mov r3,#0x00
2340 } by {
2341 ; Peephole 231.a simplified moves
2342 mov ar%3,r%2
2343 mov ar%2,r%4
2344 mov r%4,#0
2345 mov r%1,#0
2348 replace {
2349 mov r%1,#0
2350 mov r%2,#0
2351 mov a,r%2
2352 orl a,r%3
2353 mov %4,a
2354 mov a,r%5
2355 orl a,r%1
2356 mov %6,a
2357 } by {
2358 ; Peephole 231.b simplified or
2359 mov r%1,#0
2360 mov r%2,#0
2361 mov a,r%3
2362 mov %4,a
2363 mov a,r%5
2364 mov %6,a
2367 replace {
2368 mov a,r%1
2369 mov b,r%2
2370 mov r%1,b
2371 mov r%2,a
2372 } by {
2373 ; Peehole 232.a simplified xch
2374 mov a,r%1
2375 xch a,r%2
2376 mov r%1,a
2379 replace {
2380 mov a,#%1
2381 mov b,#%2
2382 mov r%3,b
2383 mov r%4,a
2384 } by {
2385 ; Peehole 232.b simplified xch
2386 mov r%3,#%2
2387 mov r%4,#%1
2390 replace {
2391 mov dpl1,#%1
2392 mov dph1,#(%1 >> 8)
2393 mov dpx1,#(%1 >> 16)
2394 } by {
2395 ; Peephole 233 24 bit load of dptr1
2396 inc dps
2397 mov dptr,#%1
2398 dec dps
2401 // 14 rules by Fiorenzo D. Ramaglia <fd.ramaglia@tin.it>
2403 replace {
2404 add a,ar%1
2405 } by {
2406 ; Peephole 236a
2407 add a,r%1
2410 replace {
2411 addc a,ar%1
2412 } by {
2413 ; Peephole 236b
2414 addc a,r%1
2417 replace {
2418 anl a,ar%1
2419 } by {
2420 ; Peephole 236c
2421 anl a,r%1
2424 replace {
2425 dec ar%1
2426 } by {
2427 ; Peephole 236d
2428 dec r%1
2431 replace {
2432 djnz ar%1,%2
2433 } by {
2434 ; Peephole 236e
2435 djnz r%1,%2
2438 replace {
2439 inc ar%1
2440 } by {
2441 ; Peephole 236f
2442 inc r%1
2445 replace {
2446 mov a,ar%1
2447 } by {
2448 ; Peephole 236g
2449 mov a,r%1
2452 replace {
2453 mov ar%1,#%2
2454 } by {
2455 ; Peephole 236h
2456 mov r%1,#%2
2459 replace {
2460 mov ar%1,a
2461 } by {
2462 ; Peephole 236i
2463 mov r%1,a
2466 replace {
2467 mov ar%1,ar%2
2468 } by {
2469 ; Peephole 236j
2470 mov r%1,ar%2
2473 replace {
2474 orl a,ar%1
2475 } by {
2476 ; Peephole 236k
2477 orl a,r%1
2480 replace {
2481 subb a,ar%1
2482 } by {
2483 ; Peephole 236l
2484 subb a,r%1
2487 replace {
2488 xch a,ar%1
2489 } by {
2490 ; Peephole 236m
2491 xch a,r%1
2494 replace {
2495 xrl a,ar%1
2496 } by {
2497 ; Peephole 236n
2498 xrl a,r%1
2501 replace {
2502 sjmp %1
2504 mov %3,%4
2507 } by {
2508 ; Peephole 237a removed sjmp to ret
2511 mov %3,%4
2516 replace {
2517 sjmp %1
2519 mov %3,%4
2520 mov dpl,%5
2521 mov dph,%6
2524 } by {
2525 ; Peephole 237b removed sjmp to ret
2528 mov %3,%4
2529 mov dpl,%5
2530 mov dph,%6
2535 // applies to f.e. device/lib/log10f.c
2536 replace {
2537 mov %1,%9
2538 mov %2,%10
2539 mov %3,%11
2540 mov %4,%12
2542 mov %5,%13
2543 mov %6,%14
2544 mov %7,%15
2545 mov %8,%16
2547 mov %9,%1
2548 mov %10,%2
2549 mov %11,%3
2550 mov %12,%4
2551 } by {
2552 mov %1,%9
2553 mov %2,%10
2554 mov %3,%11
2555 mov %4,%12
2557 mov %5,%13
2558 mov %6,%14
2559 mov %7,%15
2560 mov %8,%16
2561 ; Peephole 238.a removed 4 redundant moves
2562 } if notSame(%1 %2 %3 %4 %5 %6 %7 %8)
2564 // applies to device/lib/log10f.c
2565 replace {
2566 mov %1,%5
2567 mov %2,%6
2568 mov %3,%7
2569 mov %4,%8
2571 mov %5,%1
2572 mov %6,%2
2573 mov %7,%3
2574 } by {
2575 mov %1,%5
2576 mov %2,%6
2577 mov %3,%7
2578 mov %4,%8
2579 ; Peephole 238.b removed 3 redundant moves
2580 } if notSame(%1 %2 %3 %4 %5 %6 %7)
2582 // applies to f.e. device/lib/time.c
2583 replace {
2584 mov %1,%5
2585 mov %2,%6
2587 mov %3,%7
2588 mov %4,%8
2590 mov %5,%1
2591 mov %6,%2
2592 } by {
2593 mov %1,%5
2594 mov %2,%6
2596 mov %3,%7
2597 mov %4,%8
2598 ; Peephole 238.c removed 2 redundant moves
2599 } if notSame(%1 %2 %3 %4)
2601 // applies to f.e. support/regression/tests/bug-524209.c
2602 replace {
2603 mov %1,%4
2604 mov %2,%5
2605 mov %3,%6
2607 mov %4,%1
2608 mov %5,%2
2609 mov %6,%3
2610 } by {
2611 mov %1,%4
2612 mov %2,%5
2613 mov %3,%6
2614 ; Peephole 238.d removed 3 redundant moves
2615 } if notSame(%1 %2 %3 %4 %5 %6)
2617 // applies to f.e. ser_ir.asm
2618 replace {
2619 mov r%1,acc
2620 } by {
2621 ; Peephole 239 used a instead of acc
2622 mov r%1,a
2625 replace restart {
2626 mov a,%1
2627 addc a,#0x00
2628 } by {
2629 ; Peephole 240 use clr instead of addc a,#0
2630 clr a
2631 addc a,%1
2634 // peepholes 241.a to 241.c and 241.d to 241.f need to be in order
2635 replace {
2636 cjne r%1,#%2,%3
2637 cjne r%4,#%5,%3
2638 cjne r%6,#%7,%3
2639 cjne r%8,#%9,%3
2640 mov a,#0x01
2641 sjmp %10
2643 clr a
2644 %10:
2645 } by {
2646 ; Peephole 241.a optimized compare
2647 clr a
2648 cjne r%1,#%2,%3
2649 cjne r%4,#%5,%3
2650 cjne r%6,#%7,%3
2651 cjne r%8,#%9,%3
2652 inc a
2654 %10:
2657 // applies to f.e. time.c
2658 replace {
2659 cjne r%1,#%2,%3
2660 cjne r%4,#%5,%3
2661 mov a,#0x01
2662 sjmp %6
2664 clr a
2666 } by {
2667 ; Peephole 241.b optimized compare
2668 clr a
2669 cjne r%1,#%2,%3
2670 cjne r%4,#%5,%3
2671 inc a
2676 // applies to f.e. malloc.c
2677 replace {
2678 cjne r%1,#%2,%3
2679 mov a,#0x01
2680 sjmp %4
2682 clr a
2684 } by {
2685 ; Peephole 241.c optimized compare
2686 clr a
2687 cjne r%1,#%2,%3
2688 inc a
2693 // applies to f.e. j = (k!=0x1000);
2694 // with volatile idata long k;
2695 replace {
2696 cjne @r%1,#%2,%3
2697 inc r%1
2698 cjne @r%1,#%4,%3
2699 inc r%1
2700 cjne @r%1,#%5,%3
2701 inc r%1
2702 cjne @r%1,#%6,%3
2703 mov a,#0x01
2704 sjmp %7
2706 clr a
2708 } by {
2709 ; Peephole 241.d optimized compare
2710 clr a
2711 cjne @r%1,#%2,%3
2712 inc r%1
2713 cjne @r%1,#%4,%3
2714 inc r%1
2715 cjne @r%1,#%5,%3
2716 inc r%1
2717 cjne @r%1,#%6,%3
2718 inc a
2723 // applies to f.e. j = (k!=0x1000);
2724 // with volatile idata int k;
2725 replace {
2726 cjne @r%1,#%2,%3
2727 inc r%1
2728 cjne @r%1,#%4,%3
2729 mov a,#0x01
2730 sjmp %7
2732 clr a
2734 } by {
2735 ; Peephole 241.e optimized compare
2736 clr a
2737 cjne @r%1,#%2,%3
2738 inc r%1
2739 cjne @r%1,#%4,%3
2740 inc a
2745 // applies to f.e. vprintf.asm (--stack-auto)
2746 replace {
2747 cjne @r%1,#%2,%3
2748 mov a,#0x01
2749 sjmp %7
2751 clr a
2753 } by {
2754 ; Peephole 241.f optimized compare
2755 clr a
2756 cjne @r%1,#%2,%3
2757 inc a
2762 // applies to f.e. scott-bool1.c
2763 replace {
2764 jnz %1
2765 mov %2,%3
2767 jz %4
2768 } by {
2769 ; Peephole 242.a avoided branch jnz to jz
2770 jnz %1
2771 mov %2,%3
2772 jz %4
2774 } if labelRefCount %1 1
2776 // applies to f.e. scott-bool1.c
2777 replace {
2778 jnz %1
2779 mov %2,%3
2780 orl a,%5
2782 jz %4
2783 } by {
2784 ; Peephole 242.b avoided branch jnz to jz
2785 jnz %1
2786 mov %2,%3
2787 orl a,%5
2788 jz %4
2790 } if labelRefCount %1 1
2792 // applies to f.e. logic.c
2793 replace {
2794 jnz %1
2795 mov %2,%3
2796 orl a,%5
2797 orl a,%6
2798 orl a,%7
2800 jz %4
2801 } by {
2802 ; Peephole 242.c avoided branch jnz to jz
2803 jnz %1
2804 mov %2,%3
2805 orl a,%5
2806 orl a,%6
2807 orl a,%7
2808 jz %4
2810 } if labelRefCount %1 1
2812 replace {
2813 jnz %1
2815 } by {
2816 ; Peephole 243a jump optimization
2817 } if labelRefCount %1 1
2819 replace {
2820 jz %1
2822 } by {
2823 ; Peephole 243b jump optimization
2824 } if labelRefCount %1 1
2827 // This allows non-interrupt and interrupt code to safely compete
2828 // for a resource without the non-interrupt code having to disable
2829 // interrupts:
2830 // volatile bit resource_is_free;
2831 // if( resource_is_free ) {
2832 // resource_is_free=0; do_something; resource_is_free=1;
2833 // }
2834 replace {
2835 jnb %1,%2
2837 clr %1
2838 } by {
2839 ; Peephole 244.a using atomic test and clear
2840 jbc %1,%3
2841 sjmp %2
2843 } if labelRefCount %3 0
2845 replace {
2846 jb %1,%2
2847 ljmp %3
2849 clr %1
2850 } by {
2851 ; Peephole 244.b using atomic test and clear
2852 jbc %1,%2
2853 ljmp %3
2855 } if labelRefCount %2 1