[llvm-bugs] [Bug 46405] New: Calling a function with the address of your own argument produces lots of unnecessary moves
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jun 19 11:59:13 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46405
Bug ID: 46405
Summary: Calling a function with the address of your own
argument produces lots of unnecessary moves
Product: new-bugs
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: josephcsible at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
Consider this code:
void g(long *);
long f(long x) {
g(&x);
return x;
}
With "-O3", it results in this assembly:
f:
pushq %rax
movq %rdi, (%rsp)
movq %rsp, %rdi
callq g
movq (%rsp), %rax
popq %rcx
retq
This does two unnecessary moves, because it wastes both the push and pop to
just update the stack pointer, and then immediately fills in the right value
afterwards.
With "-Os", it results in this assembly:
f:
pushq %rbx
subq $16, %rsp
leaq 8(%rsp), %rbx
movq %rdi, (%rbx)
movq %rbx, %rdi
callq g
movq (%rbx), %rax
addq $16, %rsp
popq %rbx
retq
This is a really big mess and is hardly any shorter than "-O0" (in fact, it'd
be longer if not for the frame pointer).
In both cases, it should produce something more like this instead:
f:
pushq %rdi
movq %rsp, %rdi
callq g
popq %rax
retq
Godbolt link: https://godbolt.org/z/aoSMqg
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200619/30b721d4/attachment.html>
More information about the llvm-bugs
mailing list