Diagnostic 15520: loop was not vectorized: loop with early exits cannot be vectorized unless it meets search loop idiom criteria

ID 662810
Updated 4/4/2016
Version Latest
Public

author-image

By

 Product Version: Intel® Fortran Compiler 15.0 and a later version 

Cause:

The vectorization report generated using Intel® Fortran Compiler's optimization and vectorization report options includes non-vectorized loop instance because of the inherent potential for an early exit from the loop.:

Windows* OS:  /O2  /Qopt-report:2  /Qopt-report-phase:vec    

Linux OS or OS X:  -O2 -qopt-report2  -qopt-report-phase=vec

Example:

An example below will generate the following  remark in optimization report:

subroutine f15520(a,b,c,n)
  implicit none
  real, intent(in ), dimension(n) :: a, b
  real, intent(out), dimension(n) :: c
  integer, intent(in)             :: n
  integer                         :: i

  do i=1,n
     if(a(i).lt.0.) exit
     c(i) = sqrt(a(i)) * b(i)
  enddo
end subroutine f15520

ifort -c /O2 /Qopt-report:2 /Qopt-report-phase:vec /Qopt-report-file:stdout f15520.f90
 
Begin optimization report for: F15520

    Report from: Vector optimizations [vec]

LOOP BEGIN at f15520.f90(8,3)
   remark #15520: loop was not vectorized: loop with early exits cannot be vectorized unless it meets search loop idiom criteria
 LOOP END

Resolution: 

A loop with two exits can only be vectorized if it is a very simple search loop. Rewriting the above example as follows will get it vectorized:

 subroutine f15520(a,b,c,n) 
  implicit none 
  real, intent(in ), dimension(n) :: a, b 
  real, intent(out), dimension(n) :: c 
  integer, intent(in)             :: n 
  integer                         :: i, j 
  
  do i=1,n 
     if(a(i).lt.0.) exit
  enddo
  
  do j=1,i-1 
     c(j) = sqrt(a(j)) * b(j) 
  enddo 

end subroutine f15520

ifort -c -qopt-report-file=stderr -qopt-report-phase=vec f15520b.f90
…
LOOP BEGIN at f15520b.f90(8,3)
   remark #15300: LOOP WAS VECTORIZED
LOOP END
…
LOOP BEGIN at f15520b.f90(12,3)
   remark #15300: LOOP WAS VECTORIZED
LOOP END

In this case, the first loop is recognized as a pure search loop (searching for the first value of a that is less than zero).

See also:

Requirements for Vectorizable Loops

Vectorization Essentials

Vectorization and Optimization Reports

Back to the list of vectorization diagnostics for Intel® Fortran