<div dir="ltr"><div><div><div><div><div><div>Hello all,<br><br></div>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 <a href="http://llvm.org/docs/Vectorizers.html#vectorization-of-function-calls" target="_blank">http://llvm.org/docs/Vectorizers.html#vectorization-of-function-calls</a> , it seems that the exp function should be able to be vectorized using SIMD instructions. I'm using the tippy SVN clang. <br>
<br>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.<br><br></div><div>
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.<br></div><div>
<br></div>My code (loop_test2.cpp):<br><br>#include <vector><br>#include <cmath><br><br>typedef double numtype;<br><br>void foo(numtype *f) {<br> for (int i = 0; i != 1024; ++i)<br> f[i] = floor(f[i]);<br>
}<br><br>void foo2(numtype *f) {<br> for (int i = 0; i != 1024; ++i)<br> f[i] = exp(f[i]);<br>}<br><br>int main()<br>{<br> std::vector<numtype> f(1024, 1.3);<br> foo(&f[0]);<br> return 0;<br>}<br><br></div>
Compilation:<br>../../../build/Debug+Asserts/bin/clang++ -c -Rpass=loop-vectorize -Rpass-analysis=loop-vectorize -O3 -gline-tables-only -gcolumn-info loop_test2.cpp<br><br></div>which yields<br><br>loop_test2.cpp:7:8: remark: unrolled with interleaving factor 2 (vectorization<br>
not beneficial) [-Rpass=loop-vectorize]<br> for (int i = 0; i != 1024; ++i)<br> ^<br>loop_test2.cpp:13:12: remark: loop not vectorized: call instruction cannot be<br> vectorized [-Rpass-analysis=loop-vectorize]<br>
f[i] = exp(f[i]);<br> ^<br>loop_test2.cpp:18:3: remark: vectorized loop (vectorization factor: 2, unrolling<br> interleave factor: 2) [-Rpass=loop-vectorize]<br> std::vector<numtype> f(1024, 1.3);<br>
^<br>loop_test2.cpp:8:12: remark: unrolled with interleaving factor 2 (vectorization<br> not beneficial) [-Rpass=loop-vectorize]<br> f[i] = floor(f[i]);<br> ^<br><br></div>Thanks,<br></div>Ian<br>
</div>