<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - x86: uint8_t % and / doesn't take advantage of the results already being in the same register"
href="https://llvm.org/bugs/show_bug.cgi?id=27921">27921</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>x86: uint8_t % and / doesn't take advantage of the results already being in the same register
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</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>peter@cordes.ca
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>clang3.8 compiles (<a href="https://godbolt.org/g/558Tg6">https://godbolt.org/g/558Tg6</a>) this with -O3, for amd64:
__attribute__((always_inline))
unsigned cvt_to_2digit(uint8_t i, uint8_t base) {
return ((i / base) | (uint32_t)(i % base)<<8);
}
movzbl %dil, %eax
divb %sil
# should just return here, result is already in ax, with the upper
bytes of eax zeroed
movzbl %ah, %ecx # NOREX
movzbl %al, %eax
shll $8, %ecx
orl %eax, %ecx
movl %ecx, %eax
gcc compiles to just movzx/div/movzx/ret.
See the godbolt link for related functions that compile similarly (including
one with a union where gcc which gets gcc to make bad code like this, too).</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>