<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 - Value range knowledge of higher bits not used in optimizations"
href="https://bugs.llvm.org/show_bug.cgi?id=43431">43431</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Value range knowledge of higher bits not used in optimizations
</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>enhancement
</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>zamazan4ik@tut.by
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Consider the example:
unsigned long long sample2(unsigned long long m) {
if (m >= 100) __builtin_unreachable();
m *= 16;
return m >> 3;
}
After the `if` statement we do know that the higher bits are set to 0. So
instead of generating the following assembly:
sample2(unsigned long long):
mov rax, rdi
sal rax, 4
shr rax, 3
ret
A more optimal assembly could be generated:
sample2(unsigned long long):
lea rax, [rdi + rdi]
ret
Godbolt playground: <a href="https://godbolt.org/z/1iSpTh">https://godbolt.org/z/1iSpTh</a>
Same issues for GCC: <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91881">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91881</a>
P.S.: that optimization is important for std::to_chars(..., double) like
functions, where a significant of a double is extracted into an unsigned long
long variable, so its upper bits are always zero.</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>