From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8674 invoked by alias); 18 Mar 2014 01:11:05 -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 8617 invoked by uid 48); 18 Mar 2014 01:11:00 -0000 From: "uwe at netbsd dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/60039] sh3 optimisation bug with -O2 Date: Tue, 18 Mar 2014 01:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.8.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: uwe at netbsd dot 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: Message-ID: In-Reply-To: References: 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: 2014-03/txt/msg01503.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60039 --- Comment #6 from Valeriy E. Ushakov --- As far as I can tell the actual problem is in this code: .loc 1 189 0 mov.l .L91,r0 ; ... add r12,r0 mov.l .L84,r1 jsr @r0 ; udivsi3 for 32*1024/pagesz ; ... .loc 1 189 0 bsrf r1 ; morepages call .LPCS6: mov r0,r4 ; with result of division .L91: .long __udivsi3@GOTOFF .L84: .long morepages-(.LPCS6+2) That code assumes that r1 is not clobbered, but in our case it is. So instead of calling morepages() we end up with a small branch forward. and pagepool_start is not initialized properly, causing SIGSEGV later. I don't remember how we build udivsi3 &c bits in NetBSD, we might be violating assumptions about clobbered regs. FWIW, our in-tree gcc 4.5 generates for this: mov.l .L75,r0 ; ... mov.l @(r0,r12),r2 jsr @r2 ; ... mov.l .L67,r1 mov r0,r4 bsrf r1 .LPCS6: .L75: .long __udivsi3_i4i@GOT .L67: .long morepages-(.LPCS6+2) Because, as far as I can tell, in 4.5 sh_override_options() has an extra else if (TARGET_SH2) /* ??? EXPERIMENTAL */ sh_div_strategy = SH_DIV_CALL_TABLE; clause, that is missing in 4.8 sh_option_override().