[Bug target/52049] New: SH Target: Inefficient constant address access

oleg.endo@t-online.de gcc-bugzilla@gcc.gnu.org
Sun Jan 29 22:45:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52049

             Bug #: 52049
           Summary: SH Target: Inefficient constant address access
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: oleg.endo@t-online.de
                CC: kkojima@gcc.gnu.org
            Target: sh*-*-*


static volatile int* const g_0 = (volatile int*)0x1240;
static volatile int* const g_1 = (volatile int*)0x1244;
static volatile int* const g_2 = (volatile int*)0x1248;
static volatile int* const g_3 = (volatile int*)0x124C;

int test_24 (void)
{
  return *g_0 + *g_1 + *g_2 + *g_3;
}

Compiled with -O1:
    mov.w    .L31,r1
    mov.l    @r1+,r0
    mov.l    @r1+,r3
    mov.l    @r1+,r2
    mov.l    @r1,r1
    add    r3,r0
    add    r2,r0
    rts    
    add    r1,r0
    .align 1
.L31:
    .short    4672

Compiled with -O2, -Os, -O3:
    mov.w    .L31,r1
    mov.l    @r1,r0
    mov.l    @(4,r1),r3
    mov.l    @(8,r1),r2
    add    #12,r1      ! why not mov.l @(12,r1),r1 ??
    mov.l    @r1,r1
    add    r3,r0
    add    r2,r0
    rts    
    add    r1,r0
    .align 1
.L31:
    .short    4672

This happens always for the last memory access, if the number of contiguous
accesses is > 2.


When using non-volatile variables:

static int* const h_0 = (int*)0x1240;
static int* const h_1 = (int*)0x1244;
static int* const h_2 = (int*)0x1248;
static int* const h_3 = (int*)0x124C;

int test_25 (void)
{
  return *h_0 + *h_1 + *h_2 + *h_3;
}

Compiled with -O1,-O2,-Os,-O3:
    mov.w    .L33,r1
    mov.l    @r1+,r0
    mov.l    @r1,r1
    add    r1,r0
    mov.w    .L34,r1
    mov.l    @r1,r1
    add    r1,r0
    mov.w    .L35,r1
    mov.l    @r1,r1
    rts    
    add    r1,r0
    .align 1
.L33:
    .short    4672
.L34:
    .short    4680
.L35:
    .short    4684

Better:
    mov.w    .L31,r1
    mov.l    @r1+,r0
    mov.l    @r1+,r3
    mov.l    @r1+,r2
    add    r3,r0
    mov.l    @r1,r1
    add    r2,r0
    rts    
    add    r1,r0
    .align 1
.L31:
    .short    4672

I'm not sure whether this is actually a problem of the SH back-end or of some
middle-end passes.  It happens for all sub-targets and regardless of the
endianess.

Using built-in specs.
COLLECT_GCC=sh-elf-gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/sh-elf/4.7.0/lto-wrapper
Target: sh-elf
Configured with: ../gcc-trunk/configure --target=sh-elf --prefix=/usr/local
--enable-languages=c,c++ --enable-multilib --disable-libssp --disable-nls
--disable-werror --enable-lto --with-newlib --with-gnu-as --with-gnu-ld
--with-system-zlib
Thread model: single
gcc version 4.7.0 20120129 (experimental) (GCC)



More information about the Gcc-bugs mailing list