git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3801
4a8a32a2-be11-0410-ad9d-
d568d2c75423
2005-07-12 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
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>
* doc/sdccman.lyx: removed screenshot and provided link instead
2005-07-05 Frieder Ferlemann <Frieder.Ferlemann AT web.de>
} by {
; Peephole 107 removed redundant ljmp
%1:
} by {
; Peephole 107 removed redundant ljmp
%1:
+} labelRefCountChange(%1 -1)
; Peephole 108 removed ljmp by inverse jump logic
jnc %5
%1:
; Peephole 108 removed ljmp by inverse jump logic
jnc %5
%1:
+} if labelInRange(), labelRefCountChange(%1 -1)
; Peephole 109 removed ljmp by inverse jump logic
jnz %5
%1:
; Peephole 109 removed ljmp by inverse jump logic
jnz %5
%1:
+} if labelInRange(), labelRefCountChange(%1 -1)
; Peephole 110 removed ljmp by inverse jump logic
jz %5
%1:
; Peephole 110 removed ljmp by inverse jump logic
jz %5
%1:
+} if labelInRange(), labelRefCountChange(%1 -1)
; Peephole 111 removed ljmp by inverse jump logic
jnb %1,%5
%2:
; Peephole 111 removed ljmp by inverse jump logic
jnb %1,%5
%2:
+} if labelInRange(), labelRefCountChange(%2 -1)
; Peephole 112.a removed ljmp by inverse jump logic
jb %1,%5
%2:
; Peephole 112.a removed ljmp by inverse jump logic
jb %1,%5
%2:
+} if labelInRange(), labelRefCountChange(%2 -1)
- ; Peephole 115.a jump optimization
+ ; Peephole 115.a jump optimization (acc not set)
cjne %1,%2,%3
sjmp %4
%3:
cjne %1,%2,%3
sjmp %4
%3:
+} labelRefCountChange(%2 -1)
- ; Peephole 116 jump optimization
+ ; Peephole 116 jump optimization (acc not set)
cjne %1,%2,%3
cjne %9,%10,%3
sjmp %4
cjne %1,%2,%3
cjne %9,%10,%3
sjmp %4
- ; Peephole 117 jump optimization
+ ; Peephole 117 jump optimization (acc not set)
cjne %1,%2,%3
cjne %9,%10,%3
cjne %11,%12,%3
cjne %1,%2,%3
cjne %9,%10,%3
cjne %11,%12,%3
- ; Peephole 118 jump optimization
+ ; Peephole 118 jump optimization (acc not set)
cjne %1,%2,%3
cjne %9,%10,%3
cjne %11,%12,%3
cjne %1,%2,%3
cjne %9,%10,%3
cjne %11,%12,%3
- ; Peephole 119 jump optimization
+ ; Peephole 119 jump optimization (acc not set)
+} if labelRefCount(%3 1), labelRefCountChange(%3 -1)
- ; Peephole 120 jump optimization
+ ; Peephole 120 jump optimization (acc not set)
cjne %1,%2,%4
cjne %10,%11,%4
%3:
cjne %1,%2,%4
cjne %10,%11,%4
%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%4 1)
- ; Peephole 121 jump optimization
+ ; Peephole 121 jump optimization (acc not set)
cjne %1,%2,%4
cjne %10,%11,%4
cjne %12,%13,%4
%3:
cjne %1,%2,%4
cjne %10,%11,%4
cjne %12,%13,%4
%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%4 2)
- ; 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:
cjne %1,%2,%4
cjne %10,%11,%4
cjne %12,%13,%4
cjne %14,%15,%4
%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%4 3)
- ; Peephole 123 jump optimization
+ ; Peephole 123 jump optimization (acc not set)
cjne %1,%2,%3
sjmp %4
%3:
cjne %1,%2,%3
sjmp %4
%3:
- ; Peephole 124 jump optimization
+ ; Peephole 124 jump optimization (acc not set)
cjne %1,%2,%3
cjne %10,%11,%3
sjmp %4
cjne %1,%2,%3
cjne %10,%11,%3
sjmp %4
- ; Peephole 125 jump optimization
+ ; Peephole 125 jump optimization (acc not set)
cjne %1,%2,%3
cjne %10,%11,%3
cjne %12,%13,%3
cjne %1,%2,%3
cjne %10,%11,%3
cjne %12,%13,%3
- ; Peephole 126 jump optimization
+ ; Peephole 126 jump optimization (acc not set)
cjne %1,%2,%3
cjne %10,%11,%3
cjne %12,%13,%3
cjne %1,%2,%3
cjne %10,%11,%3
cjne %12,%13,%3
; Peephole 160 removed sjmp by inverse jump logic
jc %2
%1:
; Peephole 160 removed sjmp by inverse jump logic
jc %2
%1:
+} labelRefCountChange(%1 -1)
; Peephole 161 removed sjmp by inverse jump logic
jnc %2
%1:
; Peephole 161 removed sjmp by inverse jump logic
jnc %2
%1:
+} labelRefCountChange(%1 -1)
; Peephole 162 removed sjmp by inverse jump logic
jz %2
%1:
; Peephole 162 removed sjmp by inverse jump logic
jz %2
%1:
+} labelRefCountChange(%1 -1)
; Peephole 163 removed sjmp by inverse jump logic
jnz %2
%1:
; Peephole 163 removed sjmp by inverse jump logic
jnz %2
%1:
+} labelRefCountChange(%1 -1)
; Peephole 164 removed sjmp by inverse jump logic
jb %3,%2
%1:
; Peephole 164 removed sjmp by inverse jump logic
jb %3,%2
%1:
+} labelRefCountChange(%1 -1)
; Peephole 165 removed sjmp by inverse jump logic
jnb %3,%2
%1:
; Peephole 165 removed sjmp by inverse jump logic
jnb %3,%2
%1:
+} labelRefCountChange(%1 -1)
; Peephole 168 jump optimization
jb %1,%3
%2:
; Peephole 168 jump optimization
jb %1,%3
%2:
+} labelRefCountChange(%2 -1)
; Peephole 169 jump optimization
jnb %1,%3
%2:
; Peephole 169 jump optimization
jnb %1,%3
%2:
+} labelRefCountChange(%2 -1)
; Peephole 170 jump optimization
cjne %1,%2,%4
%3:
; Peephole 170 jump optimization
cjne %1,%2,%4
%3:
+} if labelRefCount(%3 1), labelRefCountChange(%3 -1)
cjne %1,%2,%4
cjne %9,%10,%4
%3:
cjne %1,%2,%4
cjne %9,%10,%4
%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%4 1)
cjne %9,%10,%4
cjne %11,%12,%4
%3:
cjne %9,%10,%4
cjne %11,%12,%4
%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%4 2)
cjne %11,%12,%4
cjne %13,%14,%4
%3:
cjne %11,%12,%4
cjne %13,%14,%4
%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%4 3)
mov a,%12
cjne %13,%14,%8
sjmp %7
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)
mov a,%12
cjne %13,%14,%8
sjmp %7
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)
inc %1
cjne @%1,%14,%8
sjmp %7
inc %1
cjne @%1,%14,%8
sjmp %7
-;%3:
-} if labelRefCount %3 4
+%3:
+} if labelRefCount(%3 4), labelRefCountChange(%3 -4), labelRefCountChange(%8 3)
cjne %10,%11,%8
cjne %13,%14,%8
sjmp %7
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)
mov a,%9
cjne %10,%11,%8
sjmp %7
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)
mov a,%9
cjne %10,%11,%8
sjmp %7
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)
inc %1
cjne @%1,%11,%8
sjmp %7
inc %1
cjne @%1,%11,%8
sjmp %7
-;%3:
-} if labelRefCount %3 3
+%3:
+} if labelRefCount(%3 3), labelRefCountChange(%3 -3), labelRefCountChange(%8 2)
cjne %5,%6,%8
cjne %10,%11,%8
sjmp %7
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)
mov a,%4
cjne %5,%6,%8
sjmp %7
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)
mov a,%4
cjne %5,%6,%8
sjmp %7
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)
inc %1
cjne @%1,%6,%8
sjmp %7
inc %1
cjne @%1,%6,%8
sjmp %7
-;%3:
-} if labelRefCount %3 2
+%3:
+} if labelRefCount(%3 2), labelRefCountChange(%3 -2), labelRefCountChange(%8 1)
cjne %1,%2,%8
cjne %5,%6,%8
sjmp %7
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)
; Peephole 199 optimized misc jump sequence
cjne %1,%2,%5
sjmp %4
; 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)
} by {
; Peephole 200 removed redundant sjmp
%1:
} by {
; Peephole 200 removed redundant sjmp
%1:
+} labelRefCountChange(%1 -1)
; Peephole 201 removed redundant sjmp
%2:
%1:
; Peephole 201 removed redundant sjmp
%2:
%1:
+} labelRefCountChange(%1 -1)
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1), labelRefCountChange(%3 -1)
+} labelRefCountChange(%1 -1)
+} labelRefCountChange(%1 -1)
// applies to f.e. device/lib/log10f.c
replace {
// applies to f.e. device/lib/log10f.c
replace {
+} labelRefCountChange(%10 -1)
// applies to f.e. time.c
replace {
// applies to f.e. time.c
replace {
+} labelRefCountChange(%6 -1)
// applies to f.e. malloc.c
replace {
// applies to f.e. malloc.c
replace {
+} labelRefCountChange(%4 -1)
// applies to f.e. j = (k!=0x1000);
// with volatile idata long k;
// applies to f.e. j = (k!=0x1000);
// with volatile idata long k;
+} labelRefCountChange(%7 -1)
// applies to f.e. j = (k!=0x1000);
// with volatile idata int k;
// applies to f.e. j = (k!=0x1000);
// with volatile idata int k;
+} labelRefCountChange(%7 -1)
// applies to f.e. vprintf.asm (--stack-auto)
replace {
// applies to f.e. vprintf.asm (--stack-auto)
replace {
+} labelRefCountChange(%7 -1)
// applies to f.e. scott-bool1.c
replace {
// applies to f.e. scott-bool1.c
replace {
+} if labelInRange(), labelRefCountChange(%3 -1), labelRefCountChange(%5 1)
// applies to f.e. simplefloat.c (saving 1 cycle)
replace {
// applies to f.e. simplefloat.c (saving 1 cycle)
replace {
+} 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
// this one will not be triggered if 245 is present
// please remove 245 if 245.a 245.b are found to be safe
} by {
; Peephole 245.a optimized conditional jump (r%1 and acc not set!)
jc %3
} by {
; Peephole 245.a optimized conditional jump (r%1 and acc not set!)
jc %3
+} 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
// this one will not be triggered if 245 is present
// please remove 245 if 245.a 245.b are found to be safe
} by {
; Peephole 245.b optimized conditional jump (r%1 and acc not set!)
jnc %3
} by {
; Peephole 245.b optimized conditional jump (r%1 and acc not set!)
jnc %3
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1)
// rules 246.x apply to f.e. bitfields.c
// rules 246.x apply to f.e. bitfields.c
%1:
} by {
; Peephole 249.a jump optimization
%1:
} by {
; Peephole 249.a jump optimization
+} if labelRefCount(%1 1), labelRefCountChange(%1 -1)
replace {
jz %1
%1:
} by {
; Peephole 249.b jump optimization
replace {
jz %1
%1:
} by {
; Peephole 249.b jump optimization
+} if labelRefCount(%1 1), labelRefCountChange(%1 -1)
// This allows non-interrupt and interrupt code to safely compete
// This allows non-interrupt and interrupt code to safely compete
+} if labelRefCount(%3 0), labelRefCountChange(%3 1)
} by {
; Peephole 251.a replaced ljmp to ret with ret
ret
} by {
; Peephole 251.a replaced ljmp to ret with ret
ret
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
// not before peephole 250.b
replace {
// not before peephole 250.b
replace {
} by {
; Peephole 251.b replaced sjmp to ret with ret
ret
} by {
; Peephole 251.b replaced sjmp to ret with ret
ret
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
// applies to shifts.c and when accessing arrays with an unsigned integer index
// saving 1 byte, 2 cycles
// applies to shifts.c and when accessing arrays with an unsigned integer index
// saving 1 byte, 2 cycles
} by {
; Peephole 253.b replaced lcall/ret with ljmp
ljmp %1
} by {
; Peephole 253.b replaced lcall/ret with ljmp
ljmp %1
} if labelRefCount %2 0
// applies to f.e. scott-bool1.c
} if labelRefCount %2 0
// applies to f.e. scott-bool1.c
+} if notVolatile(%1), labelRefCountChange(%3 -1)
// in_byte<<=1; if(in_bit) in_byte|=1;
replace {
// in_byte<<=1; if(in_bit) in_byte|=1;
replace {
+} labelRefCountChange(%3 -1)
// in_byte>>=1; if(in_bit) in_byte|=0x80;
replace {
// in_byte>>=1; if(in_bit) in_byte|=0x80;
replace {
+} if notVolatile(%1), labelRefCountChange(%3 -1)
// in_byte>>=1; if(in_bit) in_byte|=0x80;
replace {
// in_byte>>=1; if(in_bit) in_byte|=0x80;
replace {
+} labelRefCountChange(%3 -1)
// out_bit=out_byte&0x80; out_byte<<=1;
// helps f.e. writing data on a 3-wire (SPI) bus
// out_bit=out_byte&0x80; out_byte<<=1;
// helps f.e. writing data on a 3-wire (SPI) bus
mov %1,a
} if notVolatile %1
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)
// 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
//
// 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
// 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
// optimizing jumptables
// Please note: to enable peephole 260.x you currently have to set
+
+// should be one of the last peepholes
+replace{
+%1:
+} by {
+ ; Peephole 300 removed redundant label %1
+} if labelRefCount(%1 0)