[cfe-dev] Bug with vectorization of transcendental functions
Ian Bell
ian.h.bell at gmail.com
Sun Aug 17 06:43:08 PDT 2014
Hello all,
I am trying to optimize an inner loop in C++ in which nearly 100% of my
runtime occurs. In this loop I have to do some exponential calls, and
according to the docs at
http://llvm.org/docs/Vectorizers.html#vectorization-of-function-calls , it
seems that the exp function should be able to be vectorized using SIMD
instructions. I'm using the tippy SVN clang.
The example here shows that the floor function is getting vectorized, but
the exp function isn't. Is this is a bug or known behavior? I see the
same problem if I use floats for what its worth.
By the way, there are some problems with the auto-vectorization docs,
vectorization is only enabled at -O3, it took me an hour to try to figure
out why my -Rpass=loop-vectorize wasn't giving ANY output.
My code (loop_test2.cpp):
#include <vector>
#include <cmath>
typedef double numtype;
void foo(numtype *f) {
for (int i = 0; i != 1024; ++i)
f[i] = floor(f[i]);
}
void foo2(numtype *f) {
for (int i = 0; i != 1024; ++i)
f[i] = exp(f[i]);
}
int main()
{
std::vector<numtype> f(1024, 1.3);
foo(&f[0]);
return 0;
}
Compilation:
../../../build/Debug+Asserts/bin/clang++ -c -Rpass=loop-vectorize
-Rpass-analysis=loop-vectorize -O3 -gline-tables-only -gcolumn-info
loop_test2.cpp
which yields
loop_test2.cpp:7:8: remark: unrolled with interleaving factor 2
(vectorization
not beneficial) [-Rpass=loop-vectorize]
for (int i = 0; i != 1024; ++i)
^
loop_test2.cpp:13:12: remark: loop not vectorized: call instruction cannot
be
vectorized [-Rpass-analysis=loop-vectorize]
f[i] = exp(f[i]);
^
loop_test2.cpp:18:3: remark: vectorized loop (vectorization factor: 2,
unrolling
interleave factor: 2) [-Rpass=loop-vectorize]
std::vector<numtype> f(1024, 1.3);
^
loop_test2.cpp:8:12: remark: unrolled with interleaving factor 2
(vectorization
not beneficial) [-Rpass=loop-vectorize]
f[i] = floor(f[i]);
^
Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140817/7fea5772/attachment.html>
More information about the cfe-dev
mailing list