<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 - Loads done by inlined memcmp() are not cached"
href="https://bugs.llvm.org/show_bug.cgi?id=36421">36421</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Loads done by inlined memcmp() are not cached
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dave@znu.io
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>While trying to create an optimized version of llvm::StringSwitch, I found that
loads done by inlined memcmp() are not cached in a register. What follows is
the distilled test case of my optimized llvm::StringSwitch. Also, given that
"clang -O3 -S -emit-llvm" doesn't inline @memcmp, I assume that this is a
backend problem. Please correct me if I'm wrong. Thanks!
#include <string.h>
unsigned test(const char *string, unsigned len) {
switch (len) {
case 6:
if (memcmp(string, "abcdef", 6) == 0) return 61;
if (memcmp(string, "ABCDEF", 6) == 0) return 62;
if (memcmp(string, "aBcDeF", 6) == 0) return 63;
if (memcmp(string, "AbCdEf", 6) == 0) return 64;
return 0;
default:
return 0;
}
}
Generates redundant loads:
_Z4testPKcj: # @_Z4testPKcj
.cfi_startproc
# %bb.0:
xorl %eax, %eax
cmpl $6, %esi
jne .LBB0_8
# %bb.1:
movl $1684234849, %eax # imm = 0x64636261
xorl (%rdi), %eax
movzwl 4(%rdi), %ecx
xorl $26213, %ecx # imm = 0x6665
orl %eax, %ecx
je .LBB0_2
# %bb.3:
movl $1145258561, %eax # imm = 0x44434241
xorl (%rdi), %eax
movzwl 4(%rdi), %ecx
xorl $17989, %ecx # imm = 0x4645
orl %eax, %ecx
je .LBB0_4
# %bb.5:
movl $1147355745, %eax # imm = 0x44634261
xorl (%rdi), %eax
movzwl 4(%rdi), %ecx
xorl $18021, %ecx # imm = 0x4665
orl %eax, %ecx
je .LBB0_6
# %bb.7:
movl $1682137665, %ecx # imm = 0x64436241
xorl (%rdi), %ecx
movzwl 4(%rdi), %edx
xorl $26181, %edx # imm = 0x6645
xorl %eax, %eax
orl %ecx, %edx
sete %al
shll $6, %eax
.LBB0_8:
retq
.LBB0_2:
movl $61, %eax
retq
.LBB0_4:
movl $62, %eax
retq
.LBB0_6:
movl $63, %eax
retq</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>