From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28881 invoked by alias); 16 Feb 2015 21:40:54 -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 28851 invoked by uid 48); 16 Feb 2015 21:40:50 -0000 From: "NickParker at Eaton dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65082] New: Wasted cycles when using a register based varible Date: Mon, 16 Feb 2015 21:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: NickParker at Eaton 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-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter 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: 2015-02/txt/msg01835.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65082 Bug ID: 65082 Summary: Wasted cycles when using a register based varible Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: NickParker at Eaton dot com gcc version 4.8.0 20130306 (experimental) (GCC) Was just playing around and found this. When using a register based variable, the compiler misses an obvious optimisation. Notice in code below the addition does not take place 'in place' and is instead performed in scratch/temporary registers and then shifted back to "phaseAccPh". Why not just add directly to "phaseAccPh" since in this case it IS register based already. It seems that GCC "thinks" that the variable is still in SRAM or something else..... Nick. c code: --------------------------------------------------------- register uint16_t phaseAccPh asm ("r4"); uint16_t phaseAccFr; phaseAccPh += phaseAccFr; asm code: --------------------------------------------------------- 40:pll.c **** void pllExec(void) 41:pll.c **** { 15 .loc 1 41 0 16 .cfi_startproc 17 /* prologue: function */ 18 /* frame size = 0 */ 19 /* stack size = 0 */ 20 .L__stack_usage = 0 42:pll.c **** int16_t mix_output_s2; 43:pll.c **** phaseAccPh += phaseAccFr; 21 .loc 1 43 0 22 0000 E091 0000 lds r30,phaseAccFr 23 0004 F091 0000 lds r31,phaseAccFr+1 24 0008 E40D add r30,r4 25 000a F51D adc r31,r5 26 000c 2F01 movw r4,r30