avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[2]: [avr-gcc-list] Optimization bug in AVRGCC 3.3 compiler


From: Alexei Semenov
Subject: Re[2]: [avr-gcc-list] Optimization bug in AVRGCC 3.3 compiler
Date: Sun, 6 Apr 2003 20:35:26 +0400

Hello Marek,

Sunday, April 6, 2003, 3:58:43 AM, you wrote:

MM> On Fri, Apr 04, 2003 at 10:25:44PM +0400, Alexei Semenov wrote:
>> Following C code produces inapplicable assembler code with
>> WinAVR-20030312:
>> 
>> #include <avr/io.h>
>> 
>> int main(void)
>> {
>>    unsigned char v= 0;
>>    for(;;)
>>    {
>>       if ((PIND ^ v) & 1) // do wrong compiling
>>       {
>>           v= ~v;
>>           PORTB= v;
>>       }
>>    }
>> }
MM> Thanks.  Looks like PORTB write optimized away as if there was no
MM> "volatile".  I couldn't reproduce this with avr-gcc 3.3 20030405
MM> from CVS.  So, the bug should be gone with a new WinAVR release...
MM> Marek

I suppose the wrong compiling is effect of porting avr-gcc to win32.

Further to the theme i have tested out same C code with little variations.
Next three variants demonstrate behavior of WinAVR-20030312.
Early portings of avr-gcc 3.xx have the same bug.

1)
int main(void) {
   unsigned char v= 0;
   for(;;)
      if ((PIND ^ v) & 1) // do wrong compiling
         v= ~v;
}
produces next erroneous assembler code:
        ...
.L6:
        in r24,48-0x20
        rjmp .L6
        ...
2)
int main(void) {
   signed char v= 0;    // signed instead of unsigned
   for(;;)
      if ((PIND ^ v) & 1) // do correct compiling
         v= ~v;
}
produces next correct but redundant assembler code:
        ...
        ldi r20,lo8(0)
.L6:
        in r24,48-0x20
        clr r25
        mov r18,r20
        clr r19
        sbrc r18,7
        com r19
        eor r24,r18
        eor r25,r19
        sbrs r24,0
        rjmp .L6
        com r20
        rjmp .L6
        ...
3)
int main(void) {
   unsigned char v= 0,t;     // unnecessary variable t
   for(;;)
      if (t= (PIND ^ v) & 1) // do correct compiling
         v= ~v;
}
produces next correct assembler code:
        ...
        ldi r25,lo8(0)
.L6:
        in r24,48-0x20
        eor r24,r25
        sbrs r24,0
        rjmp .L6
        com r25
        rjmp .L6
        ...

-- 
Best regards,
 Alexei                            mailto: address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]