auto-vectorization of sin() function for fortran

I tried to use armclang to auto-vectorize sin().  But it doesn't work.  Any suggestions?

Regards,

subroutine sum(myarr1,myarr2,ub)
        real, pointer :: myarr1(:)
        integer :: ub
        
        !dir$ ivdep
        do i=1,ub
                myarr1(i) = sin(i/180.*3.1415)
        end do
end subroutine

armclang -c -O2 -mcpu=native -Rpass-missed=loop-vectorize -Rpass=loop-vectorize -S ex1_sin.f90
remark: ex1_sin.f90:6:1: loop not vectorized (Force=true) [-Rpass-missed=sve-loop-vectorize]
warning: ex1_sin.f90:6:1: loop not vectorized: failed explicitly specified loop vectorization [-Wpass-failed=sve-loop-vectorize]
remark: ex1_sin.f90:6:1: loop not vectorized (Force=true) [-Rpass-missed=loop-vectorize]
warning: ex1_sin.f90:6:1: loop not vectorized: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering [-Wpass-failed=transform-warning]
2 warnings generated.

  • Hi

    Thanks for the query,

    The best way to compile Fortran code with ACfL is to use the Fortran driver: armflang. This driver is set up to vectorize loops with math function calls automatically when vectorization is enabled at -O2 and above.

    > armflang -c -O2 -mcpu=neoverse-n1 -Rpass-missed=vectorize -Rpass=loop-vectorize -S ex1_sin.f90
    ex1_sin.f90:6: remark: vectorized loop (vectorization width: 2, interleaved count: 1) [-Rpass=loop-vectorize]
            do i=1,ub

    It is possible to coerce the armclang driver into doing this too, but using armflang is the most reliable way to compile Fortran. You should be able to set this up in your makefile/CMake.with CMAKE_Fortran_COMPILER and associated variables.

    Ta

    Rich