From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20729 invoked by alias); 5 Dec 2013 20:19:13 -0000 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 Received: (qmail 20703 invoked by uid 48); 5 Dec 2013 20:19:09 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/59401] New: [SH] GBR addressing mode optimization produces wrong code Date: Thu, 05 Dec 2013 20:19: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-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: olegendo at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cf_gcctarget Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2013-12/txt/msg00429.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59401 Bug ID: 59401 Summary: [SH] GBR addressing mode optimization produces wrong code Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: olegendo at gcc dot gnu.org Target: sh*-*-* The GBR addressing mode optimization which was added in 4.8 is buggy. The following example: struct tcb_t { int x, y, z, w; }; int test_00 (int a, tcb_t* b) { tcb_t* tcb = (a & 5) ? (tcb_t*)__builtin_thread_pointer () : b; return tcb->w + tcb->x; } compiled with -O2 results in: mov.l @(12,gbr),r0 mov r0,r2 mov.l @(0,gbr),r0 rts add r2,r0 which is obviously wrong code. This is because sh_find_base_reg_disp in sh.c will step insns outside the current basic block without any further considerations. This is only OK to do if the predecessor basic block has a fall through edge to the current basic block (i.e. there are no labels in between). Otherwise the address reg in question might be set in multiple basic blocks which must be analyzed. In the above test case GBR addressing modes can't be used actually.