From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30152 invoked by alias); 22 Apr 2010 14:00:59 -0000 Received: (qmail 29979 invoked by uid 48); 22 Apr 2010 14:00:40 -0000 Date: Thu, 22 Apr 2010 14:00:00 -0000 Message-ID: <20100422140040.29978.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/43829] Scalarization of reductions In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-04/txt/msg02359.txt.bz2 ------- 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