3 ms·
For a couple of days I experimented with auto-vectorization in my language which uses LLVM as its backend. In my example I had a simple function multiplying ele
by Panzerschrek 11d ago
For a couple of days I experimented with auto-vectorization in my language which uses LLVM as its backend. In my example I had a simple function multiplying elements from two arrays and writing them in the third one. And it worked as expected, I did see autovectorization in the result code. But I also noticed something strange - there were a couple of pointer difference calculations and jumps prior to the unrolled/vectorized loop. Then I realized, what this means. LLVM isn't sure that it can use autovectorization, since input and output arrays may overlap. So, it just performs a runtime overlapping check and if no overlap is detected, a vectorized version of the loop is executed, otherwise it jumps to a non-vectorized loop version.
That's why C has restrict keyword. If it's provided, LLVM is sure that no runtime overlapping check is needed and can autovecrorize, sometimes even in places where such vectorization without restrict isn't possible at all.