X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmcs51%2Fpeeph.def;h=08f8b0225133a3b4c085e1fc078623e9cf47e292;hb=80972b2e54c9b88f11c27b878874fd2a6a681391;hp=97492818f227249f8f51df14372f145fa71ec8cb;hpb=e488f474083f79233c0d203a54b1b03599b0231f;p=fw%2Fsdcc diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index 97492818..08f8b022 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -1,20 +1,3 @@ -//replace restart { -// pop %1 -// push %1 -//} by { -// ; Peephole 1 removed pop %1 push %1 (not push pop) -//} - -//replace restart { -// pop %1 -// mov %2,%3 -// push %1 -//} by { -// ; Peephole 2 removed pop %1 push %1 (not push pop) -// mov %2,%3 -//} - -// // added by Jean Louis VERN for // his shift stuff replace { @@ -193,6 +176,52 @@ replace { movx @dptr,a } if notVolatile %1 +// applies to f.e. lib/src/time.c (--model-large) +replace { + mov a,%1 + movx @dptr,a + inc dptr + mov a,%1 + movx @dptr,a + inc dptr + mov a,%1 + movx @dptr,a + inc dptr + mov a,%1 + movx @dptr,a +} by { + mov a,%1 + movx @dptr,a + inc dptr + ; Peephole 101.a removed redundant moves + movx @dptr,a + inc dptr + movx @dptr,a + inc dptr + movx @dptr,a +} if notVolatile %1 + +// applies to f.e. support/regression/tests/literalop.c (--model-large) +replace { + mov a,%1 + movx @dptr,a + inc dptr + mov a,%1 + movx @dptr,a + inc dptr + mov a,%1 + movx @dptr,a +} by { + mov a,%1 + movx @dptr,a + inc dptr + ; Peephole 101.b removed redundant moves + movx @dptr,a + inc dptr + movx @dptr,a +} if notVolatile %1 + +// applies to f.e. support/regression/tests/onebyte.c (--model-large) replace { mov a,%1 movx @dptr,a @@ -203,7 +232,7 @@ replace { mov a,%1 movx @dptr,a inc dptr - ; Peephole 101 removed redundant mov + ; Peephole 101.c removed redundant mov movx @dptr,a } if notVolatile %1 @@ -268,7 +297,7 @@ replace { mov a,%1 } by { mov %1,a -; Peephole 105 removed redundant mov + ; Peephole 105 removed redundant mov } if notVolatile %1 replace { @@ -711,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 @@ -793,7 +823,7 @@ replace { mov %1,a mov dpl,%2 mov dph,%3 - ; Peephole 136 removed redundant move + ; Peephole 136 removed redundant mov } if notVolatile %1 // WTF? Doesn't look sensible to me... @@ -845,7 +875,8 @@ replace { } by { ; Peephole 139.b removed redundant mov orl a,%2 - mov r%1,a } + mov r%1,a +} replace { mov r%1,a @@ -875,7 +906,7 @@ replace { mov r%2,ar%1 mov ar%1,@r%2 } by { - ; Peephole 142 removed redundant moves + ; Peephole 142 removed redundant mov mov r%2,a mov ar%1,@r%2 } @@ -1284,9 +1315,9 @@ replace { mov %1,%2 mov %1,%3 } by { - ; Peephole 177.c removed redundant move + ; Peephole 177.c removed redundant mov mov %1,%3 -} if notVolatile %1 %2 +} if notVolatile(%1 %2),operandsNotRelated(%1 %3) // applies to f.e. bug-408972.c // not before peephole 177.c @@ -1297,24 +1328,23 @@ replace restart { } by { mov %1,%2 mov %3,%4 - ; Peephole 177.d removed redundant move + ; Peephole 177.d removed redundant mov } if notVolatile(%1 %2),operandsNotRelated(%1 %2 %3) // applies to f.e. bug-607243.c -// also check notVolatile %3, as it will return FALSE if it's @r%1 replace { - mov r%1,%2 - mov ar%1,%3 + mov %1,%2 + mov a%1,%3 } by { - ; peephole 177.e removed redundant move - mov ar%1,%3 -} if notVolatile %2 %3 + ; peephole 177.e removed redundant mov %1,%2 + mov a%1,%3 +} if notVolatile(%2), operandsNotRelated(%1 %3) replace { mov ar%1,%2 mov r%1,%3 } by { - ; peephole 177.f removed redundant move + ; peephole 177.f removed redundant mov mov r%1,%3 } if notVolatile %2 @@ -1336,6 +1366,26 @@ 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 r%1,%2 + mov ar%3,r%1 + mov r%1,%4 +} by { + ; peephole 177.j optimized mov sequence + mov r%3,%2 + mov r%1,%4 +} + replace { mov a,%1 mov b,a @@ -1453,15 +1503,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 { @@ -1660,15 +1710,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 @@ -1691,7 +1752,7 @@ replace { cjne %13,%14,%8 sjmp %7 %3: -} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) +} if labelInRange(%8), labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) replace { cjne %1,%2,%3 @@ -1715,7 +1776,7 @@ replace { cjne %13,%14,%8 sjmp %7 %3: -} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) +} if labelInRange(%8), labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) replace { cjne @%1,%2,%3 @@ -1739,7 +1800,7 @@ replace { cjne @%1,%14,%8 sjmp %7 %3: -} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) +} if labelInRange(%8), labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) replace { cjne %1,%2,%3 @@ -1757,7 +1818,7 @@ replace { cjne %13,%14,%8 sjmp %7 %3: -} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) +} if labelInRange(%8), labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3) replace { jnz %3 @@ -1777,7 +1838,7 @@ replace { cjne %10,%11,%8 sjmp %7 %3: -} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) +} if labelInRange(%8), labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) replace { cjne %1,%2,%3 @@ -1797,7 +1858,7 @@ replace { cjne %10,%11,%8 sjmp %7 %3: -} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) +} if labelInRange(%8), labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) replace { cjne @%1,%2,%3 @@ -1817,7 +1878,7 @@ replace { cjne @%1,%11,%8 sjmp %7 %3: -} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) +} if labelInRange(%8), labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) replace { cjne %1,%2,%3 @@ -1833,7 +1894,7 @@ replace { cjne %10,%11,%8 sjmp %7 %3: -} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) +} if labelInRange(%8), labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2) replace { jnz %3 @@ -1849,7 +1910,7 @@ replace { cjne %5,%6,%8 sjmp %7 %3: -} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) +} if labelInRange(%8), labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) replace { cjne %1,%2,%3 @@ -1865,7 +1926,7 @@ replace { cjne %5,%6,%8 sjmp %7 %3: -} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) +} if labelInRange(%8), labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) replace { cjne @%1,%2,%3 @@ -1881,7 +1942,7 @@ replace { cjne @%1,%6,%8 sjmp %7 %3: -} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) +} if labelInRange(%8), labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) replace { cjne %1,%2,%3 @@ -1895,7 +1956,7 @@ replace { cjne %5,%6,%8 sjmp %7 %3: -} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) +} if labelInRange(%8), labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1) replace { cjne %1,%2,%3 @@ -1907,7 +1968,7 @@ replace { cjne %1,%2,%5 sjmp %4 %3: -} if labelRefCount(%3 1), labelRefCountChange(%3 -1) +} if labelInRange(%5), labelRefCount(%3 1), labelRefCountChange(%3 -1) replace { sjmp %1 @@ -1972,7 +2033,7 @@ replace { mov %1,%1 } by { ; Peephole 206 removed redundant mov %1,%1 -} if notVolatile +} if notVolatile %1 // Does not seem to be triggered anymore //replace { @@ -2054,7 +2115,7 @@ replace { add a,%1 } by { mov %1,a - ; Peephole 214 reduced some extra moves + ; Peephole 214.a removed redundant mov add a,%2 } if operandsNotSame @@ -2063,7 +2124,7 @@ replace { add a,%2 mov %1,a } by { - ; Peephole 215 removed some moves + ; Peephole 214.b removed redundant mov add a,%2 mov %1,a } if operandsNotSame @@ -2182,13 +2243,13 @@ replace { replace { mov %1 + %2,(%2 + %1) } by { - ; Peephole 221.a remove redundant move + ; Peephole 221.a remove redundant mov } if notVolatile replace { mov (%1 + %2 + %3),((%2 + %1) + %3) } by { - ; Peephole 221.b remove redundant move + ; Peephole 221.b remove redundant mov } if notVolatile replace { @@ -3682,37 +3743,27 @@ 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(); } +// unsigned char i=8; do{ } while(--i != 0); +// this applies if i is kept in a register replace { - lcall %1 -%2: - ret + dec %1 + cjne %1,#0x00,%2 } by { - ; Peephole 253.b replaced lcall/ret with ljmp - ljmp %1 - ; -} if labelRefCount %2 0 + ; Peephole 253.a optimized decrement with compare + djnz %1,%2 +} if notVolatile(%1) -// applies to f.e. scott-bool1.c +// unsigned char i=8; do{ } while(--i != 0); +// this applies if i is kept in data memory +// must come before 256, see bug 1721024 replace { - lcall %1 -%2: - ret + dec %1 + mov a,%1 + jnz %2 } by { - ; Peephole 253.c replaced lcall with ljmp - ljmp %1 -%2: - ret -} + ; Peephole 253.b optimized decrement with compare + djnz %1,%2 +} if notVolatile(%1), operandsNotRelated(%1 '@r0' '@r1') // applies to f.e. funptrs.c @@ -3833,28 +3884,6 @@ replace { } if labelRefCount(%2 0),operandsNotRelated('a' %4 %6 %8) -// unsigned char i=8; do{ } while(--i != 0); -// this applies if i is kept in a register -replace { - dec %1 - cjne %1,#0x00,%2 -} by { - ; Peephole 257.a optimized decrement with compare - 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') - - // in_byte<<=1; if(in_bit) in_byte|=1; // helps f.e. reading data on a 3-wire (SPI) bus replace { @@ -4529,7 +4558,7 @@ replace { } by { ; Peephole 263.a optimized loading const mov %1,#(%2 + 3) -} +} if notVolatile(%1) replace { mov %1,#%2 @@ -4538,7 +4567,7 @@ replace { } by { ; Peephole 263.b optimized loading const mov %1,#(%2 + 2) -} +} if notVolatile(%1) replace { mov %1,#%2 @@ -4546,7 +4575,7 @@ replace { } by { ; Peephole 263.c optimized loading const mov %1,#(%2 + 1) -} +} if notVolatile(%1) replace { @@ -4561,9 +4590,169 @@ replace { %3: } if labelRefCount(%3 1), labelRefCountChange(%3 -1) + +replace { + mov %1,c + cpl %1 +} by { + ; Peephole 265 optimized mov/cpl sequence (carry differs) + cpl c + mov %1,c +} if notVolatile(%1) + +replace { + mov %1,c + jb %1,%2 +} by { + ; Peephole 266.a optimized mov/jump sequence + mov %1,c + jc %2 +} if notVolatile(%1) + +replace { + mov %1,c + jnb %1,%2 +} by { + ; Peephole 266.b optimized mov/jump sequence + mov %1,c + jnc %2 +} if notVolatile(%1) + +replace { + jnc %1 + setb %2 + sjmp %3 +%1: + clr %2 +%3: +} by { + ; Peephole 267.a optimized mov bit sequence + mov %2,c +%1: +%3: +} if labelRefCount(%1 1), labelRefCountChange(%1 -1), labelRefCountChange(%3 -1) + +replace { + jc %1 + clr %2 + sjmp %3 +%1: + setb %2 +%3: +} by { + ; Peephole 267.b optimized mov bit sequence + mov %2,c +%1: +%3: +} if labelRefCount(%1 1), labelRefCountChange(%1 -1), labelRefCountChange(%3 -1) + +replace { + mov %1,c + mov %1,c +} by { + ; Peephole 268 removed redundant mov + mov %1,c +} if notVolatile(%1) + +replace { + mov %1,c + mov c,%1 +} by { + ; Peephole 269 removed redundant mov + mov %1,c +} if notVolatile(%1) + +//accessing struct/array on stack +replace { + add a,#%1 + add a,#%2 +} by { + ; Peephole 270 removed redundant add + add a,#%1+%2 +} + +replace { + jz %1 + mov %2,%4 + sjmp %3 +%1: + mov %2,#0x00 +%3: +} by { + jz %1 + ; Peephole 271 optimized ternary operation (acc different) + mov a,%4 +%1: + mov %2,a +%3: +} if operandsNotRelated('a' 'dptr' %2), labelRefCount(%1 1), labelRefCountChange(%3 -1) + + +replace restart { + pop ar%1 +} by { + ; Peephole 300 pop ar%1 removed +} 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 300 removed redundant label %1 + ; Peephole 500 removed redundant label %1 } if labelRefCount(%1 0)