public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/65247] New: [missed optimisation] Reading a callee-saved register writes to the stack
@ 2015-02-28 8:44 adam at consulting dot net.nz
2015-02-28 9:23 ` [Bug rtl-optimization/65247] " adam at consulting dot net.nz
2015-03-02 8:56 ` rguenth at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: adam at consulting dot net.nz @ 2015-02-28 8:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65247
Bug ID: 65247
Summary: [missed optimisation] Reading a callee-saved register
writes to the stack
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: adam at consulting dot net.nz
There is no way to inform the compiler one is reading a callee-saved register
without the compiler also writing the register to the stack:
read_callee_saved_register.c:
#include <stdint.h>
uint64_t read_rbx(void) {
register uint64_t rbx asm ("rbx");
uint64_t value;
asm ("mov %[rbx], %[value]" : [value] "=r" (value) : [rbx] "r" (rbx));
return value;
}
int main(void) {
return 0;
}
The code above explicitly tells the complier that local register variable rbx
is only being read. Here is the output of gcc and clang respectively:
$ gcc-snapshot.sh -O3 read_callee_saved_register.c && objdump -d -m i386:x86-64
a.out|less
00000000004004c0 <read_rbx>:
4004c0: 48 89 d8 mov %rbx,%rax
4004c3: 53 push %rbx
4004c4: 5b pop %rbx
4004c5: c3 retq
4004c6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
4004cd: 00 00 00
$ clang-3.7 -O3 read_callee_saved_register.c && objdump -d -m i386:x86-64
a.out|less
00000000004004e0 <read_rbx>:
4004e0: 53 push %rbx
4004e1: 48 89 d8 mov %rbx,%rax
4004e4: 5b pop %rbx
4004e5: c3 retq
4004e6: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
4004ed: 00 00 00
Neither gcc nor clang should be pushing and popping rbx.
Note: gcc already trusts that rbx is merely being read since the assembly is
inserted before rbx is pushed and popped off the stack.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug rtl-optimization/65247] [missed optimisation] Reading a callee-saved register writes to the stack
2015-02-28 8:44 [Bug rtl-optimization/65247] New: [missed optimisation] Reading a callee-saved register writes to the stack adam at consulting dot net.nz
@ 2015-02-28 9:23 ` adam at consulting dot net.nz
2015-03-02 8:56 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: adam at consulting dot net.nz @ 2015-02-28 9:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65247
--- Comment #1 from Adam Warner <adam at consulting dot net.nz> ---
CLANG bug report:
<http://llvm.org/bugs/show_bug.cgi?id=22735>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug rtl-optimization/65247] [missed optimisation] Reading a callee-saved register writes to the stack
2015-02-28 8:44 [Bug rtl-optimization/65247] New: [missed optimisation] Reading a callee-saved register writes to the stack adam at consulting dot net.nz
2015-02-28 9:23 ` [Bug rtl-optimization/65247] " adam at consulting dot net.nz
@ 2015-03-02 8:56 ` rguenth at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-03-02 8:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65247
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization, ra
Target| |x86_64-*-*, i?86-*-*
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-03-02
Ever confirmed|0 |1
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Well, if you want to read %rbx as it is at the point of the asm (you don't
initialize "rbx") then simply read from it without any input or input
constraint.
Or do not use an asm at tall but just 'return rbx;'?
As of why we still push/pop %rbx, no idea. That is, confirmed with
#include <stdint.h>
uint64_t read_rbx(void) {
register uint64_t rbx asm ("rbx");
return rbx;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-02 8:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-28 8:44 [Bug rtl-optimization/65247] New: [missed optimisation] Reading a callee-saved register writes to the stack adam at consulting dot net.nz
2015-02-28 9:23 ` [Bug rtl-optimization/65247] " adam at consulting dot net.nz
2015-03-02 8:56 ` rguenth 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).