} by {
; Peephole 107 removed redundant ljmp
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
jc %1
; Peephole 108 removed ljmp by inverse jump logic
jnc %5
%1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
replace {
jz %1
; Peephole 109 removed ljmp by inverse jump logic
jnz %5
%1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
replace {
jnz %1
; Peephole 110 removed ljmp by inverse jump logic
jz %5
%1:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%1 -1)
replace {
jb %1,%2
; Peephole 111 removed ljmp by inverse jump logic
jnb %1,%5
%2:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%2 -1)
replace {
jnb %1,%2
; Peephole 112.a removed ljmp by inverse jump logic
jb %1,%5
%2:
-} if labelInRange
+} if labelInRange(), labelRefCountChange(%2 -1)
replace {
ljmp %5
%3:
jnz %4
} by {
- ; Peephole 115.a jump optimization
+ ; Peephole 115.a jump optimization (acc not set)
cjne %1,%2,%3
sjmp %4
%3:
mov %1,a
jz %3
%2:
-}
+} labelRefCountChange(%2 -1)
replace {
clr a
%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
%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
%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
%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
%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
%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
%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
%3:
jz %4
} by {
- ; Peephole 123 jump optimization
+ ; Peephole 123 jump optimization (acc not set)
cjne %1,%2,%3
sjmp %4
%3:
%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
%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
%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
; Peephole 160 removed sjmp by inverse jump logic
jc %2
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
jc %1
; Peephole 161 removed sjmp by inverse jump logic
jnc %2
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
jnz %1
; Peephole 162 removed sjmp by inverse jump logic
jz %2
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
jz %1
; Peephole 163 removed sjmp by inverse jump logic
jnz %2
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
jnb %3,%1
; Peephole 164 removed sjmp by inverse jump logic
jb %3,%2
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
jb %3,%1
; Peephole 165 removed sjmp by inverse jump logic
jnb %3,%2
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
mov %1,%2
; Peephole 168 jump optimization
jb %1,%3
%2:
-}
+} labelRefCountChange(%2 -1)
replace {
jb %1,%2
; Peephole 169 jump optimization
jnb %1,%3
%2:
-}
+} labelRefCountChange(%2 -1)
replace {
clr a
; Peephole 170 jump optimization
cjne %1,%2,%4
%3:
-} if labelRefCount %3 1
+} if labelRefCount(%3 1), labelRefCountChange(%3 -1)
replace {
clr a
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
; 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
} by {
; Peephole 200 removed redundant sjmp
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
sjmp %1
; Peephole 201 removed redundant sjmp
%2:
%1:
-}
+} labelRefCountChange(%1 -1)
replace {
push acc
djnz %1,%4
%2:
%3:
-} if labelRefCount %2 1
+} if labelRefCount(%2 1), labelRefCountChange(%2 -1), labelRefCountChange(%3 -1)
replace {
mov %1,%1
mov %3,%4
%1:
ret
-}
+} labelRefCountChange(%1 -1)
replace {
sjmp %1
mov dph,%6
%1:
ret
-}
+} labelRefCountChange(%1 -1)
// applies to f.e. device/lib/log10f.c
replace {
inc a
%3:
%10:
-}
+} labelRefCountChange(%10 -1)
// applies to f.e. time.c
replace {
inc a
%3:
%6:
-}
+} labelRefCountChange(%6 -1)
// applies to f.e. malloc.c
replace {
inc a
%3:
%4:
-}
+} labelRefCountChange(%4 -1)
// applies to f.e. j = (k!=0x1000);
// with volatile idata long k;
inc a
%3:
%7:
-}
+} labelRefCountChange(%7 -1)
// applies to f.e. j = (k!=0x1000);
// with volatile idata int k;
inc a
%3:
%7:
-}
+} labelRefCountChange(%7 -1)
// applies to f.e. vprintf.asm (--stack-auto)
replace {
inc a
%3:
%7:
-}
+} labelRefCountChange(%7 -1)
// applies to f.e. scott-bool1.c
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 {
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
} 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
} 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
%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
jbc %1,%3
sjmp %2
%3:
-} if labelRefCount %3 0
+} if labelRefCount(%3 0), labelRefCountChange(%3 1)
replace {
jb %1,%2
} by {
; Peephole 251.a replaced ljmp to ret with ret
ret
-} if labelIsReturnOnly
+} if labelIsReturnOnly(), labelRefCountChange(%5 -1)
// not before peephole 250.b
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
} by {
; Peephole 253.b replaced lcall/ret with ljmp
ljmp %1
+ ;
} if labelRefCount %2 0
// applies to f.e. scott-bool1.c
mov %1,a
%4:
%3:
-} if notVolatile %1
+} if notVolatile(%1), labelRefCountChange(%3 -1)
// in_byte<<=1; if(in_bit) in_byte|=1;
replace {
mov r%1,a
%4:
%3:
-}
+} labelRefCountChange(%3 -1)
// in_byte>>=1; if(in_bit) in_byte|=0x80;
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 {
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
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
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)