[Bug tree-optimization/61000] No loop interchange for inner loop along the slow index

tkoenig at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Nov 5 14:47:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61000

--- Comment #7 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
When tackling this in the front end, one problem is when
_not_ to do loop interchange.

Consider

do i=1,10
  do j=1,10
    call foo(a(i,j))
  end do
end do

where we have no idea what foo does, and if it depends on
the order it is called (unless it is pure).

Also, if you look at

program main
  integer, dimension(3,3) :: a
  integer, dimension(9) :: b
  a = reshape([(4**(i-1),i=1,9)],shape(a))
  b = [(2*4**(i-1),i=1,9)]
  k = 0
  do i=1,3
    do j=1,3
      k = k + 1
      a(i,j) = a(i,j) + b(k)
    end do
  end do
  print *,a

  a = reshape([(4**(i-1),i=1,9)],shape(a))
  k = 0
  do j=1,3
    do i=1,3
      k = k + 1
      a(i,j) = a(i,j) + b(k)
    end do
  end do
  print *,a
end program main

you see that loop reordering can introduce wrong code quite
easily.


More information about the Gcc-bugs mailing list