[clang] [flang] [flang] add -floop-interchange and enable it with opt levels (PR #140182)
Ryotaro Kasuga via cfe-commits
cfe-commits at lists.llvm.org
Mon May 26 05:30:21 PDT 2025
kasuga-fj wrote:
There is still a correctness issue with LoopInterchange, as I reported in #140238. This problem is not specific to C/C++. The following code demonstrates a case where illegal loop-interchange occurs.
```fortran
program main
implicit none
real, save :: A(5, 5)
real, target :: V(16), W(16)
real, pointer :: X(:, :) => null(), Y(:, :) => null()
integer :: i, j
do i = 0, 15
A(i / 4 + 1, mod(i, 4) + 1) = real(i)
V(i + 1) = real(i + i)
W(i + 1) = real(i * i)
end do
X(1:4, 1:4) => V(:)
if (A(2, 2) < A(3, 3)) then
Y(1:4, 1:4) => V(:)
else
Y(1:4, 1:4) => W(:)
endif
! Illegal interchange occurs
do j = 1, 4
do i = 1, 4
X(i, j) = Y(j, i)
A(i + 1, j) = A(i, j) + 1
end do
end do
print *, X
end program main
```
godbolt: https://godbolt.org/z/db5qaab1T
This issue should be resolved by #140709.
https://github.com/llvm/llvm-project/pull/140182
More information about the cfe-commits
mailing list