1

Given a C++ function:

double myFunction(int n)
{

double A[n];
for(int i = 0;i<n;++i)
{
A[i] = 1.0;
}
return A[2];
}

If function 'myFunction' is compiled using intel C++ compilers, then the for loop will be vectorized by the compiler for a vector register word length 'N'. However, there can be a remainder loop that exists if the number of iterations of the loop, n is NOT a multiple of N.

I have observed in the compiler optimization reports that the compiler can also vectorize the remainder loop but fail to understand how could that be possible.

How are the remainder loops vectorized by C++ compilers?

The remainder loop was not vectorized when the function above was compiled by intel compilers for SSE instruction set. However, the remainder loop was vectorized when compiled for AVX-512 instruction set.

0 Answers0