https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77353

            Bug ID: 77353
           Summary: [AVR] uint16_t instead uint8_t comparison
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bseifert at gmx dot at
  Target Milestone: ---

Consider the following code:

if (PINA < static_cast<uint8_t>(32))
{
   PORTB = 0;
}

It compiles to - as expected:

 6dc:   80 b1           in      r24, 0x00       ; 0
 6de:   80 32           cpi     r24, 0x20       ; 32
 6e0:   08 f4           brcc    .+2             ; 0x6e4 <main+0x8>
 6e2:   15 b8           out     0x05, r1        ; 5

In GCC 6.2.0 a uint16_t instead of sufficient uint8_t comparison is performed -
high byte set to 0:

 6d8:   80 b1           in      r24, 0x00       ; 0
 6da:   90 e0           ldi     r25, 0x00       ; 0
 6dc:   80 97           sbiw    r24, 0x20       ; 32
 6de:   0c f4           brge    .+2             ; 0x6e2 <main+0xa>
 6e0:   15 b8           out     0x05, r1        ; 5

Once I also got the following compilation in GCC 6.2.0 with similar code
snippet:

   0:   28 2f           mov     r18, r24
   2:   30 e0           ldi     r19, 0x00       ; 0
   4:   20 32           cpi     r18, 0x20       ; 32
   6:   31 05           cpc     r19, r1
   8:   04 f0           brlt    .+0             ; 0xa <ADC::measure(unsigned
char)+0xa>

Here also a uint16_t instead of uint8_t comparison is performed and the even
less performant cpi/cpc instructions are used instead of sbiw.

Reply via email to