SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/gbz80/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.1.12 #12697 (MINGW32)
command line:
sdcc -mpdk13 -DPMS150C --opt-code-size --fverbose-asm --peep-asm --peep-return test.c
test code:
volatile __sfr __at(0x10) _pa; void main() { __asm__("mov a,#00 ;"); __asm__("mov a,#01; "); __asm__("mov a,#02; some comments"); __asm__("mov a,#03"); __asm__("mov __pa,a"); }
resilt is:
000000 105 _main: 106 ; ../test.c: 4: __asm__("mov a,#00 ;"); 107 ; genInline 000000 00 17 108 mov a,#00 ; 109 ; ../test.c: 5: __asm__("mov a,#01; "); 110 ; genInline 111 ; peephole 0 removed dead load into a from #01;. 112 ; ../test.c: 6: __asm__("mov a,#02; some comments"); 113 ; genInline 000002 02 17 114 mov a,#02; some comments 115 ; ../test.c: 7: __asm__("mov a,#03"); 116 ; genInline 000004 03 17 117 mov a,#03 118 ; ../test.c: 8: __asm__("mov __pa,a"); 119 ; genInline 000006 D0 05 120 mov __pa,a 121 ; genLabel 122 ; peephole j0 removed unused label 00101$. 123 ; ../test.c: 9: } 124 ; genEndFunction 000008 3A 00 125 ret
Expected to be removed all loads before line "117 mov a,#03".
--peep-asm is rarely used, and unfortunately tends to not work as well as one would hope (for most ports). AFAIK, it hasn't been a priority in the past, though patches are of course welcome (as long as they don't break anything else).
P.S.: In particular, I think the interaction between inline asm and notUsed could be improved.
Last edit: Philipp Klaus Krause 2021-10-22
I hope that there is not hidden bug as per sensitivity to space position.
Following two lines have different effects:
From my experiments on the mos6502 port it seems the peephole has trouble matching any line with comments.
the issue is in SDCCpeeph.c at the end of matchLine()
to match
"mov a,#00 ;"
the trailing spaces eater should also discard comments before checking if it is a match.
something like this before checking for the last match should do the trick.
correctly matching
"mov a,#01; "
is harder as the parser uses only ISCHARSPACE() and comma to separate the tokens. so the ; becomes part of the third token #01; instead of #01
Last edit: Gabriele Gorla 2022-01-19
Thanks! Nice catch!
issue should be fixed with [r12908]
I see that it works for case:
__asm__("mov a,#00 ;");
Still following case is not handled:
__asm__("mov a,#02; some comments");
Last edit: Maarten Brock 2022-03-07
I think I found the issue in bindVar (should be fixed starting with [r13003]
The testcase provided now works as expected.
Does this work now?
Alternatively we could rewrite output assembly like we do for labels.
Iām not sure if the size counting functions can handle lines that end with comments.
As per my tests I do not see issues anymore.
IMHO fixed