This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Fortran] Another round of WHERE statement optimizations


Roger Sayle wrote:
As has been pointed out, most of the functionality that was changed
with this patch is currently tested in the testsuite, but I agree
that the follow-up patches cover corner cases that currently have
poor coverage.

How about the following testsuite additions, that pass both with
and without the current patch, that cover a few more cases to make
sure nothing bad happens?

Ok for mainline?

Looks good to me; I'd suggest also adding some checks to make sure that things that need to be independent stay independent even when the argument is being modified, and such things.


For instance (added onto the end of your list):

! Check to ensure only the first true clause in WHERE is
! executed.
program where_17
   integer :: a(3)

   a = (/1, 2, 3/)
   where (a .eq. 1)
     a = 2
   elsewhere (a .le. 2)
     a = 3
   elsewhere (a .le. 3)
     a = 4
   endwhere
   if (any (a .ne. (/2, 3, 4/))) call abort
end program

! Check to ensure mask is calculated first in WHERE
! statements.
program where_18
   integer :: a(4)
   integer :: b(3)
   integer :: c(3)
   equivalence (a(1), b(1)), (a(2), c(1))

   a = (/1, 1, 1, 1/)
   where (b .eq. 1)
     c = 2
   elsewhere (b .eq. 2)
     c = 3
   endwhere
   if (any (a .ne. (/1, 2, 2, 2/))) &
     call abort

   a = (/1, 1, 1, 1/)
   where (c .eq. 1)
     b = 2
   elsewhere (b .eq. 2)
     b = 3
   endwhere
   if (any (a .ne. (/2, 2, 2, 1/))) &
     call abort
end program

! Check to ensure result is calculated from unmodified
! version of the right-hand-side in WHERE statements.
program where_19
   integer :: a(4)
   integer :: b(3)
   integer :: c(3)
   equivalence (a(1), b(1)), (a(2), c(1))

   a = (/1, 2, 3, 4/)
   where (b .gt. 1)
     c = b
   endwhere
   if (any (a .ne. (/1, 1, 2, 3/))) &
     call abort

   a = (/1, 2, 3, 4/)
   where (c .gt. 1)
     b = c
   endwhere
   if (any (a .ne. (/2, 3, 4, 4/))) &
     call abort
end program


- Brooks


P.S. Because this is the first time it's come up: Yes, I do have a copyright assignment on file.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]