public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65082] New: Wasted cycles when using a register based varible
@ 2015-02-16 21:40 NickParker at Eaton dot com
  2015-02-16 21:45 ` [Bug middle-end/65082] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: NickParker at Eaton dot com @ 2015-02-16 21:40 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-05-26  2:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-16 21:40 [Bug c/65082] New: Wasted cycles when using a register based varible NickParker at Eaton dot com
2015-02-16 21:45 ` [Bug middle-end/65082] " pinskia at gcc dot gnu.org
2015-02-20 13:41 ` gjl at gcc dot gnu.org
2015-02-22 22:17 ` NickParker at Eaton dot com
2015-02-22 22:21 ` NickParker at Eaton dot com
2023-05-26  1:35 ` pinskia at gcc dot gnu.org
2023-05-26  1:38 ` pinskia at gcc dot gnu.org
2023-05-26  2:30 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).