3 ms·
The problem with autovectorization is that there's no good tooling for it. icc at least has #pragma simd to force vectorization, but gcc and clang don't. An
by 10000truths 3y ago
The problem with autovectorization is that there's no good tooling for it. icc at least has
#pragma simd
to force vectorization, but gcc and clang don't. And there's no way to annotate a loop to say "throw a compile error if this loop fails to autovectorize". You either pray that someone else doesn't cause a silent 4x regression by adding a loop-carried dependency, or you perform some brittle hackery trying to read the output of -fopt-info-vec-missed flag and killing the build when you see a file name + line number that corresponds to a hot loop.
At that point, it just becomes easier to use SIMD intrinsics. You're still deferring to the compiler for the instruction scheduling and register allocation, but you no longer have to worry about whether the SIMD is being emitted at all.
- bick_nyers 3y agoOr you can have some automated benchmarks as part of your CI pipeline that will compare performance numbers to previous builds to know if there is a regression that ends up mattering. An added benefit is that you can use it to do PGO and potentially eek out some more performance: https://en.wikipedia.org/wiki/Profile-guided_optimization https://en.wikipedia.org/wiki/Profile-guided_optimization
- 10000truths 3y agoAutomated benchmarks are good practice, but they're not a substitute for compile-time feedback. I would much prefer the immediate results from a compiler error, over the minutes-long wait for a traditional CI pipeline to finish.
- voidbert 3y agoIt shouldn't be too hard to write a script that objdumps a list of functions and checks if SIMD instructions are used. Strap it to your build system / CI pipeline and you're good to go. Of course, it'd be better if compilers could do that natively.
- rowls66 3y agoReally surpising to me that compilers don't support a feature like this. Anybody know why?
- nonameiguess 3y agoYou can do something similar with OpenMP in GCC: https://gcc.gnu.org/onlinedocs/libgomp/Enabling-OpenMP.html https://gcc.gnu.org/onlinedocs/libgomp/Enabling-OpenMP.html