Diagnostic 15534: Loop was not vectorized: loop contains arithmetic if or computed goto.

ID 662811
Updated 4/4/2016
Version Latest
Public

author-image

By

Product Version: Intel® Visual Fortran Compiler XE 15.0 or a later version

Cause:

The vectorization report generated when using Visual Fortran Compiler's optimization options ( /O3 or /O2  /Qopt-report:2 ) states that loop was not vectorized since loop contains GOTO statement.

Example:

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

subroutine foo(a, b, n) 
      implicit none 
      integer, intent(in)    :: n 
      real,    intent(inout) :: a(n) 
      integer, intent(in)    :: b(n) 
      integer:: i 
        
      do 500 i=1,n 
        goto (100,200,300,400,100,200) b(i) 
100     a(i) = 1. + a(i)**4 
        go to 500  
200     a(i) = 1. + log(a(i))
        go to 500
300     a(i) = 2. * a(i) 
        go to 500
400     a(i) = 1. - sin(a(i))**2
500   continue 

end subroutine foo

$ ifort -c -xavx f15534a.f90 -qopt-report-file=stderr -qopt-report-phase=vec

Report from: Vector optimizations [vec]

Non-optimizable loops:

LOOP BEGIN at f15534a.f90(8,10)

   remark #15534: loop was not vectorized: loop contains arithmetic if or computed goto. Consider using if-then-else statement.    [ f15534a.f90(9,9) ]

LOOP END

Resolution:

Complex flow control can prevent vectorization; rewriting the code using IF statements instead of a computed GO TO will get this loop vectorized:”

subroutine foo(a, b, n) 
      implicit none 
      integer, intent(in)    :: n 
      real,    intent(inout) :: a(n) 
      integer, intent(in)    :: b(n) 
      integer:: i 
        
      do i=1,n 
        if(b(i).eq.1 .or. b(I).eq.5) a(i) = 1. + a(i)**4 
        if(b(i).eq.2 .or. b(i).eq.6) a(i) = 1. + log(a(i))
        if(b(i).eq.3)                a(i) = 2. * a(i)
        if(b(i).eq.4)                a(i) = 1. - sin(a(i))**2           
      end do 

end subroutine foo

$ ifort -c -xavx f15534b.f90 -qopt-report-file=stderr -qopt-report-phase=vec

LOOP BEGIN at f15534b.f90(8,7)

<Peeled loop for vectorization>

LOOP END

LOOP BEGIN at f15534b.f90(8,7)

   remark #15300: LOOP WAS VECTORIZED

LOOP END

LOOP BEGIN at f15534b.f90(8,7)

<Remainder loop for vectorization>

LOOP END

 

See also:

Requirements for Vectorizable Loops

Vectorization Essentials

Vectorization and Optimization Reports

Back to the list of vectorization diagnostics for Intel® Fortran