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