I am working on automatic vectorization using GCC. I cannot use functions or attributes due to client requirements. (I cannot get user input to support vectorization)
If the alignment information of the array that can be vectorized is unknown, GCC causes a pass for 'loop versioning'. A loop is executed when the vectorization of a vector is performed on trees. When a cycle is identified as being vectorized, and a restriction on data alignment or data dependency prevents it (since they cannot be determined at compile time), then two versions of the cycle will be created. These are vectorized and non-vectorized versions of the loop along with runtime checks for alignment or dependencies for version control.
My question is, how should we ensure alignment? If I find a loop that is vectorizable, I should not generate two versions of the loop due to lack of alignment information.
For example. Consider the code below
short a[15]; short b[15]; short c[15];
int i;
void foo()
{
for (i=0; i<15; i++)
{
a[i] = b[i] ;
}
}
(: -fdump-tree-optimized -ftree-vectorize)
<SNIP>
vector short int * vect_pa.49;
vector short int * vect_pb.42;
vector short int * vect_pa.35;
vector short int * vect_pb.30;
bb 2>:
vect_pb.30 = (vector short int *) &b;
vect_pa.35 = (vector short int *) &a;
if (((signed char) vect_pa.35 | (signed char) vect_pb.30) & 3 == 0) ;; <== (A)
goto <bb 3>;
else
goto <bb 4>;
bb 3>:
</SNIP>
'bb 3' . "bb 4" . ( "A" ). , , ( ).