<html>
<head>
<base href="https://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 --- - simplifylibcalls should optimize various floating point rounding utilities like lround or lrintf"
href="https://llvm.org/bugs/show_bug.cgi?id=22944">22944</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>simplifylibcalls should optimize various floating point rounding utilities like lround or lrintf
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</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>Quickly rounding a floating point value towards the nearest integer in the
positive direction is hard to do portably. The obvious code of (int)(f + 0.5)
does float to double promotion before rounding to the nearest int. It also
fails on some obscure edge cases, which aren't important. C99 has a whole
family of functions such as round(), lrintf(), nearbyint(), etc that we should
optimize down to a cvttss2si instruction. Today users have to write stuff like
this to get down to a single cvttss2i:
int roundit(float f) { return _mm_cvt_ss2si(_mm_load_ss(&f)); }
This is hacky and not portable.
This transform may be tricky, since some functions like lrint are supposed to
respect the fenv rounding and error handling modes, which LLVM doesn't respect.
I think some libcalls like lround are specified to behave the same way, so if
we limit ourselves to that I'd be happy.
Alternatively, we could fix this in Clang IRgen, but I think simplifylibcalls
is more likely to be the right place.</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>