From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16920 invoked by alias); 20 Oct 2010 16:53:31 -0000 Received: (qmail 16909 invoked by uid 22791); 20 Oct 2010 16:53:29 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID,SARE_SUB_PCT_LETTER,TW_IV 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; Wed, 20 Oct 2010 16:53:25 +0000 From: "ams at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/43721] Failure to optimise (a/b) and (a%b) into single __aeabi_idivmod call X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: ams at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: CC In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 20 Oct 2010 16:53:00 -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 X-SW-Source: 2010-10/txt/msg01689.txt.bz2 Message-ID: <20101020165300.tl1xL3Z_nY_oSK_URltJb4sftOX_u4syUNzC4XrcChY@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43721 Andrew Stubbs changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ams at gcc dot gnu.org --- Comment #6 from Andrew Stubbs 2010-10-20 16:53:13 UTC --- Here's the problem: expand_divmod always prefers the straight "div" library call over the "divmod" library call, no exceptions. Yes, "divmodsi4" in a .md is indeed preferred over "divsi4", so the optimization works fine on targets that have those, but ARM doesn't, so those rules are irrelevant. ARM does not provide a separate library function for "mod", so expand_divmod does use "divmod" for mod operations, but never for div operations. The reason for the apparent opposite rules appears to be that the divmodsi4 rule can be coded to auto-detect the most optimal kind of underlying operation to use, whereas the library call is fixed, once chosen. I see two possible ways to fix this: 1. Teach CSE (or somewhere) that div and divmod library calls have some overlap. 2. Always prefer divmod, and find some other way to convert it to div, where appropriate. I don't see any way to generate the RTL with the right call, so I'm pretty sure it does have to be fixed up after the fact. Or, I could be way off. :)