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

            Bug ID: 89198
           Summary: GCC generates/fails to optimize unnecessary sign
                    extension instruction
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---
            Target: x86_64

GCC generates/fails to optimize unnecessary sign extension instruction.

unsigned char foo(char c)
{
    unsigned i = c;
    return ++i;
}

Results in:
    movsx   eax, dil
    add     eax, 1
    ret

While this one:

unsigned char bar(char c)
{
    unsigned char i = c;
    return ++i;
}

Results in:
    lea     eax, [rdi+1]
    ret

https://godbolt.org/z/I54SZr

I found a lot of reports about redundant sign/zero extension instructions, did
not open them all but the ten I had opened have more complex examples.

Reply via email to