<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 - Factorial function gets over-vectorized and slower with -O2"
href="https://bugs.llvm.org/show_bug.cgi?id=36918">36918</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Factorial function gets over-vectorized and slower with -O2
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>naslundx@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Consider a simple factorial function with tail recursion:
```
int factorial(int n)
{
if (n <= 0) return 1;
return n * factorial(n - 1);
}
```
Compiling with -O2 on clang++ produces a lot of code compared to -O1, -Os, or
any of these flags on gcc. This holds for at least versions 3.8 and onwards.
A comparison can be found here: <a href="https://godbolt.org/g/fbztqo">https://godbolt.org/g/fbztqo</a>
Basic performance tests on Ubuntu 16.04 (core i7-6700 CPU) also shows the
non-super-vectorized version is considerably slower, at least for all values
that don't lead to overflow. The clang binary is also slightly larger.
I would expect clang to not attempt this "optimization".
Note: Using -Os gives a result almost identical to gcc with -O2.</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>