[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From cvs-commit at gcc dot gnu dot org 2005-04-15 20:06 --- Subject: Bug 18495 CVSROOT:/cvs/gcc Module name:gcc Changes by: [EMAIL PROTECTED] 2005-04-15 20:06:17 Modified files: libgfortran: ChangeLog libgfortran/intrinsics: spread_generic.c gcc/testsuite : ChangeLog gcc/testsuite/gfortran.fortran-torture/execute: intrinsic_spread.f90 Log message: 2005-04-15 Thomas Koenig <[EMAIL PROTECTED]> PR libfortran/18495 * intrinsics/spread_generic.c (spread): Remove const from return array descriptor. New variables: rrank (rank of return array), rs (for calculating the size of the return array), srank (rank of the source array). Generate runtime error if the dim= argument is larger than the rank of the return array. Generate runtime error if the needed rank of the return array is larger than 7. If ret->data is null, populate the return array descriptor and initialize the variables for the actual operation. Otherwise, set ret->dim[0].stride to one if it is zero. Change second, independent use of variable dim to srank. 2005-04-15 Thomas Koenig <[EMAIL PROTECTED]> PR libfortran/18495 * gfortran.fortran-torture/execute/intrinsic_spread.f90: Test callee-allocated version of return array with a write statement. Test spread with a temporary with another write statement. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.193&r2=1.194 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/intrinsics/spread_generic.c.diff?cvsroot=gcc&r1=1.6&r2=1.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5355&r2=1.5356 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_spread.f90.diff?cvsroot=gcc&r1=1.2&r2=1.3 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-15 19:39 --- Spread putting its result into temporary arrays does indeed do something strange, even if the front end is providing the space. This is with an unpatched spread_generic.c: program test_spread implicit none integer, parameter :: N = 4 integer:: I integer, dimension(N) :: source integer, dimension(N,N) :: temp, sink source = (/(i,i=1,4)/) temp = spread (source, 1, N ) sink = spread( source , 1 , N ) + 0 print *,'On the fly:' print '(1x,4I12)',sink print *,'Using temporary array:' sink = temp + 0 print '(1x,4I12)',sink end program test_spread $ gfortran t1.f90 $ ./a.out On the fly: 1 437457152 386863616 22 2 134537768 12 1075739744 3 116774548 1073850628 4 1073772283 1073853733 134513615 Using temporary array: 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-15 17:24 --- There's something rotten in the state of Denmark. I've slightly modified Paul's test program with my patch, and this is what I got: program test_spread implicit none integer, parameter :: N = 100 integer:: I integer, dimension(N) :: source integer, dimension(N,N) :: sink, check,c1,c2 source =(/(i, i=1,N)/) check = spread( source , 1 , N ) PRINT *,"first 4x4 elements with DIM=1" write(*,'(1x,4I4)') check(1:4,1:4) check = spread( source , 2 , N ) PRINT *,"first 4x4 elements with DIM=2" write(*,'(1x,4I4)') check(1:4,1:4) c1 = spread(source, 1, N) c2 = spread(source, 2, N) sink = spread( source , 1 , N ) * spread( source , 2 , N ) PRINT *,"The product using temporaries" write(*,'(1x,4I4)') sink(1:4,1:4) PRINT *,"The product using fixed arrays" sink = c1 * c2 write(*,'(1x,4I4)') sink(1:4,1:4) end program test_spread $ gfortran test_spread.f90 $ ./a.out first 4x4 elements with DIM=1 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 first 4x4 elements with DIM=2 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 The product using temporaries 100 0 0 0 200 0 0 0 300 0 0 0 400 0 0 0 The product using fixed arrays 1 2 3 4 2 4 6 8 3 6 9 12 4 8 12 16 I am not applying my patch for the moment. A segfault is better than a silently generated wrong result :-( Investigating further. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-15 11:29 --- (In reply to comment #13) > I believe that reshape needs the same/similar fix. > Is ret->data = NULL guaranteed for temporaries? ret->data = NULL is what the front end generates when it doesn't know enough about the temporary. > This is what I would have done but the question that I asked on the > original PR is still unanswered - is it the caller or the callee who > should be arranging the correct amount of memory for a temporary object? Ideally, it should be the caller, but that doesn't happen always at the moment. Thomas -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From paulthomas2 at wanadoo dot fr 2005-04-15 05:07 --- Subject: Re: Intrinisc function SPREAD is broken > > >This appears to fix the benchmark in question. > > > I believe that reshape needs the same/similar fix. Is ret->data = NULL guaranteed for temporaries? This is what I would have done but the question that I asked on the original PR is still unanswered - is it the caller or the callee who should be arranging the correct amount of memory for a temporary object? Paul T -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-14 21:49 --- Created an attachment (id=8634) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8634&action=view) Proposed fix for PR 18495. This appears to fix the benchmark in question. -- What|Removed |Added AssignedTo|unassigned at gcc dot gnu |tkoenig at gcc dot gnu dot |dot org |org Status|NEW |ASSIGNED http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From paulthomas2 at wanadoo dot fr 2005-04-13 21:27 --- Subject: Re: Intrinisc function SPREAD is broken tkoenig at gcc dot gnu dot org wrote: >--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-13 >10:01 --- >The program test_spread from the original bug report >is bogus. dim=1000 doesn't make sense (which invalidates >my comment #5 and makes this particular case a diagnostics >issue). > >Thomas > > > Thomas - I'll provide you with what you need in the morning. Paul T -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-13 19:47 --- Can anybody point me to the actual source of the benchmark that exposed the failure? From the description, I can't see what's wrong. Thomas -- What|Removed |Added CC||Thomas dot Koenig at online ||dot de http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tkoenig at gcc dot gnu dot org 2005-04-13 10:01 --- The program test_spread from the original bug report is bogus. dim=1000 doesn't make sense (which invalidates my comment #5 and makes this particular case a diagnostics issue). Thomas -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From fxcoudert at gcc dot gnu dot org 2005-04-08 15:28 --- Yet another SPREAD problem: ! Original bug-report by Walt Brainerd, The Fortran Company integer,dimension(2) :: mi1 = 1 integer,dimension(1,1) :: s s = spread(mi1,1,2) end I agree those intrinsics should be high-priority. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From paulthomas2 at wanadoo dot fr 2005-03-25 05:44 --- (In reply to comment #4) It should be noted that reshape also suffers from the same disorder. To my mind, this makes the PR rather high priority - after all, the vectorized functions are among the features that make F9x different. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From Thomas dot Koenig at online dot de 2005-03-09 23:33 --- This looks very much like a front end bug. The "along" parameter gets the wrong value. Look at this: $ cat test_spread.f90 program test_spread implicit none integer, parameter :: N = 1000 integer:: I integer, dimension(N) :: source integer, dimension(N,N) :: sink do i = 1 , N source(i) = N end do print *,'product' sink = spread( source , 1 , N ) * spread( source , N , N ) print *, sink stop end program test_spread $ gfortran -fdump-tree-original test_spread.f90 >From the *.t02.original file: L.2:; _gfortran_filename = "test_spread.f90"; _gfortran_line = 10; _gfortran_ioparm.unit = 6; _gfortran_ioparm.list_format = 1; _gfortran_st_write (); _gfortran_transfer_character ("product", 7); _gfortran_st_write_done (); { int4 C.512 = 1000; int4 C.511 = 1000; struct array1_int4 parm.3; struct array2_int4 atmp.2; int4 C.492 = 1000; int4 C.491 = 1; struct array1_int4 parm.1; struct array2_int4 atmp.0; ... and further down: parm.1.dtype = 265; parm.1.dim[0].lbound = 1; parm.1.dim[0].ubound = 1000; parm.1.dim[0].stride = 1; parm.1.data = (int4[0:] *) (int4[0:] *) &source[0]; parm.1.offset = 0; _gfortran_spread (&atmp.0, &parm.1, &C.491, &C.492); ^^ This is =1000, which is bogus The last parameter of spread is "along", which is supposed to give the dimension. 1000 is a bit too high :-) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tobi at gcc dot gnu dot org 2004-12-02 21:05 --- I think I know now how the return array is allocated. This is not the error. An additional error seems to be that a scalar source is not special cased, as for PACK, see PR17283: [EMAIL PROTECTED] tests]$ cat spread.f90 real :: a(5) a = spread (1., 1, 5) end [EMAIL PROTECTED] tests]$ gfortran spread.f90 [EMAIL PROTECTED] tests]$ ./a.out Segmentation fault -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From tobi at gcc dot gnu dot org 2004-12-02 20:56 --- Looking at the code it seems to me that the return array isn't allocated anywhere. I don't know the scalarizer well enough, though. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From paulthomas2 at wanadoo dot fr 2004-11-15 14:58 --- Looking at the source of SPREAD, I note that it does not assert the rank of the output matrix. Thus, in the fragment from the LLNL test it should be possible to output the calls to SPREAD to temporary arrays, multiply these and add them to the result. Thus: DO K = 1, 25 PRTTEMP = SPREAD(VY(:25,K),DIM = 2,NCOPIES = N) PRTTEMP = PRTTEMP * SPREAD(CX(K,:N),DIM = 1,NCOPIES = 25) PX(:,:N) = PX(:,:N) + PRTTEMP !! PX(:,:N) = PX(:,:N) + SPREAD(VY(:25,K),DIM = 2,NCOPIES = N)* & !! & SPREAD(CX(K,:N),DIM = 1,NCOPIES = 25) END DO works but the commented out part does not. Is the caller or the callee responsible for asserting the rank of the output? If the latter, the fix is trivial. If the former, the problem is not with SPREAD but with the compiler front-end not assigning intermediate temporaries the correct rank. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495
[Bug libfortran/18495] Intrinisc function SPREAD is broken
--- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-15 05:43 --- Confirmed. -- What|Removed |Added Status|UNCONFIRMED |NEW Component|fortran |libfortran Ever Confirmed||1 Last reconfirmed|-00-00 00:00:00 |2004-11-15 05:43:32 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18495