src/mcs51/peeph.def: added labelrefcounting for peepholes (patch #1144962), added...
authorfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 12 Jul 2005 21:22:26 +0000 (21:22 +0000)
committerfrief <frief@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 12 Jul 2005 21:22:26 +0000 (21:22 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3801 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/mcs51/peeph.def

index cdb5ae28576ab3a72aff03960b033555b3c39808..5f390bb2a8b504c973b824b4b4bd0ecd081f8731 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2005-07-12 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
 
+       * src/mcs51/peeph.def: added labelrefcounting for peepholes
+         (patch #1144962), added peephole 300, enabled 259.x
        * doc/sdccman.lyx: removed screenshot and provided link instead
 
 2005-07-05 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
index 97095ba55720498bf40f3856c09b5546c7105d61..cc657b9747c8b205c154408ab5b0349250a9bbbc 100644 (file)
@@ -286,7 +286,7 @@ replace {
 } by {
        ;       Peephole 107    removed redundant ljmp
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jc      %1
@@ -296,7 +296,7 @@ replace {
        ;       Peephole 108    removed ljmp by inverse jump logic
        jnc     %5
 %1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
 
 replace {
        jz      %1
@@ -306,7 +306,7 @@ replace {
        ;       Peephole 109    removed ljmp by inverse jump logic
        jnz     %5
 %1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
 
 replace {
        jnz     %1
@@ -316,7 +316,7 @@ replace {
        ;       Peephole 110    removed ljmp by inverse jump logic
        jz      %5
 %1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
 
 replace {
        jb      %1,%2
@@ -326,7 +326,7 @@ replace {
        ;       Peephole 111    removed ljmp by inverse jump logic
        jnb     %1,%5
 %2:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%2 -1)
 
 replace {
        jnb     %1,%2
@@ -336,7 +336,7 @@ replace {
        ;       Peephole 112.a  removed ljmp by inverse jump logic
        jb      %1,%5
 %2:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%2 -1)
 
 replace {
        ljmp    %5
@@ -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 116    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 117    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 118    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 119    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 120    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 121    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 122    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 123    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 124    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 125    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 126    jump optimization (acc not set)
        cjne    %1,%2,%3
        cjne    %10,%11,%3
        cjne    %12,%13,%3
@@ -1061,7 +1061,7 @@ replace {
        ;       Peephole 160    removed sjmp by inverse jump logic
        jc      %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jc      %1
@@ -1071,7 +1071,7 @@ replace {
        ;       Peephole 161    removed sjmp by inverse jump logic
        jnc     %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jnz     %1
@@ -1081,7 +1081,7 @@ replace {
        ;       Peephole 162    removed sjmp by inverse jump logic
        jz      %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jz      %1
@@ -1091,7 +1091,7 @@ replace {
        ;       Peephole 163    removed sjmp by inverse jump logic
        jnz     %2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jnb     %3,%1
@@ -1101,7 +1101,7 @@ replace {
        ;       Peephole 164    removed sjmp by inverse jump logic
        jb      %3,%2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        jb      %3,%1
@@ -1111,7 +1111,7 @@ replace {
        ;       Peephole 165    removed sjmp by inverse jump logic
        jnb     %3,%2
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        mov     %1,%2
@@ -1140,7 +1140,7 @@ replace {
        ;       Peephole 168    jump optimization
        jb      %1,%3
 %2:
-}
+} labelRefCountChange(%2 -1)
 
 replace {
        jb      %1,%2
@@ -1150,7 +1150,7 @@ replace {
        ;       Peephole 169    jump optimization
        jnb     %1,%3
 %2:
-}
+} labelRefCountChange(%2 -1)
 
 replace {
        clr     a
@@ -1162,7 +1162,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 +1176,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 +1192,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 +1210,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
@@ -1666,8 +1666,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 +1690,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 +1714,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 +1732,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 +1752,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 +1772,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 +1792,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 +1808,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 +1824,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 +1840,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 +1856,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
@@ -1870,8 +1870,8 @@ replace {
        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
@@ -1882,8 +1882,8 @@ replace {
        ;       Peephole 199    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
@@ -1891,7 +1891,7 @@ replace {
 } by {
        ;       Peephole 200    removed redundant sjmp
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        sjmp    %1
@@ -1901,7 +1901,7 @@ replace {
        ;       Peephole 201    removed redundant sjmp
 %2:
 %1:
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        push    acc
@@ -1942,7 +1942,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
@@ -2479,7 +2479,7 @@ replace {
        mov     %3,%4
 %1:
        ret
-}
+} labelRefCountChange(%1 -1)
 
 replace {
        sjmp    %1
@@ -2498,7 +2498,7 @@ replace {
        mov     dph,%6
 %1:
        ret
-}
+} labelRefCountChange(%1 -1)
 
 // applies to f.e. device/lib/log10f.c
 replace {
@@ -2620,7 +2620,7 @@ replace {
        inc     a
 %3:
 %10:
-}
+} labelRefCountChange(%10 -1)
 
 // applies to f.e. time.c
 replace {
@@ -2639,7 +2639,7 @@ replace {
        inc     a
 %3:
 %6:
-}
+} labelRefCountChange(%6 -1)
 
 // applies to f.e. malloc.c
 replace {
@@ -2656,7 +2656,7 @@ replace {
        inc     a
 %3:
 %4:
-}
+} labelRefCountChange(%4 -1)
 
 // applies to f.e. j = (k!=0x1000);
 // with volatile idata long k;
@@ -2686,7 +2686,7 @@ replace {
        inc     a
 %3:
 %7:
-}
+} labelRefCountChange(%7 -1)
 
 // applies to f.e. j = (k!=0x1000);
 // with volatile idata int k;
@@ -2708,7 +2708,7 @@ replace {
        inc     a
 %3:
 %7:
-}
+} labelRefCountChange(%7 -1)
 
 // applies to f.e. vprintf.asm (--stack-auto)
 replace {
@@ -2725,7 +2725,7 @@ replace {
        inc     a
 %3:
 %7:
-}
+} labelRefCountChange(%7 -1)
 
 // applies to f.e. scott-bool1.c
 replace {
@@ -2790,7 +2790,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 +2850,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 +2868,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 +2886,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 +3520,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 +3546,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 +3567,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 +3575,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 +3614,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 +3777,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 +3796,7 @@ replace {
        mov     r%1,a
 %4:
 %3:
-}
+} labelRefCountChange(%3 -1)
 
 // in_byte>>=1; if(in_bit) in_byte|=0x80;
 replace {
@@ -3815,7 +3816,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 +3836,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 +3873,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 +4417,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)