<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 - C++ "f < 0 ? -f : f" generates much worse code than fabs"
href="https://bugs.llvm.org/show_bug.cgi?id=38333">38333</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>C++ "f < 0 ? -f : f" generates much worse code than fabs
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</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>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>bratell@opera.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Example at:
<a href="https://godbolt.org/g/tcNgGG">https://godbolt.org/g/tcNgGG</a>
While optimizing code in the Chromium project, we noticed that fabs generates
much better machine code than "f < 0 ? -f : f". There might be some subtleties
around it, but I'd expect them to generate code that is very similar.
fabs and manually clearing the sign bit are both just an "and" instruction.
"f < 0 ? -f : f" results in 10 machine code instructions, including 2 "and" but
also 4 "move", 1 "cmp", 2 "xor" and 1 "or".
The emitted code is identical in -O1, -O2 and -O3. This was tested in clang
6.0. gcc seems better at this construct, but worse at fabs.</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>