public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/67944] New: GCC emits unnecessary push/pop for callee-save reads.
@ 2015-10-12 20:48 alex.reinking at gmail dot com
  2015-10-12 21:39 ` [Bug inline-asm/67944] " segher at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: alex.reinking at gmail dot com @ 2015-10-12 20:48 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-13 13:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-12 20:48 [Bug inline-asm/67944] New: GCC emits unnecessary push/pop for callee-save reads alex.reinking at gmail dot com
2015-10-12 21:39 ` [Bug inline-asm/67944] " segher at gcc dot gnu.org
2015-10-12 23:34 ` alex.reinking at gmail dot com
2015-10-13 13:09 ` segher at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).