As I mentioned in another thread, I found that nsw on loop bounds could help vectorization. The language standard doesn’t mention about integer overflow of DO statement parameters, but some compilers seem to assume they never overflow. I can say so because the following loop is vectorized without loop versioning.
subroutine s115 (a,n)
integer n, i, j
real a(n)
do j = 1,n
do i = j+1, n
a(i) = a(i) + a(j)
end do
end do
end subroutine
j+1 can be less than j if j+1 overflows, so the loop should be versioned but actually not.
The following is the result of my investigation. I made parameters polynomial forms and checked whether the loop was vectorized.
| gfortran | ifort | ifx | frt (Fujitsu) |
notes | |
|---|---|---|---|---|---|
| initial parameters | vec | vec | vec | vec | Compiler Explorer |
| terminal parameters | vec | no vec | no vec | vec | Compiler Explorer |
| incrementation parameters | vec | no vec | no vec | vec | Compiler Explorer The loop was not vectorized by LLVM even if the operation has the nsw flag. |
Considering this, nsw on calculations of initial parameters would be allowed. On the other hand, it is controversial to add nsw to terminal parameters and incrementation parameters. IMHO, flang-new could also allow nsw on them because some other compilers (not all) do so.
We agreed to add nsw only to address calculations to keep transformations safe. However, the above argument violates it. Therefore, I’d like to ask for your opinions.