Missed Obvious Vectorization
Missed Obvious Vectorizations
While looking into potential ways of improving on a related issues, I discovered that the fairly recent addition of autovectorization to GCC appears to almost not work at all for Ada.
Autovectorization was added into GCC in the early 4.X versions. It is capable of automatically generating vector based code (e.g. Altivec or SSE) for certain cases even if the programmer has not made use of any vectorization intrinsics. While this capability is still fairly new to GCC and may never reach the performance level of hand vectorized code, it is a step in the right direction and in some limited cases can provide some real advantages.
The following example code demonstrates the problem:
package compare_lang is type the_range is range 0 .. 100; type My_Array is array (the_range) of Float; a, b, c : my_array; procedure do_compare; end compare_lang; package body compare_lang is procedure do_compare is begin for JJJ in the_range loop a(jjj) := b(jjj) * c(jjj); end loop; end do_compare; end compare_lang;
When compiled with vectorization and verbose output enabled :
gcc -c -O3 -gnatp -march=pentium4 -mfpmath=sse -msse3 -ftree-vectorize -ftree-vectorizer-verbose=5 compare_lang.adb
Results in :
compare_lang.adb:5: note: not vectorized: complicated access pattern. compare_lang.adb:3: note: vectorized 0 loops in function.
This bug has been entered into the GCC database as issue Ada fails to vectorize even trivial loops.