Bug 33753 - gfortran treads known-to-be-contiguous array as having strides
Summary: gfortran treads known-to-be-contiguous array as having strides
Status: RESOLVED DUPLICATE of bug 32131
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2007-10-12 16:21 UTC by Tobias Burnus
Modified: 2007-10-12 20:17 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-10-12 16:21:52 UTC
Assume a module with the following definitions:
(a)  real, allocatable, dimension(:) :: array
or
(b)  real, dimension(500) :: array

Both arrays are contiguous as one cannot allocate strides
  allocate(array(1:1000:2)) ! invalid
Thus: Only pointers or dummy arguments can have strides.

If one accesses the array in a loop, this can slow down the calculation considerably.

Test case:

module a
  implicit none
  real, dimension(500) :: array
!  real, allocatable, dimension(:) :: array
contains
  subroutine test(x,n)
    integer :: n, i
    real :: x(n)
!    allocate(array(1:500))
    do i = 1, n
      x(i) = array(i)
    end do
  end subroutine test
end module a
end

From the dump difference:

-              (*x)[(int8) i + -1] = array[(int8) i + -1];
+              (*x)[(int8) i + -1] = (*(real4[0:] *) array.data)[(int8) i * array.dim[0].stride + array.offset];

Full example, see:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/8fac8fcf6e93fba7/
("Program slowdown when calling function with dynamic arrays" by Paul Hilscher)
Comment 1 Janne Blomqvist 2007-10-12 20:17:38 UTC
Gfortran should know that stride==1 for allocatables, as was suggested by Tomas Koenig in #32131, comment 5.

*** This bug has been marked as a duplicate of 32131 ***