Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

ICC 17 and Auto Vectorization

piedpiper
Beginner
704 Views

Hello,

 

I have just recently begun experimenting with ICC 17 and its auto-vectorization features.   I was wondering if anyone could explain why the following code ('blah') can be auto-vectorized by ICC while ('blahblah') cannot ?  The difference being that variables a,b,c are declared on the stack in 'blahblah'.

const int numElems = 256;


void blah(double a[], double b[], double c[])
{
   int i = 0;

   // This vectorizes
   for (i = 0; i < numElems; i++)
   {
     a = b * c;
   }
}

void blahblah()
{
   double a[numElems];
   double b[numElems];
   double c[numElems];

   int i = 0;

   // This does not vectorize
   for (i = 0; i < numElems; i++)
   {
     a = b * c;
   }
}

Thanks in advance for any help.

 

 

0 Kudos
1 Solution
Judith_W_Intel
Employee
704 Views

 

What makes you think the loop was not vectorized? I see the following in the optimization report:

sptxl15-274> cat t.c

const int numElems = 256;

void blahblah()
{
   double a[numElems];
   double b[numElems];
   double c[numElems];

   int i = 0;

   // This does not vectorize
   for (i = 0; i < numElems; i++)
   {
     a = b * c;
   }

}
sptxl15-275> icc -qopt-report=5 -c t.c
icc: remark #10397: optimization reports are generated in *.optrpt files in the output location
sptxl15-276> grep "LOOP" *.optrpt | grep VECTOR
   remark #15300: LOOP WAS VECTORIZED
sptxl15-277>

Are you using any special command line switches?

Judy

View solution in original post

0 Kudos
2 Replies
Judith_W_Intel
Employee
705 Views

 

What makes you think the loop was not vectorized? I see the following in the optimization report:

sptxl15-274> cat t.c

const int numElems = 256;

void blahblah()
{
   double a[numElems];
   double b[numElems];
   double c[numElems];

   int i = 0;

   // This does not vectorize
   for (i = 0; i < numElems; i++)
   {
     a = b * c;
   }

}
sptxl15-275> icc -qopt-report=5 -c t.c
icc: remark #10397: optimization reports are generated in *.optrpt files in the output location
sptxl15-276> grep "LOOP" *.optrpt | grep VECTOR
   remark #15300: LOOP WAS VECTORIZED
sptxl15-277>

Are you using any special command line switches?

Judy

0 Kudos
piedpiper
Beginner
704 Views

Sorry for the confusion.  You're correct.   The loops are vectorized in both code samples - I confirmed on my test bench.

0 Kudos
Reply