This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug inline-asm/67944] New: GCC emits unnecessary push/pop for callee-save reads.


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

            Bug ID: 67944
           Summary: GCC emits unnecessary push/pop for callee-save reads.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alex.reinking at gmail dot com
  Target Milestone: ---

When trying to return the current value of a register in a function via a local
register variable, the compiler will emit a useless push/pop instruction as in 
the following example:

C code:

    unsigned int readEBX(void) {
        register unsigned int reg asm("ebx");
        return reg;
    }

Assembly:

    readEBX():
        mov  eax, ebx
        push ebx
        pop  ebx
        ret

This same pattern occurs for all callee-save registers: ebx, esi, edi, ebp
The code is properly-optimized for: eax, ecx, edx, esp

See also my StackOverflow question: 
See also this Godbolt* result: https://goo.gl/bzgt4P

  * Try substituting different registers to compare


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]