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

            Bug ID: 64082
           Summary: virtual register elimination doing bad for local array
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiwang at gcc dot gnu.org

this ticket is seperated from 62173, for background please see there.

and given Pinski's simple testcase

void bar(int i)
{
  char A[10];
  g(A);
  f(A[i]);
}

both ARM and AArch64 are generating similar sub-optimal code.

for example, for AArch64, we are generating:

bar:
        stp     x29, x30, [sp, -48]!
        add     x29, sp, 0
        str     x19, [sp, 16]
        mov     w19, w0
        add     x0, x29, 32
        bl      g
        add     x0, x29, 48  <-------
        add     x19, x0, x19, sxtw   |  A
        ldrb    w0, [x19, -16] <----- 
        bl      f
        ldr     x19, [sp, 16]
        ldp     x29, x30, [sp], 48
        ret

code sequence A is generated from

  add     x19, virtual_stack_vars_rtx, x19, sxtw
  ldrb    w0, [x19, -16]

the elimination of virtual_stack_vars_rtx generated the extra "add     x0, x29,
48", while if the elimination pass if smart enough, then it could eliminate
above into

  add     x19, x29, x19, sxtw
  ldrb    w0, [x19, 32]

given x19 REG_DEAD after ldrb (if not may need some multi propagation).

current elimination pass in lra-elimination.c only optimize one special case
which is (virtual_reg + const_imm), we need to handle above two insns pattern.

Reply via email to