<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 - Load combining is excessively fragile"
href="https://bugs.llvm.org/show_bug.cgi?id=39438">39438</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Load combining is excessively fragile
</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>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>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>luto@mit.edu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>This input:
#include <stddef.h>
#include <stdint.h>
uint16_t good_read16le(const uint8_t *src)
{
return (uint16_t)(src[0] |
((uint16_t)(src[1]) << 8));
}
size_t bad_read16le(const uint8_t *src)
{
return (uint16_t)(src[0] |
((uint16_t)(src[1]) << 8));
}
size_t unfortunate_read16le(const uint8_t *src)
{
return good_read16le(src);
}
Generates this output:
good_read16le(unsigned char const*): # @good_read16le(unsigned char const*)
movzx eax, word ptr [rdi]
ret
bad_read16le(unsigned char const*): # @bad_read16le(unsigned char const*)
movzx ecx, byte ptr [rdi]
movzx eax, byte ptr [rdi + 1]
shl rax, 8
or rax, rcx
ret
unfortunate_read16le(unsigned char const*): # @unfortunate_read16le(unsigned
char const*)
movzx ecx, byte ptr [rdi]
movzx eax, byte ptr [rdi + 1]
shl rax, 8
or rax, rcx
ret
I'm willing to accept that there's a right way to write this (good_read16le)
and a wrong way (bad_read16le), but unfortunate_read16le() demonstrates that
even the "right" way to write this is to fragile to work reliably in a
nontrivial program.
(This can easily matter in real life. x86 is bad at addressing arrays by
anything other than a native word-sized index, but, if an index is computed
using a combined load and upcast to a native word, the optimization is lost.)</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>