------- Comment #5 from rguenth at gcc dot gnu dot org  2010-04-22 14:00 -------
Now onto

  subroutine test1(esss,Ix,Iyz)
    real(kind=kind(1.0d0)), dimension(:), intent(out) :: esss
    real(kind=kind(1.0d0)), dimension(:,:) :: Ix,Iyz
    esss = sum(Ix * Iyz, 1)
  end subroutine

noting that we can exchange the sum and the indexing of the assignment
making the sum() of rank one (and thus eligible for inline expansion).

Thus, expand it as

  do i=1,size(esss)
    esss(i) = sum(Ix(i,:) * Iyz(i,:))
  end do


An even simpler testcase where we want to do this exchange is

  subroutine test0(esss,Ix,Iyz)
    real(kind=kind(1.0d0)), dimension(:), intent(out) :: esss
    real(kind=kind(1.0d0)), dimension(:,:), intent(in) :: Ix
    esss = sum(Ix, 1)
  end subroutine

Thus, whenever the reduction is one-dimensional (though in this simpler
testcase we do not avoid the temporary for the sum intrinsic argument
which was the point of the excercise).  So, slightly more complicated
to show that this is still beneficial:

  subroutine test0(esss,Ix,Iyz)
    real(kind=kind(1.0d0)), dimension(:), intent(out) :: esss
    real(kind=kind(1.0d0)), dimension(:,:), intent(in) :: Ix
    esss = esss + sum(Ix, 1)
  end subroutine


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43829

Reply via email to