<html>
<head>
<base href="http://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 --- - unneeded stores to stack left after memcmp optimization"
href="http://llvm.org/bugs/show_bug.cgi?id=20673">20673</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>unneeded stores to stack left after memcmp optimization
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm@insonuit.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=12901" name="attach_12901" title="Reduced test case for inlined small structure comparisons">attachment 12901</a> <a href="attachment.cgi?id=12901&action=edit" title="Reduced test case for inlined small structure comparisons">[details]</a></span>
Reduced test case for inlined small structure comparisons
clang replaces a small memcmp() operation with direct comparisons, which is
great.
But in a test case reduced from our product, there are cases where temporary
stores
remain after this optimization, and occasionally the comparison is made against
an
in-memory temporary rather than a register.
In our case, this occurs when working with a small (8-byte) structure. It's
passed
in a register, so a direct register-to-register comparison is possible. But
clang
is leaving a dead store-to-memory operation after the optimization, and
sometimes
comparing against memory instead. We originally saw this with 3.4 and I
reproduced
it with trunk as of r214549 (and Apple LLVM 5.1).
I'll attach the full test file, but here's a simple example:
struct ss {
uint16_t f1;
uint8_t f2;
uint8_t f3;
uint32_t f4;
};
static inline bool
ss_equal(const struct ss a, const struct ss b)
{
return (memcmp(&a, &b, sizeof(a)) == 0);
}
struct obj {
int w;
struct ss x;
};
int equal_test(struct obj *a, struct obj *b)
{
return ss_equal(a->x, b->x);
}
This produces:
movq 4(%rdi), %rax
movq 4(%rsi), %rcx
movq %rax, -8(%rsp)
movq %rcx, -16(%rsp)
cmpq %rcx, -8(%rsp)
sete %al
movzbl %al, %eax
retq
where we would hope for
movq 4(%rdi), %rax
cmpq 4(%rsi), %rax
sete %al
movzbl %al, %eax
retq
We've used type-casting tricks to get the latter for now, but they're
non-well-defined
and we'd like to move toward using only standards-compliant, warning-free code.</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>