• register allocation going wrong..

    From erwin.matthijssen@gmail.com@21:1/5 to All on Fri Sep 22 09:45:18 2017
    I have retargeted LCC for my own custom designed CPU. LCC actually works quite well and I have the basis of an OS running; all compiling correctly.

    Today I compiled the Dhrystone benchmark code and suddenly LCC does something very strange: it is screwing up its register allocation; overwriting values by using the same register where it shouldn't. Look at the example below:

    ldw r4,-2(bp)
    ldi r3, -84
    add r3, r3, bp
    stw r0(r3),r4

    ldw r3,-4(bp)
    ldi r3, -82
    add r3, r3, bp
    stw r0(r3),r3

    MULT16(r1,r3,r4)

    The code is setting up 2 parameters for a multiplication. In the first block it is loading a local var into R4 and then storing it somewhere using R3 (i clobber all registers when i call a pseudo op like MULT).

    However, in the second block it is loading a local var in R3, then immediately overwriting that register for the address calculation.

    The relevant code generation rules are:

    reg: ADDRLP2 "\tld16\t%c, %a\n\tadd\t%c, %c, bp\n" 2
    stmt: ASGNU2(reg,reg) "\tstw\tr0(%0),%1\n" 2
    reg: MULU2(reg,reg) "MULT16(%c,%0,%1)\n" 1

    the clobber function has this:

    case MUL+U:
    spill( (1<<R2) | (1<<R3) | (1<<R4), IREG, p);
    break;

    I don't really know where to look for a problem. The compiler has been behaving splendidly and I never had trouble with register allocations.

    Any pointers or tips greatly appreciated!
    Erwin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jacob navia@21:1/5 to All on Sat Sep 23 19:42:35 2017
    Can you send me the C source that produces this bug?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)