https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71344

            Bug ID: 71344
           Summary: [RL78] Really bad register allocation/utilization
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
  Target Milestone: ---
            Target: rl78-*-*

Compiling the following code for -mcpu=g10 -O2

char* test_00 (char* p)
{
  int r = 0;
  r |= p[0];
  r |= p[1];
  r |= p[2];
  r |= p[-1];
  p[3] = r;
  return p + 3;
}

results in:

__Z7test_00Pc:
        movw    ax, [sp+4]
        movw    r8, ax
        movw    de, ax
        movw    hl, ax
        mov     a, [de]
        or      a, [hl+1]
        mov     r10, a
        movw    hl, r8
        mov     a, [hl+2]
        or      a, r10
        mov     r10, a
        movw    bc, r8
        movw    ax, r8
        decw    ax
        movw    hl, ax
        mov     a, [hl]
        or      a, r10
        mov     3[bc], a
        movw    ax, r8
        addw    ax, #3
        movw    r8, ax
        ret                    (total 39 bytes)


I think the minimal version would be:
        movw    ax,[sp+4]
        movw    hl,ax
        mov     a,[hl]
        or      a,[hl+1]
        or      a,[hl+2]
        decw    hl
        or      a,[hl]
        mov     [hl+4],a
        movw    ax,#3
        addw    ax,hl
        movw    r8,ax
        ret                    (total 19 bytes)

Reply via email to