<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 - On x86-64, RAX is unnecessarily preserved when returning member of struct containing couple of floats"
href="https://bugs.llvm.org/show_bug.cgi?id=39654">39654</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>On x86-64, RAX is unnecessarily preserved when returning member of struct containing couple of floats
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows XP
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>s.hesp@oisyn.nl
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Compiler Explorer link: <a href="https://godbolt.org/z/9-TCNN">https://godbolt.org/z/9-TCNN</a>
Consider the following code:
====================
using type = float;
struct Data
{
type a, b;
};
type _a, _b;
__attribute__((noinline)) Data GetData() { return {_a, _b}; }
auto FirstMember()
{
return GetData().a;
}
====================
For FirstMember(), this will generate (with -O):
push rax
call GetData()
pop rax
ret
If you change 'type' to 'double', this will just turn into a tail call:
jmp GetData() # TAILCALL
When changing 'type' to 'double' AND returning 'b' rather than 'a', we see the
preservation of RAX again:
push rax
call GetData()
movaps xmm0, xmm1
pop rax
ret
I suspect it has to do with the rule that a function should return a pointer to
the returned struct according to the x86-64 ABI, but I don't think that applies
here as the struct is returned fully in SSE registers.
Note that it does NOT try to preserve RAX when compiling without optimizations.</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>