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
} by {
; 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
} 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 mov
- 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 %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
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
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
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
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
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
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
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
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
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
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
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
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
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
mov r%3,a
}
+// 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 253.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
+// must come before 256, see bug 1721024
+replace {
+ dec %1
+ mov a,%1
+ jnz %2
+} by {
+ ; Peephole 253.b optimized decrement with compare
+ djnz %1,%2
+} if notVolatile(%1), operandsNotRelated(%1 '@r0' '@r1')
+
+
// applies to f.e. funptrs.c
// saves one byte if %1 is a register or @register
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
-// 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;
// helps f.e. reading data on a 3-wire (SPI) bus
replace {
} 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 (carry might differ, bug 2736282)
+// 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 {
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{