#797 sdcc optimizator bug

closed-fixed
5
2013-05-25
2004-08-11
Anonymous
No

I has found bug in SDCC:

Source:
#include <8051.h>

//&#1055;&#1088;&#1086;&#1094;&#1077;&#1076;&#1091;&#1088;&#1099; &#1089;&#1074;&#1103;&#1079;&#1080; &#1089; PC
void conout(unsigned char chr)
{
SBUF=chr;
loop:
if (TI==0) goto loop;
TI=0;
}

//&#1042;&#1099;&#1074;&#1086;&#1076; &#1089;&#1090;&#1088;&#1086;&#1082;&#1080; &#1089;&#1080;&#1084;&#1074;&#1086;&#1083;&#1086;&#1074; &#1074; UART
void string_out(code unsigned char * data adr)
{
code unsigned char * data uk;
unsigned char symb;
uk= adr;
loop:
symb=*uk;
uk++;
if (symb!=0)
{
conout(symb);
goto loop;
}
}

void main(void)
{
}

SDCC run command:
sdcc --verbose --model-small --peep-asm -mmcs51 --
iram-size 128 --xram-size 0 --code-size 4096 --
nojtbound test.c

SDCC version:
SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51
/ds400/hc08 2.4.3 #792 (Aug 10 2004) (MINGW32)

Asm list:
335 ;------------------------------
------------------------------
336 ;Allocation info for local
variables in function 'string_out'
337 ;------------------------------
------------------------------
338 ;adr Allocated
to registers r2 r3
339 ;uk Allocated
to registers r2 r3
340 ;symb Allocated
to registers r4
341 ;------------------------------
------------------------------
342 ;test.c:13: void string_out
(code unsigned char * data adr)
343 ; ---------------------------
--------------
344 ; function string_out
345 ; ---------------------------
--------------
003A 346 _string_out:
347 ; genReceive
003A AA 82 348 mov r2,dpl
003C AB 83 349 mov r3,dph
350 ;test.c:18: loop:
351 ; genAssign
003E 352 00101
$: <= Loop position
353 ;test.c:19: symb=*uk;
354 ; genPointerGet
355 ; genCodePointerGet
003E 8A 82 356 mov dpl,r2
0040 8B 83 357 mov dph,r3
0042 E4 358 clr a
0043 93 359 movc a,@a+dptr
0044 FC 360 mov
r4,a <= Assign var to
R4
0045 A3 361 inc dptr
0046 AA 82 362 mov r2,dpl
0048 AB 83 363 mov r3,dph
364 ;test.c:20: uk++;
365 ;test.c:21: if (symb!=0)
366 ; genCmpEq
004A BC 00 01 367 cjne
r4,#0x00,00108$ <= Check var
368 ; Peephole 112.b changed
ljmp to sjmp
369 ; Peephole 251.b replaced
sjmp to ret with ret
004D 22 370 ret
004E 371 00108$:
372 ;test.c:23: conout(symb);
373 ; genCall
004E 8C 82 374 mov
dpl,r4 <= Final use var
0050 C0 02 375 push ar2
0052 C0 03 376 push ar3
0054 C0 04 377 push
ar4 <= Waste Push
operation
0056 12s00r31 378 lcall _conout
0059 D0 04 379 pop
ar4 <= Waste Pop
Operation
005B D0 03 380 pop ar3
005D D0 02 381 pop ar2
382 ;test.c:24: goto loop;
383 ; Peephole 112.b changed
ljmp to sjmp
005F 80 DD 384 sjmp 00101$
0061 385 00104$:
0061 22 386 ret

In the old sdcc versions this error not exists.

With the best wishes, Ruslan. My e-mail:
Ruslan@hitechcenter.com

Discussion

  • Maarten Brock

    Maarten Brock - 2004-08-11

    Logged In: YES
    user_id=888171

    Could you please be more specific which older version you're
    referring to? Preferrably the latest that doesn't produce this
    little less efficient optimization?

     
  • Erik Petrich

    Erik Petrich - 2004-08-12
    • labels: --> Live range problems
    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Erik Petrich

    Erik Petrich - 2004-08-12
    • assigned_to: nobody --> epetrich
     
  • Erik Petrich

    Erik Petrich - 2004-08-12

    Logged In: YES
    user_id=635249

    Fixed in SDCClrange.c 1.39.

     
  • Nobody/Anonymous

    Logged In: NO

    To Maarten Brock:
    Latest version without such bug is
    SDCC :
    mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds40
    0/hc08 2.4.3 #785 (Aug 4 2004) (MINGW32)

    With the best wishes, Ruslan. My e-mail:
    Ruslan@hitechcenter.com

     

Log in to post a comment.