[llvm-bugs] [Bug 36918] New: Factorial function gets over-vectorized and slower with -O2
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Mar 27 02:28:58 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=36918
Bug ID: 36918
Summary: Factorial function gets over-vectorized and slower
with -O2
Product: clang
Version: 5.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: naslundx at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
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: https://godbolt.org/g/fbztqo
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180327/94a75fdc/attachment.html>
More information about the llvm-bugs
mailing list