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

            Bug ID: 96770
           Summary: -mpure-code produces suboptimal code for relocations
                    with small offset for thumb-1
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: clyon at gcc dot gnu.org
  Target Milestone: ---

As discussed in PR94538, -mpure-code produces suboptimal code for relocations
with small offset for thumb-1.

int arr[10];
int *f4 (void) { return &arr[1]; }

Compiled with -O2 -mpure-code,
-mcpu=cortex-m0:
f4:
        movs    r3, #:upper8_15:#.LC0
        lsls    r3, #8
        adds    r3, #:upper0_7:#.LC0
        lsls    r3, #8
        adds    r3, #:lower8_15:#.LC0
        lsls    r3, #8
        adds    r3, #:lower0_7:#.LC0
        @ sp needed
        ldr     r0, [r3]
        adds    r0, r0, #4
        bx      lr

We should avoid the extra load from the literal pool (related to PR96767), and
the 'adds r0,r0,4'.

-mcpu=cortex-m23:
f4:
        movw    r0, #:lower16:.LANCHOR0
        @ sp needed
        movt    r0, #:upper16:.LANCHOR0
        adds    r0, r0, #4
        bx      lr

For reference, -mcpu=cortex-m3 produces:
f4:
        movw    r0, #:lower16:.LANCHOR0+4
        movt    r0, #:upper16:.LANCHOR0+4
        bx      lr

We should generate the same code for cortex-m23.

Reply via email to