4 ms·
aren’t compiler built in simd vector types practically equivalent to what the compiler would vectorise scalar code to anyway
by taminka 3y ago
aren’t compiler built in simd vector types practically equivalent to what the compiler would vectorise scalar code to anyway
- huppeldepup 3y agoIt’s been a while (10 years?) since I wrote NEON and vf code (different arch but sentiment remains) and every now and then I used to run a quick disassembly to verify that my optimisation hadn’t been undone by the compiler. The first time it happens you kinda lose faith in the compiler.
- exDM69 3y agoNo, compilers may be able to vectorize basic loops, but they won't for example turn four adjacent additions into a vector addition.
- JonChesterfield 3y agoThere's (at least) two vectorisers in LLVM. One does loops, the other acts on basic blocks. https://llvm.org/docs/Vectorizers.html#the-slp-vectorizer https://llvm.org/docs/Vectorizers.html#the-slp-vectorizer. Both really like alignment metadata on pointers. They certainly have limitations but the hit rate is reasonably good.
- astrange 3y agoNo, autovectorization is a lie and doesn't work. We're not stupid, we did it the way the article does it for a reason. The main problems preventing it from working are that the compiler doesn't have enough information about alignment (especially if it's intentionally unaligned) or aliasing. It tends to get things especially wrong when it autovectorizes code that was already partly hand vectorized; it ends up emitting the preludes (which correct for misalignment) twice. It does work better for languages like Fortran made for it - contrary to popular belief C is not actually a low level language and isn't that easy to optimize.