renamed similar peepholes by using suffixes
[fw/sdcc] / src / mcs51 / peeph.def
index 97095ba55720498bf40f3856c09b5546c7105d61..489def433af0adc43e1410a02643d1e231a12eef 100644 (file)
@@ -286,57 +286,57 @@ replace {
 } by {
        ;       Peephole 107    removed redundant ljmp
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jc      %1
        ljmp    %5
 %1:
 } by {
-       ;       Peephole 108    removed ljmp by inverse jump logic
+       ;       Peephole 108.a  removed ljmp by inverse jump logic
        jnc     %5
 %1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
 
 replace {
        jz      %1
        ljmp    %5
 %1:
 } by {
-       ;       Peephole 109    removed ljmp by inverse jump logic
+       ;       Peephole 108.b  removed ljmp by inverse jump logic
        jnz     %5
 %1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
 
 replace {
        jnz     %1
        ljmp    %5
 %1:
 } by {
-       ;       Peephole 110    removed ljmp by inverse jump logic
+       ;       Peephole 108.c  removed ljmp by inverse jump logic
        jz      %5
 %1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
 
 replace {
        jb      %1,%2
        ljmp    %5
 %2:
 } by {
-       ;       Peephole 111    removed ljmp by inverse jump logic
+       ;       Peephole 108.d  removed ljmp by inverse jump logic
        jnb     %1,%5
 %2:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%2 -1)
 
 replace {
        jnb     %1,%2
        ljmp    %5
 %2:
 } by {
-       ;       Peephole 112.a  removed ljmp by inverse jump logic
+       ;       Peephole 108.e  removed ljmp by inverse jump logic
        jb      %1,%5
 %2:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%2 -1)
 
 replace {
        ljmp    %5
@@ -355,7 +355,7 @@ replace {
        rrc     a
        mov     %4,c
 } by {
-       ;       Peephole 113    optimized misc sequence
+       ;       Peephole 113.a  optimized misc sequence
        clr     %4
        cjne    %1,%2,%3
        setb    %4
@@ -371,7 +371,7 @@ replace {
        rrc     a
        mov     %4,c
 } by {
-       ;       Peephole 114    optimized misc sequence
+       ;       Peephole 113.b  optimized misc sequence
        clr     %4
        cjne    %1,%2,%3
        cjne    %10,%11,%3
@@ -386,7 +386,7 @@ replace {
 %3:
        jnz     %4
 } by {
-       ;       Peephole 115.a  jump optimization
+       ;       Peephole 115.a  jump optimization (acc not set)
        cjne    %1,%2,%3
        sjmp    %4
 %3:
@@ -402,7 +402,7 @@ replace {
        mov     %1,a
        jz      %3
 %2:
-}
+} labelRefCountChange(%2 -1)
 
 replace {
        clr     a
@@ -412,7 +412,7 @@ replace {
 %3:
        jnz     %4
 } by {
-       ;       Peephole 116    jump optimization
+       ;       Peephole 115.c  jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %9,%10,%3
        sjmp    %4
@@ -428,7 +428,7 @@ replace {
 %3:
        jnz %4
 } by {
-       ;       Peephole 117    jump optimization
+       ;       Peephole 115.d  jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %9,%10,%3
        cjne    %11,%12,%3
@@ -446,7 +446,7 @@ replace {
 %3:
        jnz     %4
 } by {
-       ;       Peephole 118    jump optimization
+       ;       Peephole 115.e  jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %9,%10,%3
        cjne    %11,%12,%3
@@ -462,10 +462,10 @@ replace {
 %3:
        jnz     %4
 } by {
-       ;       Peephole 119    jump optimization
+       ;       Peephole 115.f  jump optimization (acc not set)
        cjne    %1,%2,%4
 %3:
-} if labelRefCount %3 1
+} if labelRefCount(%3 1), labelRefCountChange(%3 -1)
 
 replace {
        mov     a,#0x01
@@ -475,11 +475,11 @@ replace {
 %3:
        jnz     %4
 } by {
-       ;       Peephole 120    jump optimization
+       ;       Peephole 115.g  jump optimization (acc not set)
        cjne    %1,%2,%4
        cjne    %10,%11,%4
 %3:
-} if labelRefCount %3 2
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%4 1)
 
 replace {
        mov     a,#0x01
@@ -490,12 +490,12 @@ replace {
 %3:
        jnz  %4
 } by {
-       ;       Peephole 121    jump optimization
+       ;       Peephole 115.h  jump optimization (acc not set)
        cjne    %1,%2,%4
        cjne    %10,%11,%4
        cjne    %12,%13,%4
 %3:
-} if labelRefCount %3 3
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%4 2)
 
 replace {
        mov     a,#0x01
@@ -507,13 +507,13 @@ replace {
 %3:
        jnz     %4
 } by {
-       ;       Peephole 122    jump optimization
+       ;       Peephole 115.i  jump optimization (acc not set)
        cjne    %1,%2,%4
        cjne    %10,%11,%4
        cjne    %12,%13,%4
        cjne    %14,%15,%4
 %3:
-} if labelRefCount %3 4
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%4 3)
 
 replace {
        mov     a,#0x01
@@ -522,7 +522,7 @@ replace {
 %3:
        jz      %4
 } by {
-       ;       Peephole 123    jump optimization
+       ;       Peephole 115.j  jump optimization (acc not set)
        cjne    %1,%2,%3
        sjmp    %4
 %3:
@@ -536,7 +536,7 @@ replace {
 %3:
        jz      %4
 } by {
-       ;       Peephole 124    jump optimization
+       ;       Peephole 115.k  jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %10,%11,%3
        sjmp    %4
@@ -552,7 +552,7 @@ replace {
 %3:
        jz      %4
 } by {
-       ;       Peephole 125    jump optimization
+       ;       Peephole 115.l  jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %10,%11,%3
        cjne    %12,%13,%3
@@ -570,7 +570,7 @@ replace {
 %3:
        jz      %4
 } by {
-       ;       Peephole 126    jump optimization
+       ;       Peephole 115.m  jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %10,%11,%3
        cjne    %12,%13,%3
@@ -832,7 +832,7 @@ replace {
        anl     ar%1,%2
        mov     a,r%1
 } by {
-       ;       Peephole 139    removed redundant mov
+       ;       Peephole 139.a  removed redundant mov
        anl     a,%2
        mov     r%1,a
 }
@@ -842,7 +842,7 @@ replace {
        orl     ar%1,%2
        mov     a,r%1
 } by {
-       ;       Peephole 140    removed redundant mov
+       ;       Peephole 139.b  removed redundant mov
        orl     a,%2
        mov     r%1,a }
 
@@ -851,7 +851,7 @@ replace {
        xrl     ar%1,%2
        mov     a,r%1
 } by {
-       ;       Peephole 141    removed redundant mov
+       ;       Peephole 139.c  removed redundant mov
        xrl     a,%2
        mov     r%1,a
 }
@@ -870,7 +870,7 @@ replace {
        rlc     a
        mov     acc.0,c
 } by {
-       ;       Peephole 143    converted rlc to rl
+       ;       Peephole 143.a  converted rlc to rl
        rl      a
 }
 
@@ -878,7 +878,7 @@ replace {
        rrc     a
        mov     acc.7,c
 } by {
-       ;       Peephole 144    converted rrc to rc
+       ;       Peephole 143.b  converted rrc to rc
        rr      a
 }
 
@@ -886,7 +886,7 @@ replace {
        clr     c
        addc    a,%1
 } by {
-       ;       Peephole 145    changed to add without carry
+       ;       Peephole 145.a  changed to add without carry
        add     a,%1
 }
 
@@ -895,11 +895,12 @@ replace {
        mov     a,%1
        addc    a,%2
 } by {
-       ;       Peephole 146    changed to add without carry
+       ;       Peephole 145.b  changed to add without carry
        mov     a,%1
        add     a,%2
 }
 
+// what are #147-#149 for?
 replace {
        orl     r%1,a
 } by {
@@ -927,7 +928,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 150    removed misc moves via dpl before return
+       ;       Peephole 150.a  removed misc moves via dpl before return
 %9:
        ret
 }
@@ -940,7 +941,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 151    removed misc moves via dph, dpl before return
+       ;       Peephole 150.b  removed misc moves via dph, dpl before return
 %9:
        ret
 }
@@ -952,7 +953,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 152    removed misc moves via dph, dpl before return
+       ;       Peephole 150.c  removed misc moves via dph, dpl before return
 %9:
        ret
 }
@@ -967,7 +968,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 153    removed misc moves via dph, dpl, b before return
+       ;       Peephole 150.d  removed misc moves via dph, dpl, b before return
 %9:
        ret
 }
@@ -980,7 +981,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 154    removed misc moves via dph, dpl, b before return
+       ;       Peephole 150.e  removed misc moves via dph, dpl, b before return
 %9:
        ret
 }
@@ -994,7 +995,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 155    removed misc moves via dph, dpl, b before return
+       ;       Peephole 150.f  removed misc moves via dph, dpl, b before return
 %9:
        ret
 }
@@ -1011,7 +1012,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 156    removed misc moves via dph, dpl, b, a before return
+       ;       Peephole 150.g  removed misc moves via dph, dpl, b, a before return
 %9:
        ret
 }
@@ -1026,7 +1027,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 157    removed misc moves via dph, dpl, b, a before return
+       ;       Peephole 150.h  removed misc moves via dph, dpl, b, a before return
 %9:
        ret
 }
@@ -1040,7 +1041,7 @@ replace {
 %9:
        ret
 } by {
-       ;       Peephole 158    removed misc moves via dph, dpl, b, a before return
+       ;       Peephole 150.i  removed misc moves via dph, dpl, b, a before return
 %9:
        ret
 }
@@ -1058,60 +1059,60 @@ replace {
        sjmp    %2
 %1:
 } by {
-       ;       Peephole 160    removed sjmp by inverse jump logic
+       ;       Peephole 160.a  removed sjmp by inverse jump logic
        jc      %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jc      %1
        sjmp    %2
 %1:
 } by {
-       ;       Peephole 161    removed sjmp by inverse jump logic
+       ;       Peephole 160.b  removed sjmp by inverse jump logic
        jnc     %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jnz     %1
        sjmp    %2
 %1:
 } by {
-       ;       Peephole 162    removed sjmp by inverse jump logic
+       ;       Peephole 160.c  removed sjmp by inverse jump logic
        jz      %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jz      %1
        sjmp    %2
 %1:
 } by {
-       ;       Peephole 163    removed sjmp by inverse jump logic
+       ;       Peephole 160.d  removed sjmp by inverse jump logic
        jnz     %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jnb     %3,%1
        sjmp    %2
 %1:
 } by {
-       ;       Peephole 164    removed sjmp by inverse jump logic
+       ;       Peephole 160.e  removed sjmp by inverse jump logic
        jb      %3,%2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jb      %3,%1
        sjmp    %2
 %1:
 } by {
-       ;       Peephole 165    removed sjmp by inverse jump logic
+       ;       Peephole 160.f  removed sjmp by inverse jump logic
        jnb     %3,%2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        mov     %1,%2
@@ -1140,7 +1141,7 @@ replace {
        ;       Peephole 168    jump optimization
        jb      %1,%3
 %2:
-}
+} labelRefCountChange(%2 -1)
 
 replace {
        jb      %1,%2
@@ -1150,7 +1151,7 @@ replace {
        ;       Peephole 169    jump optimization
        jnb     %1,%3
 %2:
-}
+} labelRefCountChange(%2 -1)
 
 replace {
        clr     a
@@ -1162,7 +1163,7 @@ replace {
        ;       Peephole 170    jump optimization
        cjne    %1,%2,%4
 %3:
-} if labelRefCount %3 1
+} if labelRefCount(%3 1), labelRefCountChange(%3 -1)
 
 replace {
        clr     a
@@ -1176,7 +1177,7 @@ replace {
        cjne    %1,%2,%4
        cjne    %9,%10,%4
 %3:
-} if labelRefCount %3 2
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%4 1)
 
 replace {
        clr     a
@@ -1192,7 +1193,7 @@ replace {
        cjne    %9,%10,%4
        cjne    %11,%12,%4
 %3:
-} if labelRefCount %3 3
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%4 2)
 
 replace {
        clr     a
@@ -1210,7 +1211,7 @@ replace {
        cjne    %11,%12,%4
        cjne    %13,%14,%4
 %3:
-} if labelRefCount %3 4
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%4 3)
 
 replace {
        mov     r%1,%2
@@ -1219,7 +1220,7 @@ replace {
        subb    a,#0x01
        mov     %2,a
 } by {
-       ;       Peephole 174    optimized decrement (acc not set to %2, flags undefined)
+       ;       Peephole 174.a  optimized decrement (acc not set to %2, flags undefined)
        mov     r%1,%2
        dec     %2
 }
@@ -1230,7 +1231,7 @@ replace {
        add     a,#0x01
        mov     %2,a
 } by {
-       ;       Peephole 175    optimized increment (acc not set to %2, flags undefined)
+       ;       Peephole 174.b  optimized increment (acc not set to %2, flags undefined)
        mov     r%1,%2
        inc     %2
 }
@@ -1240,7 +1241,7 @@ replace {
        inc     %1
        mov     @r%2,%1
 } by {
-       ;       Peephole 176    optimized increment, removed redundant mov
+       ;       Peephole 174.c  optimized increment, removed redundant mov
        inc     @r%2
        mov     %1,@r%2
 } if notVolatile
@@ -1666,8 +1667,8 @@ replace {
        mov     a,%12
        cjne    %13,%14,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 4
+%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
 
 replace {
        cjne    %1,%2,%3
@@ -1690,8 +1691,8 @@ replace {
        mov     a,%12
        cjne    %13,%14,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 4
+%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
 
 replace {
        cjne    @%1,%2,%3
@@ -1714,8 +1715,8 @@ replace {
        inc     %1
        cjne    @%1,%14,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 4
+%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
 
 replace {
        cjne    %1,%2,%3
@@ -1732,8 +1733,8 @@ replace {
        cjne    %10,%11,%8
        cjne    %13,%14,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 4
+%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
 
 replace {
        jnz     %3
@@ -1752,8 +1753,8 @@ replace {
        mov     a,%9
        cjne    %10,%11,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 3
+%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
 
 replace {
        cjne    %1,%2,%3
@@ -1772,8 +1773,8 @@ replace {
        mov     a,%9
        cjne    %10,%11,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 3
+%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
 
 replace {
        cjne    @%1,%2,%3
@@ -1792,8 +1793,8 @@ replace {
        inc     %1
        cjne    @%1,%11,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 3
+%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
 
 replace {
        cjne    %1,%2,%3
@@ -1808,8 +1809,8 @@ replace {
        cjne    %5,%6,%8
        cjne    %10,%11,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 3
+%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
 
 replace {
        jnz     %3
@@ -1824,8 +1825,8 @@ replace {
        mov     a,%4
        cjne    %5,%6,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 2
+%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
 
 replace {
        cjne    %1,%2,%3
@@ -1840,8 +1841,8 @@ replace {
        mov     a,%4
        cjne    %5,%6,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 2
+%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
 
 replace {
        cjne     @%1,%2,%3
@@ -1856,8 +1857,8 @@ replace {
        inc     %1
        cjne    @%1,%6,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 2
+%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
 
 replace {
        cjne    %1,%2,%3
@@ -1866,12 +1867,12 @@ replace {
 %3:
        sjmp    %8
 } by {
-       ;       Peephole 198    optimized misc jump sequence
+       ;       Peephole 198.a  optimized misc jump sequence
        cjne    %1,%2,%8
        cjne    %5,%6,%8
        sjmp    %7
-;%3:
-} if labelRefCount %3 2
+%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
 
 replace {
        cjne    %1,%2,%3
@@ -1879,29 +1880,29 @@ replace {
 %3:
        sjmp    %5
 } by {
-       ;       Peephole 199    optimized misc jump sequence
+       ;       Peephole 198.b  optimized misc jump sequence
        cjne    %1,%2,%5
        sjmp    %4
-;%3:
-} if labelRefCount %3 1
+%3:
+} if labelRefCount(%3 1), labelRefCountChange(%3 -1)
 
 replace {
        sjmp    %1
 %1:
 } by {
-       ;       Peephole 200    removed redundant sjmp
+       ;       Peephole 200.a  removed redundant sjmp
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        sjmp    %1
 %2:
 %1:
 } by {
-       ;       Peephole 201    removed redundant sjmp
+       ;       Peephole 200.b  removed redundant sjmp
 %2:
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        push    acc
@@ -1942,7 +1943,7 @@ replace {
        djnz    %1,%4
 %2:
 %3:
-} if labelRefCount %2 1
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1), labelRefCountChange(%3 -1)
 
 replace {
        mov     %1,%1
@@ -2048,7 +2049,7 @@ replace {
        dec     r%1
        mov     @r%1,a
 } by {
-       ;       Peephole 216    simplified clear (2bytes)
+       ;       Peephole 216.a  simplified clear (2bytes)
        mov     r%1,%2
        clr     a
        mov     @r%1,a
@@ -2067,7 +2068,7 @@ replace {
        dec     r%1
        mov     @r%1,a
 } by {
-       ;       Peephole 217    simplified clear (3bytes)
+       ;       Peephole 216.b  simplified clear (3bytes)
        mov     r%1,%2
        clr     a
        mov     @r%1,a
@@ -2091,7 +2092,7 @@ replace {
        dec     r%1
        mov     @r%1,a
 } by {
-       ;       Peephole 218    simplified clear (4bytes)
+       ;       Peephole 216.c  simplified clear (4bytes)
        mov     r%1,%2
        clr     a
        mov     @r%1,a
@@ -2110,7 +2111,7 @@ replace {
        clr     a
        movx    @dptr,a
 } by {
-       ;       Peephole 219    removed redundant clear
+       ;       Peephole 219.a  removed redundant clear
        clr     a
        movx    @dptr,a
        mov     dptr,%1
@@ -2126,7 +2127,7 @@ replace {
        clr     a
        movx    @dptr,a
 } by {
-       ;       Peephole 219.a  removed redundant clear
+       ;       Peephole 219.b  removed redundant clear
        clr     a
        movx    @dptr,a
        mov     dptr,%1
@@ -2176,7 +2177,7 @@ replace {
        mov     dpl,%1
        mov     dph,%2
 } by {
-       ;       Peephole 223    removed redundant dph/dpl moves
+       ;       Peephole 223.a  removed redundant dph/dpl moves
        mov     %1,dpl
        mov     %2,dph
 } if notVolatile %1 %2
@@ -2187,7 +2188,7 @@ replace {
        mov     dpl,%1
        mov     dph,(%1 + 1)
 } by {
-       ;       Peephole 224    removed redundant dph/dpl moves
+       ;       Peephole 223.b  removed redundant dph/dpl moves
        mov     %1,dpl
        mov     (%1 + 1),dph
 } if notVolatile %1
@@ -2238,7 +2239,7 @@ replace {
        lcall   __decdptr
        movx    @dptr,a
 } by {
-       ;       Peephole 227    replaced inefficient 32 bit clear
+       ;       Peephole 227.a  replaced inefficient 32 bit clear
        mov     dptr,#%1
        clr     a
        movx    @dptr,a
@@ -2266,7 +2267,7 @@ replace {
        mov     a,#%2
        movx    @dptr,a
 } by {
-       ;       Peephole 228    replaced inefficient 32 constant
+       ;       Peephole 227.b  replaced inefficient 32 constant
        mov     dptr,#%1
        mov     a,#%2
        movx    @dptr,a
@@ -2288,7 +2289,7 @@ replace {
        lcall   __decdptr
        movx    @dptr,a
 } by {
-       ;       Peephole 229    replaced inefficient 16 bit clear
+       ;       Peephole 227.c  replaced inefficient 16 bit clear
        mov     dptr,#%1
        clr     a
        movx    @dptr,a
@@ -2306,7 +2307,7 @@ replace {
        mov     a,#%2
        movx    @dptr,a
 } by {
-       ;       Peephole 230    replaced inefficient 16 bit constant
+       ;       Peephole 227.d  replaced inefficient 16 bit constant
        mov     dptr,#%1
        mov     a,#%2
        movx    @dptr,a
@@ -2316,12 +2317,12 @@ replace {
        mov     dptr,#%1
 }
 
-// this last peephole often removes the last mov from 227-230
+// this last peephole often removes the last mov from 227.a - 227.d
 replace {
        mov     dptr,#%1
        mov     dptr,#%2
 } by {
-       ;       Peephole 231    removed redundant mov to dptr
+       ;       Peephole 227.e  removed redundant mov to dptr
        mov     dptr,#%2
 }
 
@@ -2346,7 +2347,7 @@ replace {
 %2:
        ret
 } by {
-       ;       Peephole 234    loading dpl directly from a(ccumulator), r%1 not set
+       ;       Peephole 234.a  loading dpl directly from a(ccumulator), r%1 not set
        mov     dpl,a
 %2:
        ret
@@ -2359,7 +2360,7 @@ replace {
 %3:
        ret
 } by {
-       ;       Peephole 235    loading dph directly from a(ccumulator), r%1 not set
+       ;       Peephole 234.b  loading dph directly from a(ccumulator), r%1 not set
        mov     dpl,r%2
        mov     dph,a
 %3:
@@ -2479,7 +2480,7 @@ replace {
        mov     %3,%4
 %1:
        ret
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        sjmp    %1
@@ -2498,7 +2499,7 @@ replace {
        mov     dph,%6
 %1:
        ret
-}
+} labelRefCountChange(%1 -1)
 
 // applies to f.e. device/lib/log10f.c
 replace {
@@ -2620,7 +2621,7 @@ replace {
        inc     a
 %3:
 %10:
-}
+} labelRefCountChange(%10 -1)
 
 // applies to f.e. time.c
 replace {
@@ -2639,7 +2640,7 @@ replace {
        inc     a
 %3:
 %6:
-}
+} labelRefCountChange(%6 -1)
 
 // applies to f.e. malloc.c
 replace {
@@ -2656,7 +2657,7 @@ replace {
        inc     a
 %3:
 %4:
-}
+} labelRefCountChange(%4 -1)
 
 // applies to f.e. j = (k!=0x1000);
 // with volatile idata long k;
@@ -2686,7 +2687,7 @@ replace {
        inc     a
 %3:
 %7:
-}
+} labelRefCountChange(%7 -1)
 
 // applies to f.e. j = (k!=0x1000);
 // with volatile idata int k;
@@ -2708,7 +2709,7 @@ replace {
        inc     a
 %3:
 %7:
-}
+} labelRefCountChange(%7 -1)
 
 // applies to f.e. vprintf.asm (--stack-auto)
 replace {
@@ -2725,7 +2726,7 @@ replace {
        inc     a
 %3:
 %7:
-}
+} labelRefCountChange(%7 -1)
 
 // applies to f.e. scott-bool1.c
 replace {
@@ -2790,7 +2791,7 @@ replace {
        inc     %4
 %3:
        sjmp    %5
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%3 -1), labelRefCountChange(%5 1)
 
 // applies to f.e. simplefloat.c (saving 1 cycle)
 replace {
@@ -2850,7 +2851,7 @@ replace {
        clr     a
        rlc     a
        mov     r%1,a
-} if labelRefCount %2 1
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1)
 
 // this one will not be triggered if 245 is present
 // please remove 245 if 245.a 245.b are found to be safe
@@ -2868,7 +2869,7 @@ replace {
 } by {
        ;       Peephole 245.a  optimized conditional jump (r%1 and acc not set!)
        jc      %3
-} if labelRefCount %2 1
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1)
 
 // this one will not be triggered if 245 is present
 // please remove 245 if 245.a 245.b are found to be safe
@@ -2886,7 +2887,7 @@ replace {
 } by {
        ;       Peephole 245.b  optimized conditional jump (r%1 and acc not set!)
        jnc     %3
-} if labelRefCount %2 1
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1)
 
 
 // rules 246.x apply to f.e. bitfields.c
@@ -3520,14 +3521,14 @@ replace {
 %1:
 } by {
        ;       Peephole 249.a   jump optimization
-} if labelRefCount %1 1
+} if labelRefCount(%1 1), labelRefCountChange(%1 -1)
 
 replace {
        jz      %1
 %1:
 } by {
        ;       Peephole 249.b   jump optimization
-} if labelRefCount %1 1
+} if labelRefCount(%1 1), labelRefCountChange(%1 -1)
 
 
 // This allows non-interrupt and interrupt code to safely compete
@@ -3546,7 +3547,7 @@ replace {
        jbc     %1,%3
        sjmp    %2
 %3:
-} if labelRefCount %3 0
+} if labelRefCount(%3 0), labelRefCountChange(%3 1)
 
 replace {
        jb      %1,%2
@@ -3567,7 +3568,7 @@ replace {
 } by {
        ;       Peephole 251.a  replaced ljmp to ret with ret
        ret
-} if labelIsReturnOnly
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
 
 // not before peephole 250.b
 replace {
@@ -3575,7 +3576,7 @@ replace {
 } by {
        ;       Peephole 251.b  replaced sjmp to ret with ret
        ret
-} if labelIsReturnOnly
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
 
 // applies to shifts.c and when accessing arrays with an unsigned integer index
 // saving 1 byte, 2 cycles
@@ -3614,6 +3615,7 @@ replace {
 } by {
        ;       Peephole 253.b  replaced lcall/ret with ljmp
        ljmp    %1
+       ;
 } if labelRefCount %2 0
 
 // applies to f.e. scott-bool1.c
@@ -3776,7 +3778,7 @@ replace {
        mov     %1,a
 %4:
 %3:
-} if notVolatile %1
+} if notVolatile(%1), labelRefCountChange(%3 -1)
 
 // in_byte<<=1; if(in_bit) in_byte|=1;
 replace {
@@ -3795,7 +3797,7 @@ replace {
        mov     r%1,a
 %4:
 %3:
-}
+} labelRefCountChange(%3 -1)
 
 // in_byte>>=1; if(in_bit) in_byte|=0x80;
 replace {
@@ -3815,7 +3817,7 @@ replace {
        mov     %1,a
 %4:
 %3:
-} if notVolatile %1
+} if notVolatile(%1), labelRefCountChange(%3 -1)
 
 // in_byte>>=1; if(in_bit) in_byte|=0x80;
 replace {
@@ -3835,7 +3837,7 @@ replace {
        mov     r%1,a
 %4:
 %3:
-}
+} labelRefCountChange(%3 -1)
 
 // out_bit=out_byte&0x80; out_byte<<=1;
 // helps f.e. writing data on a 3-wire (SPI) bus
@@ -3872,35 +3874,33 @@ replace {
        mov     %1,a
 } if notVolatile %1
 
-// Peepholes 259.x are not compatible with peepholex 250.x
-// Peepholes 250.x add jumps to a previously unused label. As the
+// Peepholes 259.x rely on the correct labelRefCount. Otherwise they are 
+// not compatible with peepholes 250.x
+// Peepholes 250.x add jumps to a previously unused label. If the 
 // labelRefCount is not increased, peepholes 259.x are (mistakenly) applied.
 // (Mail on sdcc-devel 2004-10-25)
-// Note: Peepholes 193..199, 251 remove jumps to previously used labels without
-// decreasing labelRefCount (less dangerous - this f.e. leads to 253.c being
-// applied instead of 253.b))
 //
 // applies to f.e. vprintf.c
-//replace {
-//     sjmp    %1
-//%2:
-//     ret
-//} by {
-//     sjmp    %1
-//     ;       Peephole 259.a  removed redundant label %2 and ret
-//     ;
-//} if labelRefCount %2 0
+replace {
+       sjmp    %1
+%2:    
+       ret
+} by {
+       sjmp    %1
+       ;       Peephole 259.a  removed redundant label %2 and ret
+       ;
+} if labelRefCount %2 0
 
 // applies to f.e. gets.c
-//replace {
-//     ljmp    %1
-//%2:
-//     ret
-//} by {
-//     ljmp    %1
-//     ;       Peephole 259.b  removed redundant label %2 and ret
-//     ;
-//} if labelRefCount %2 0
+replace {
+       ljmp    %1
+%2:    
+       ret
+} by {
+       ljmp    %1
+       ;       Peephole 259.b  removed redundant label %2 and ret
+       ;
+} if labelRefCount %2 0
 
 // optimizing jumptables
 // Please note: to enable peephole 260.x you currently have to set
@@ -4418,3 +4418,10 @@ replace {
        mov     acc.7,c
        mov     %1,a
 }
+
+// should be one of the last peepholes
+replace{
+%1:
+} by {
+       ;       Peephole 300    removed redundant label %1
+} if labelRefCount(%1 0)