This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/65082] New: Wasted cycles when using a register based varible


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]