User account creation filtered due to spam.

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
Keywords: missed-optimization
Depends on:
Reported: 2007-10-12 16:21 UTC by Tobias Burnus
Modified: 2007-10-12 20:17 UTC (History)
4 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


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
(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
  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

From the dump difference:

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

Full example, see:
("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 ***