<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Calling a function with the address of your own argument produces lots of unnecessary moves"
href="https://bugs.llvm.org/show_bug.cgi?id=46405">46405</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Calling a function with the address of your own argument produces lots of unnecessary moves
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>josephcsible@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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: <a href="https://godbolt.org/z/aoSMqg">https://godbolt.org/z/aoSMqg</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>