From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3768 invoked by alias); 20 Oct 2010 09:20:33 -0000 Received: (qmail 3759 invoked by uid 22791); 20 Oct 2010 09:20:32 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_OV,TW_VW 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 09:20:23 +0000 From: "carrot at google dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/46092] New: Improve constant handling of thumb2 instructions 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: normal X-Bugzilla-Who: carrot at google dot com 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 Date: Wed, 20 Oct 2010 09:20: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/msg01635.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46092 Summary: Improve constant handling of thumb2 instructions Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: carrot@google.com CC: carrot@google.com Host: i686-linux Target: arm-eabi Build: i686-linux Compile the following code with options -march=armv7-a -mthumb -Os unsigned long tv(unsigned long x) { if (x >= 65521) x = x - 65521; return x; } gcc generates: tv: movw r3, #65520 cmp r0, r3 ittt hi subhi r0, r0, #65024 // A subhi r0, r0, #496 // B subhi r0, r0, #1 // C bx lr Notice that (x = x - 65521) is translated into 3 instructions. Actually 65521 can be loaded into register with one instruction. So the shorter result is: tv: movw r3, #65520 cmp r0, r3 ittt hi movwhi r1, #65521 subhi r0, r1 bx lr This should be improved by function arm_gen_constant. The function is already commented with /* ??? This needs more work for thumb2. */