* src/mcs51/gen.c (leftRightUseAcc): use macro IS_OP_ACCUSE
[fw/sdcc] / src / mcs51 / peeph.def
index 8369811dd5f9a9e481bfc4543e798ea09de5020a..51e251225c6122972dee40d09b6609f7d310ae41 100644 (file)
@@ -740,17 +740,18 @@ replace {
        jc      %5
 } if operandsLiteral(%1)
 
-replace {
-       clr     c
-       mov     a,%1
-       subb    a,#%2
-       mov     %3,c
-} by {
-       ;       Peephole 132.d  optimized genCmpGt by inverse logic
-       mov     a,#0x100 - %2
-       add     a,%1
-       mov     %3,c
-} if operandsNotRelated('0x00' %2), operandsLiteral(%2)
+// disabled. See bug1734654.c
+//replace {
+//     clr     c
+//     mov     a,%1
+//     subb    a,#%2
+//     mov     %3,c
+//} by {
+//     ;       Peephole 132.d  optimized genCmpGt by inverse logic
+//     mov     a,#0x100 - %2
+//     add     a,%1
+//     mov     %3,c
+//} if operandsNotRelated('0x00' %2), operandsLiteral(%2)
 
 replace {
        clr     c
@@ -1366,6 +1367,16 @@ replace {
        mov     %1,a
 } if notVolatile %2
 
+// applies to f.e. testfwk.c
+replace {
+       mov     r%1,a
+       mov     ar%2,r%1
+} by {
+       mov     r%1,a
+       ;       peephole 177.i  optimized mov sequence
+       mov     r%2,a
+}
+
 replace {
        mov     a,%1
        mov     b,a
@@ -1483,15 +1494,15 @@ replace {
        mov     %1,a
 } if notVolatile %1
 
-replace {
-// acc being incremented might cause problems
-       mov     %1,a
-       inc     %1
-} by {
-       ;       Peephole 185    changed order of increment (acc incremented also!)
-       inc     a
-       mov     %1,a
-} if notVolatile %1
+//replace {
+// acc being incremented might cause problems with register tracking
+//     mov     %1,a
+//     inc     %1
+//} by {
+//     ;       Peephole 185    changed order of increment (acc incremented also!)
+//     inc     a
+//     mov     %1,a
+//} if notVolatile %1
 
 // char indexed access to: long code table[] = {4,3,2,1};
 replace restart {
@@ -1690,15 +1701,26 @@ replace {
        ;       Peephole 191    removed redundant mov
 } if notVolatile %1
 
+// applies to f.e. regression/ports/mcs51/support.c
 replace {
        mov     r%1,a
        mov     @r%2,ar%1
 } by {
        mov     r%1,a
-       ;       Peephole 192    used a instead of ar%1 as source
+       ;       Peephole 192.a  used a instead of ar%1 as source
        mov     @r%2,a
 }
 
+// applies to f.e. printf_large.c
+replace {
+       mov     ar%1,@r%2
+       mov     a,r%1
+} by {
+       ;       Peephole 192.b  used a instead of ar%1 as destination
+       mov     a,@r%2
+       mov     r%1,a
+}
+
 replace {
        jnz     %3
        mov     a,%4
@@ -3712,39 +3734,6 @@ replace {
        mov     r%3,a
 }
 
-// applies to: void test( char c ) { if( c ) func1(); else func2(); }
-replace {
-       lcall   %1
-       ret
-} by {
-       ;       Peephole 253.a  replaced lcall/ret with ljmp
-       ljmp    %1
-}
-
-// applies to: void test( char c ) { if( c ) func1(); else func2(); }
-replace {
-       lcall   %1
-%2:
-       ret
-} by {
-       ;       Peephole 253.b  replaced lcall/ret with ljmp
-       ljmp    %1
-       ;
-} if labelRefCount %2 0
-
-// applies to f.e. scott-bool1.c
-replace {
-       lcall   %1
-%2:
-       ret
-} by {
-       ;       Peephole 253.c  replaced lcall with ljmp
-       ljmp    %1
-%2:
-       ret
-}
-
-
 // applies to f.e. funptrs.c
 // saves one byte if %1 is a register or @register
 replace {
@@ -3873,16 +3862,17 @@ replace {
        djnz    %1,%2
 } if notVolatile(%1)
 
-// unsigned char i=8; do{ } while(--i != 0);
-// this applies if i is kept in data memory
-replace {
-       dec     %1
-       mov     a,%1
-       jnz     %2
-} by {
-       ;       Peephole 257.b  optimized decrement with compare
-       djnz    %1,%2
-} if notVolatile(%1), operandsNotRelated(%1 '@r0' '@r1')
+//// unsigned char i=8; do{ } while(--i != 0);
+//// this applies if i is kept in data memory
+// Disabled because together with 256.c it causes bug #1721024
+//replace {
+//     dec     %1
+//     mov     a,%1
+//     jnz     %2
+//} by {
+//     ;       Peephole 257.b  optimized decrement with compare
+//     djnz    %1,%2
+//} if notVolatile(%1), operandsNotRelated(%1 '@r0' '@r1')
 
 
 // in_byte<<=1; if(in_bit) in_byte|=1;
@@ -4559,7 +4549,7 @@ replace {
 } by {
        ;       Peephole 263.a  optimized loading const
        mov     %1,#(%2 + 3)
-}
+} if notVolatile(%1)
 
 replace {
        mov     %1,#%2
@@ -4568,7 +4558,7 @@ replace {
 } by {
        ;       Peephole 263.b  optimized loading const
        mov     %1,#(%2 + 2)
-}
+} if notVolatile(%1)
 
 replace {
        mov     %1,#%2
@@ -4576,7 +4566,7 @@ replace {
 } by {
        ;       Peephole 263.c  optimized loading const
        mov     %1,#(%2 + 1)
-}
+} if notVolatile(%1)
 
 
 replace {
@@ -4591,15 +4581,72 @@ replace {
 %3:
 } if labelRefCount(%3 1), labelRefCountChange(%3 -1)
 
+
 replace restart {
        pop     ar%1
 } by {
        ;       Peephole 300    pop ar%1 removed
-} if deadMove %1
+} if deadMove(%1)
+
+replace {
+       mov     r%1,%2
+} by {
+       ;       Peephole 301    mov r%1,%2 removed
+} if notVolatile(%2), deadMove(%1)
+
+
+// applies to: void test( char c ) { if( c ) func1(); else func2(); }
+replace {
+       lcall   %1
+       ret
+} by {
+       ;       Peephole 400.a  replaced lcall/ret with ljmp
+       ljmp    %1
+}
+
+// applies to: void test( char c ) { if( c ) func1(); else func2(); }
+replace {
+       lcall   %1
+%2:
+       ret
+} by {
+       ;       Peephole 400.b  replaced lcall/ret with ljmp
+       ljmp    %1
+       ;
+} if labelRefCount %2 0
+
+// applies to f.e. scott-bool1.c
+replace {
+       lcall   %1
+%2:
+       ret
+} by {
+       ;       Peephole 400.c  replaced lcall with ljmp
+       ljmp    %1
+%2:
+       ret
+}
+
+// for programs less than 2k
+replace {
+       lcall   %1
+} by {
+       ;       Peephole 400.d  replaced lcall with acall
+       acall   %1
+} if useAcallAjmp
+
+// for programs less than 2k
+replace {
+       ljmp    %1
+} by {
+       ;       Peephole 400.e  replaced ljmp with ajmp
+       ajmp    %1
+} if useAcallAjmp
+
 
 // should be one of the last peepholes
 replace{
 %1:
 } by {
-       ;       Peephole 400    removed redundant label %1
+       ;       Peephole 500    removed redundant label %1
 } if labelRefCount(%1 0)