[Bug fortran/18857] MATMUL failing with ALLOCATED matrices, unless base indices given
--- Additional Comments From paulthomas2 at wanadoo dot fr 2005-04-26 12:53 --- Tobi, The component base is almost completely redundant - especially, where C indices are used, such as in matmul. It can always be calculated from the bounds and the stride, in any case. Most of the operations where speed is of the essence will do the indexing in the same way as matmul. I think that I would be inclined to do away with it. As to changing the range of the second index: it works fine with the insertions removed. Paul T -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857
[Bug fortran/18857] MATMUL failing with ALLOCATED matrices, unless base indices given
--- Additional Comments From tobi at gcc dot gnu dot org 2005-04-25 14:13 --- (In reply to comment #3) The question remains: What to do with the offset field? Fix it in the front end for static arrays, or remove it altogether? The offset field is used for something like this: REAL, POINTER :: a(:), c(:) REAL, TARGET :: b(25) a = b(5:) c = a(3:) end I'm not sure this could be done without it, especially in the multi-dimensional case. -- What|Removed |Added CC||tobi at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857
[Bug fortran/18857] MATMUL failing with ALLOCATED matrices, unless base indices given
--- Additional Comments From paulthomas2 at wanadoo dot fr 2005-04-25 15:35 --- Subject: Re: MATMUL failing with ALLOCATED matrices, unless base indices given The question remains: What to do with the offset field? Fix it in the front end for static arrays, or remove it altogether? The offset field is used for something like this: REAL, POINTER :: a(:), c(:) REAL, TARGET :: b(25) a = b(5:) c = a(3:) end Nonetheless, matmul is the only case where this assertion is imposed in the m4 functions. It doesn't do anything, except assert the pathological case. I was going to consider all the variants tonight, including your example. Your message has spurred me on. Paul -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857
[Bug fortran/18857] MATMUL failing with ALLOCATED matrices, unless base indices given
--- Additional Comments From paulthomas2 at wanadoo dot fr 2005-04-25 20:31 --- Subject: Re: MATMUL failing with ALLOCATED matrices, unless base indices given Tobi, Does this do it for you? - it works with those assertions eliminated. !{ dg-do run } ! Test MATMUL for various kinds of array. ! provided by Paul Thomas - [EMAIL PROTECTED] Program test_matmul integer, parameter:: N = 5 integer, parameter:: T = 4 real(kind=T), dimension(:,:), allocatable, Target :: a, b, c real(kind=T), dimension(:,:), POINTER :: d, e real(kind=T), dimension(N,N) :: x, y, z allocate (a(2*N, N), b(N, N), c(2*N, N)) a = 1.0_T a(1:N,:) = 2.0_T b = 4.0_T x = 1.0_T y = 2.0_T z = 0.0_T z = matmul (x, y) if (sum (z) /= 250.0_T) call abort () c = 0.0_T c = matmul (a, b) if (sum (c) /= 1500.0_T) call abort () c = 0.0_T d = a(1 : N, 1:N) c = matmul (d, b) if (sum (c) /= 1000.0_T) call abort () c = 0.0_T d = a(N+1 : 2*N, 1:N) c = matmul (d, b) if (sum (c) /= 500.0_T) call abort () c = 0.0_T e = c(N+1 : 2*N, 1 : N) e = matmul (d, b) if (sum (c(1 : N, 1 : N)) /= 0.0_T) call abort () if (sum (c(N+1 : 2*N, 1 : N)) /= 500.0_T) call abort () call doitagain (a ,b ,c ,x ,y ,z ) deallocate (a, b, c) contains subroutine doitagain (a ,b ,c ,x ,y ,z ) real(kind=T), dimension(5:, 5:):: a ,b ,c ,x ,y ,z z = 0.0_T z = matmul (x, y) if (sum (z) /= 250.0_T) call abort () c = 0.0_T c = matmul (a, b) if (sum (c) /= 1500.0_T) call abort () end subroutine doitagain end program test_matmul -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857
[Bug fortran/18857] MATMUL failing with ALLOCATED matrices, unless base indices given
--- Additional Comments From Tobias dot Schlueter at physik dot uni-muenchen dot de 2005-04-25 20:47 --- Subject: Re: MATMUL failing with ALLOCATED matrices, unless base indices given paulthomas2 at wanadoo dot fr wrote: Does this do it for you? - it works with those assertions eliminated. It doesn't work for me, a.out: ../../../gcc-clean/libgfortran/generated/matmul_r4.c:161: matmul_r4: Assertion `a-base == 0' failed. Aborted but I'm not sure if understood your question. I'm kinda surprised it works with the assertions removed, as I don't see anything in the implementation which deals with a-base != 0. Does it also work if you change the lower bound in the second dimension in one of the pointer assignments? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857
[Bug fortran/18857] MATMUL failing with ALLOCATED matrices, unless base indices given
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-19 18:51 --- descriptor.offset (in the front end) aka descriptor-base in the library is currently useless. Look at this: $ cat offset.f90 program main real :: a(2,2) real, allocatable :: b(:,:) real, pointer :: c(:,:) call foo(a) allocate(b(2,2),c(2,2)) call foo(b) call foo(c) contains subroutine foo(a) real, dimension(:,:) :: a a(1,1) = 1.0 end subroutine foo end program main $ gfortran -fdump-tree-original offset.f90 From the .original file: foo (a) { int4 ubound.0; int4 stride.1; int4 ubound.2; int4 stride.3; int4 offset.4; real4[0:] * a.0; { int4 D.484; D.484 = a-dim[0].stride; stride.1 = D.484 == 0 ? 1 : D.484; a.0 = (real4[0:] *) a-data; ubound.0 = a-dim[0].ubound - a-dim[0].lbound + 1; stride.3 = a-dim[1].stride; ubound.2 = a-dim[1].ubound - a-dim[1].lbound + 1; offset.4 = -stride.1 - NON_LVALUE_EXPR stride.3; } (*a.0)[NON_LVALUE_EXPR stride.1 + NON_LVALUE_EXPR stride.3 + offset.4] = 1.0e+0; } You can see that offset.4 is calculated without a reference to a-offset. This is a good thing, because the offset is only calculated correctly for static arrays: MAIN__ () { struct array2_real4 c; real4 a[4]; struct array2_real4 b; static void foo (struct array2_real4 ); c.data = 0B; b.data = 0B; { struct array2_real4 parm.5; parm.5.dtype = 282; parm.5.dim[0].lbound = 1; parm.5.dim[0].ubound = 2; parm.5.dim[0].stride = 1; parm.5.dim[1].lbound = 1; parm.5.dim[1].ubound = 2; parm.5.dim[1].stride = 2; parm.5.data = (real4[0:] *) (real4[0:] *) a[0]; parm.5.offset = 0; ^^ This is wrong. foo (parm.5); } For allocated and pointer arrays, this is done correctly: { real4[0:] * * D.504; b.dtype = 282; b.dim[0].lbound = 1; b.dim[0].ubound = 2; b.dim[0].stride = 1; b.dim[1].lbound = 1; b.dim[1].ubound = 2; b.dim[1].stride = 2; D.504 = b.data; _gfortran_allocate (D.504, 16, 0); b.offset = -3; ^^^ correct } { real4[0:] * * D.505; c.dtype = 282; c.dim[0].lbound = 1; c.dim[0].ubound = 2; c.dim[0].stride = 1; c.dim[1].lbound = 1; c.dim[1].ubound = 2; c.dim[1].stride = 2; D.505 = c.data; _gfortran_allocate (D.505, 16, 0); c.offset = -3; ^^ correct } foo (b); foo (c); The assert is therefore false and should be removed. The question remains: What to do with the offset field? Fix it in the front end for static arrays, or remove it altogether? -- What|Removed |Added CC||Thomas dot Koenig at online ||dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18857