From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9266 invoked by alias); 27 Oct 2012 17:22:02 -0000 Received: (qmail 9205 invoked by uid 48); 27 Oct 2012 17:21:44 -0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/55100] New: FORALL: If the RHS is scalar, not array temporary is needed Date: Sat, 27 Oct 2012 17:22:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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: 2012-10/txt/msg02583.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55100 Bug #: 55100 Summary: FORALL: If the RHS is scalar, not array temporary is needed Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org As the dump shows, gfortran generates a temporary array in this case. While a temporary is needed, a scalar temporary is sufficient if/as the RHS is a scalar (or a an array element which doesn't depend on the forall index). implicit none type inner integer :: i = 5 end type inner type t integer :: i type(inner), pointer :: str end type t type(t), pointer :: y(:) type(inner), target :: tgt integer :: i, n n = 10 allocate(y(n)) forall(i=1:n) y(i)%str => null() ! Ok, no tmp needed forall(i=1:n) y(i)%i = 5 ! Ok, no tmp needed do i = 1, n if (associated(y(i)%str)) stop 'ERROR' if (y(i)%i /= 5) stop 'ERROR' end do forall(i=1:n) y(i)%str => tgt ! Only scalar tmp needed do i = 1, n if (.not. associated(y(i)%str,tgt)) stop 'ERROR' end do ! Pointless assignment of the value from tgt to tgt forall(i=1:n) y(i)%str = tgt ! Only scalar tmp needed end