#792 Waste mov in GenCast

closed
nobody
None
5
2004-07-25
2004-07-21
Anonymous
No

SDCC codegeneration error:

Source:
#include <8051.h>

static unsigned int work1;

void test(unsigned char arg1, unsigned char arg2)
{
register unsigned int tmp1;
//Waste mov in typecasting!
tmp1=arg1 << 8;
tmp1|=arg2;
work1=tmp1;
}

void main(void)
{
test(7,3);
}

SDCC run command:

sdcc --verbose --model-small --peep-asm -mmcs51 --
iram-size 256
--xram-size 0 --code-size 12288 --nojtbound test.c

SDCC version:

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51
/ds400/hc08 2.4.2 (Jul 16 2004) (MINGW32)

Asm list:
306 ;------------------------------
------------------------------
307 ;Allocation info for local
variables in function 'test'
308 ;------------------------------
------------------------------
309 ;arg2 Allocated
with name '_test_PARM_2'
310 ;arg1 Allocated
to registers r2
311 ;tmp1 Allocated
to registers r2 r3
312 ;------------------------------
------------------------------
313 ;test.c:5: void test(unsigned
char arg1, unsigned char arg2)
314 ; ---------------------------
--------------
315 ; function test
316 ; ---------------------------
--------------
0031 317 _test:
0002 318 ar2 = 0x02
0003 319 ar3 = 0x03
0004 320 ar4 = 0x04
0005 321 ar5 = 0x05
0006 322 ar6 = 0x06
0007 323 ar7 = 0x07
0000 324 ar0 = 0x00
0001 325 ar1 = 0x01
326 ; genReceive
0031 AA 82 327 mov r2,dpl
328 ;test.c:9: tmp1=arg1 << 8;
329 ; genCast
-------------------------------------------------------
---
0033 7B 00 330 mov r3,#0x00
Waste mov!
-------------------------------------------------------
---
331 ; genLeftShift
332 ; genLeftShiftLiteral
333 ; genlshTwo
-------------------------------------------------------
---
0035 8A 03 334 mov ar3,r2
0037 7A 00 335 mov r2,#0x00
-------------------------------------------------------
---
336 ;test.c:10: tmp1|=arg2;
337 ; genCast
0039 AC*00 338 mov
r4,_test_PARM_2
003B 7D 00 339 mov r5,#0x00
340 ; genOr
003D EC 341 mov a,r4
003E 4A 342 orl a,r2
003F F5*00 343 mov _work1,a
0041 ED 344 mov a,r5
0042 4B 345 orl a,r3
0043 F5*01 346 mov (_work1
+ 1),a
347 ;test.c:11: work1=tmp1;
0045 348 00101$:
0045 22 349 ret

I'm fix this bug by peephole rule:
replace {
mov %1,%2
mov a%1,%3
} by {
; peephole r.1
mov a%1,%3
}

Discussion

  • Frieder Ferlemann

    Logged In: YES
    user_id=589052

    added contributed fix for "bug" #995347 as peephole 177.e.
    Thanks to anonymous!

     
  • Frieder Ferlemann

    • status: open --> closed
     
  • Maarten Brock

    Maarten Brock - 2004-07-26

    Logged In: YES
    user_id=888171

    Frieder,

    Shouldn't you check some volatileness here before throwing
    away a read instruction on %2 ?

    Maarten

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052

    Hi Maarten,

    no it should be OK. No SDCC generated symbol (save for acc)
    matches mov a%1, (unless I'm mistaken that is)

    Frieder

     
  • Maarten Brock

    Maarten Brock - 2004-07-26

    Logged In: YES
    user_id=888171

    Unfortunately that is not the instruction you throw away. It's
    mov r%1,%2 in your fix. That could very well be MOV
    Rn,direct. Any SFR will do here as %2 !

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052

    Hi Maarten,
    you're right. Please correct this for me (I won't commit
    during the week). Thanks!

     
  • Maarten Brock

    Maarten Brock - 2004-07-27

    Logged In: YES
    user_id=888171

    Was planning to, but now I've found out it's even worse. It
    fails regression tests. (libmullong for mcs51-stack-auto)

    mov r0,%2
    mov ar0,@r0

    is reduced to

    mov ar0,@r0

    No need to tell this is wrong, is there?

     
  • Frieder Ferlemann

    Logged In: YES
    user_id=589052

    No need to - please take it out!

    Doesn't seem to be my day (or my week:(
    (There might be a chance with additionally specifying
    operandsNotSame but I don't know whether this is compatible
    with notVolatile).

     
  • Maarten Brock

    Maarten Brock - 2004-07-27

    Logged In: YES
    user_id=888171

    I don't know how to combine two checks in the peephole file.

    The good news however is that checking %3 for volatile also
    returns FALSE if it's indirect addressing mode.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks