<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 - Clang unnecessarily uses rbx and pushes it and rax"
href="https://bugs.llvm.org/show_bug.cgi?id=46316">46316</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang unnecessarily uses rbx and pushes it and rax
</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:
int g(int);
void h(void);
int f(int x) {
if(g(0) == -1) {
return 1;
}
h();
return 0;
}
When compiled on Clang 10.0.0 on x86-64 Linux with "-O3
-fno-omit-frame-pointer", it produces this:
f:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
xorl %ebx, %ebx
xorl %edi, %edi
callq g
cmpl $-1, %eax
je .LBB0_1
callq h
jmp .LBB0_3
.LBB0_1:
movl $1, %ebx
.LBB0_3:
movl %ebx, %eax
addq $8, %rsp
popq %rbx
popq %rbp
retq
<a href="https://godbolt.org/z/J3It3A">https://godbolt.org/z/J3It3A</a>
There's no need to mess with ebx at all, or to push anything other than rbp. It
should have produced something like this instead:
f:
pushq %rbp
movq %rsp, %rbp
xorl %edi, %edi
callq g
cmpl $-1, %eax
je .LBB0_1
callq h
xorl %eax, %eax
popq %rbp
retq
.LBB0_1:
movl $1, %eax
popq %rbp
retq
And Clang basically knows how to emit that code. In particular, if I change
"g(0)" to "g(x)", then that's exactly what I get, aside from the "xorl %edi,
%edi".</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>