http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61055

            Bug ID: 61055
           Summary: [avr] wrong test instruction after increment with -O1
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: konfera at efton dot sk
            Target: avr

#include <stdint.h>

extern int16_t foo(int16_t, int16_t);

int main(void) {

  int16_t x = 0;
  int16_t y = 0;  
  uint8_t c = 0x20;

  do {
    x = foo(x, y);
    y = foo(y, c);

    c++;
    if (c >= 0x80) c = 0x20;

  } while (y > 0);        

  while(1);
}


c:\tmp>avr-gcc -mmcu=avr2 -O1 -S ca.c -o ca.s
c:\tmp>avr-gcc --version
avr-gcc (AVR_8_bit_GNU_Toolchain_3.4.3_1072) 4.8.1


The sequence 

    c++;
    if (c >= 0x80) c = 0x20;

compiles into

    inc r15
    brge .L2
    set
    clr r15
    bld r15,5
.L2:

which fails when c == 0x7f, as brge does jump after the increment.

Jan Waclawek

Reply via email to