SIMD loop doesn't vectorize when referencing private variable outside the loop

Reference Number : DPD200160783

Version : 12.0

Product : Intel® C++ Compiler 12.0 for Windows*

Operating System : All versions of Windows* Operating Systems

Problem Description : When referencing a variable with simd "private" attribute, and local to a function outside a simd for-loop inside the function, the compiler will not vectorize the simd loop.  Referencing the variable includes assigning its value to another variable or trying to print the value of the private variable.  Either of the above conditions will prevent simd vectorization of the loop:

void foo(int *A, int *restrict B, int n){
  int i;
  int x = 10;

#pragma simd private(x) 
  for (i=0; i<n; i++){
    if (A[i] > 0) {
      x = 20;
    B[i] = x;
#ifdef REF
   B[i] = x;

// simd loop vectorizes when "x" is not referenced
>icl -c -Qvec-report2 test.cpp /Qrestrict
Intel® C++ Compiler for applications running on Intel® 64, Version Build 20100721

D:\NOBACKUP\quadtests\kbarticles\simPrivateBug\test.cpp(6) (col. 3): remark: SIM

// simd loop does not vectorize when "x" is referenced outside the loop
>icl -c -Qvec-report2 test.cpp /Qrestrict /DREF
Intel® C++ Compiler for applications running on Intel® 64, Version Build 20100721

test.cpp(8) (col. 7): remark: loop was not vectorized: conditional assignment to a scalar.
test.cpp(6) (col. 3): warning #13379: loop was not vectorized with "simd"

Resolution Status : This issue has been resolved in Intel® C++ Compilers 12.1 Build 20110811 and higher, and 13.0.
>icl -Qrestrict -Qvec-report2 simdprivatebug2.cpp /DREF
Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version Build 20120731
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.
test.cpp(30): (col. 3) remark: LOOP WAS VECTORIZED.
test.cpp(34): (col. 3) remark: SIMD LOOP WAS VECTORIZED.
test.cpp(35): (col. 5) remark: loop was not vectorized: exist
ence of vector dependence.
test.cpp(16): (col. 3) remark: SIMD LOOP WAS VECTORIZED.

[DISCLAIMER: The information on this web site is intended for hardware system manufacturers and software developers. Intel does not warrant the accuracy, completeness or utility of any information on this site. Intel may make changes to the information or the site at any time without notice. Intel makes no commitment to update the information at this site. ALL INFORMATION PROVIDED ON THIS WEBSITE IS PROVIDED "as is" without any express, implied, or statutory warranty of any kind including but not limited to warranties of merchantability, non-infringement of intellectual property, or fitness for any particular purpose. Independent companies manufacture the third-party products that are mentioned on this site. Intel is not responsible for the quality or performance of third-party products and makes no representation or warranty regarding such products. The third-party supplier remains solely responsible for the design, manufacture, sale and functionality of its products. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. *Other names and brands may be claimed as the property of others.]
For more complete information about compiler optimizations, see our Optimization Notice.