This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/67944] New: GCC emits unnecessary push/pop for callee-save reads.
- From: "alex.reinking at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 12 Oct 2015 20:48:09 +0000
- Subject: [Bug inline-asm/67944] New: GCC emits unnecessary push/pop for callee-save reads.
- Auto-submitted: auto-generated
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