Diagnostic 15027: loop was not vectorized: condition may protect exception

Cause:

When the compiler tries to vectorize a loop containing an IF statement, it typically evaluates the RHS expressions for all values of the loop index, but only makes the final assignment in those cases where the conditional evaluates to TRUE. In some cases, the compiler may not vectorize out of concern that the condition may be protecting against accessing an illegal memory address.


Example:

void test(int *a, int  *restrict b) {
  int i;
  b[1] = 0;

#ifdef IVDEP
#pragma ivdep
#endif  
  for (i = 0; i < 100; i++) {
    if ( a[i] == 20)
      b[1] = i;
  }
}

>icl /c /Qvec-report2 diag15027.cpp /Qrestrict
Intel® C++ Compiler for applications running on Intel® 64, Version 12.0.0.063 Build 20100721
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

diag15027.cpp
diag15027.cpp(10) (col. 7): remark: loop was not vectorized: condition may protect exception.


Resolution Status:

An IVDEP pragma may be used to reassure the compiler that the conditional is not protecting against a memory exception in such cases.  In this example after using the IVDEP pragma the loop becomes vectorizable but the compiler does not see any benefits in vectorizing the loop. 

>icl /c /Qvec-report2 diag15027.cpp /Qrestrict /DIVDEP
Intel® C++ Compiler for applications running on Intel® 64, Version 12.0.0.063 Build 20100721
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

diag15027.cpp
diag15027.cpp(8) (col. 3): remark: loop was not vectorized: vectorization possible but seems inefficient.

For more complete information about compiler optimizations, see our Optimization Notice.