I found some difference in code generation between padauk and msc51 targets.
unsigned long long foo=1;
void main() {
for(;;) foo ^= 0xFFFFFF55;
}
for pdk14 sdcc emit perfect code
00102$:
mov a, #0x55
xor _foo+0, a
not _foo+1
not _foo+2
not _foo+3
goto 00102$
but for mcs51 it looks a bit ugly
00102$:
xrl _foo,#0x55
xrl (_foo + 1),#0xff
xrl (_foo + 2),#0xff
xrl (_foo + 3),#0xff
xrl (_foo + 4),#0x00
xrl (_foo + 5),#0x00
xrl (_foo + 6),#0x00
xrl (_foo + 7),#0x00
sjmp 00102$
I believe that it might be better to eliminate useless XORs in genXor rather by peephole rule as it made in PDK case.
Yes I got similar issue
[#748]
Related
Feature Requests: #748
Last edit: Maarten Brock 2022-04-21
Similar optimization is also needed to add.
The problem is not in the addition here. First
aneeds an upcast which assigns the zero to r7. Then it is added to (1<<8).This is probably really handled best by a peephole rule. Register tracking may be used to find the value of r7 instead of relying on the position of the assignment. But care must also be taken not to corrupt the carry after the removal of
add.I'm afraid that's off topic. You may not expect optimizations with "volatile"
I cannot reproduce the issue with either SDCC 4.2.0 or trunk
sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/ds390/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502 4.2.0 #13081 (Linux)
published under GNU General Public License (GPL)
Last edit: Gabriele Gorla 2024-12-06
It's there up to 4.3.1_20231106-14398, including 13081.
From 4.4.0_20231222-14549, the topic is no longer relevant.
Could possibly narrow it down, but this is what I can verify quickly.
The generated asm looks fine in current trunk.