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

            Bug ID: 80274
           Summary: There is an unoptimized direct memory write of 16bit
                    value on x86_64 with O2 and O3.
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zloten at mail dot ru
  Target Milestone: ---

The next code:

void foo() {
 *(unsigned short*)0xFFFF=1;
}

Compiles to:

foo():
        mov     eax, 1
        mov     WORD PTR ds:65535, ax
        ret

But must be:

foo():
        mov     WORD PTR ds:65535, 1
        ret

The bug occurs with any options at optimization levels O2, O3. But this is ok
at optimization level O.
The bug occurs since 4.8.1 version of GCC.

PS: For any other sizes (8bit, 32bit and 64bit) the output is correct:
mov     BYTE PTR ds:65535, 1     ;unsigned byte
mov     DWORD PTR ds:65535, 1    ;unsigned int
mov     QWORD PTR ds:65535, 1    ;unsigned long long int

Reply via email to