Help save net neutrality! Learn more.

#5 Various 8051 register alloc fixes

Wim Lewis

fixing these bugs:

Bug 1. [see partly-related bug #542397]

bit TI;
bit RI;

char bar(void)
char z = RI;
return(2*TI - z);

Causes a fatal error in ralloc, line 1474,
"createRegMask cannot find
live range". The problem is that sdcc optimizes away
the iTemp
containing 'z', and when doing this, it updates
live-range information
for RI. But RI is a global, so when the register
allocator tries to
assign registers to all live ranges, it fails.

Bug 2. Same code, except that 'TI' and 'RI' are sbit
instead of bit.

sbits are volatile, and therefore the compiler should
not optimize
out the temporary variable. Changed the optimizer to
check for volatile
symbols in this case and not mess with them.

Bug 3. [SF bug #542397]

bit RI;
bit TI;

char bar(void)
return(2*TI - RI);

Causes a fatal error in the assembler --- wrong
addressing mode is emitted.

Bug 4. [similar to long-closed SF buf #447547]

bit RI;
bit TI;

char bar(void)
return('0' + 2*TI + RI);

If bug 3 is fixed, you find that the code generated for
this is
incorrect: it does not know that fetching RI involves
clobbering the
accumulator, and tries to leave the intermediate result
in the
accumulator while fetching RI. Changed the register
(packRegsForAccUse()) to be smarter about whether the
next iCode is
going to clobber the accumulator, and changed the code
generators for
addition and subtraction to be smarter about what order
they fetch
their operands in.

It's probably necessary for someone to go through all
the other
2-operand code emitters and check whether they're
susceptible to the
same accumulator-clobbering bug.


  • Wim Lewis

    Wim Lewis - 2002-09-16

    unified diff against current CVS repository (16sep02)

  • Wim Lewis

    Wim Lewis - 2002-09-19

    Logged In: YES

    I have cvs write access now, so I'm committing this myself.

  • Wim Lewis

    Wim Lewis - 2002-09-19
    • status: open --> closed-accepted

Log in to post a comment.