From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11358 invoked by alias); 2 Aug 2010 12:42:09 -0000 Received: (qmail 11274 invoked by uid 48); 2 Aug 2010 12:41:53 -0000 Date: Mon, 02 Aug 2010 12:42:00 -0000 Message-ID: <20100802124153.11272.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug fortran/45159] Unneccessary temporaries In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "burnus 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-08/txt/msg00061.txt.bz2 ------- Comment #6 from burnus at gcc dot gnu dot org 2010-08-02 12:41 ------- (In reply to comment #5) > > As pointed out by Dominique, one needs to be careful. I think one can optimize: > > c = matmul(b, transpose(c)) > > c = matmul(c,b) > > where c is a rank-2 matrix. I think one cannot optimize it if c is just a > > vector. (Add "conj" as you wish.) And check whether I have not confused columns > > and rows > > So far I have never seen a product matrix*matrix done "in place" and I > seriously doubt it can be done. > The best I can see is to have a temporary of rank 1 I fail to see why a scalar temporary is not enough: do j = 1, N do i = 1, N tmp = 0.0 do k = 1, N tmp = a(i,k)*b(k,j) end do a(i,j) = tmp end do end do Note: it won't work with a scalar if one reverses the i and the j loop. [It would work with a rank-1 "B" argument, but then "A = matmul(B,A)" won't work as the result is a rank-1 array ...] > Note also that the polyhedron test nf.f90 is compiled with unnecessary > temporaries: My feeling is that ONE, THREE (of comment 0), FIVE (of comment 1), and your example (comment 5) point all to the same dependency-analysis problem. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45159