From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2338 invoked by alias); 29 Jan 2012 22:11:58 -0000 Received: (qmail 2325 invoked by uid 22791); 29 Jan 2012 22:11:57 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 29 Jan 2012 22:11:44 +0000 From: "oleg.endo@t-online.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/52049] New: SH Target: Inefficient constant address access Date: Sun, 29 Jan 2012 22:45:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: oleg.endo@t-online.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-01/txt/msg03441.txt.bz2 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)