<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 - unnecessary andl for %cl when shifting"
href="https://bugs.llvm.org/show_bug.cgi?id=36721">36721</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>unnecessary andl for %cl when shifting
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>6.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>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>nruslan_devel@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Noticed that depending on the type specified as a shift parameter, llvm may
generate unnecessary 'and' instruction. Note: shifting instructions in
x86-64/x86 should ignore upper bits of the CX register (i.e., the value is
implicitly masked). This seems to be handled by clang/llvm when 1-byte type is
used, but when 'unsigned int' is used, it still masks the value for some
reason.
For example,
1.
__uint128_t func(__uint128_t a, unsigned char shift)
{
return a << (shift & 63);
}
generates a code without extra 'and'
func: # @func
.cfi_startproc
# %bb.0:
movl %edx, %ecx
shldq %cl, %rdi, %rsi
# kill: def %cl killed %cl killed %ecx
shlq %cl, %rdi
movq %rdi, %rax
movq %rsi, %rdx
retq
2. whereas
__uint128_t func(__uint128_t a, unsigned int shift)
{
return a << (shift & 63);
}
generates (notice extra 'andl $63, %ecx'):
func: # @func
.cfi_startproc
# %bb.0:
movl %edx, %ecx
andl $63, %ecx
shldq %cl, %rdi, %rsi
# kill: def %cl killed %cl killed %ecx
shlq %cl, %rdi
movq %rdi, %rax
movq %rsi, %rdx
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>