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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
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._______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs