From patchwork Thu Feb 14 14:50:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 220456 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D64652C0085 for ; Fri, 15 Feb 2013 01:50:57 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1361458258; h=Comment: DomainKey-Signature:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=RDMQUoh DKL5j8RyeutaIE66QpRE=; b=CdP+4u/SLwzXpRreS8k2DUrfvJLp2bC7C9FTV5z KFTnY4/0gMz56NOPiDWjAhRlZsMqzyrEZQL+1ny2OtWmkX7doKtEwTz9iRuKalSG B/3jjlSFDjJ/xZ8Q9StOecO6DJUf9LPZY16q3x/yNYb7Z/OO3UWWrIjJsM5pBKpT Fr+k= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=akDjIADCLY9VVEv0TBW0sU5IzT0Swvvqv6LVChRquwBK4LktM9Ttf7Nc4I8uaw eRijDhBqJACoc+eDhoergWGWSwelc2EpK42H7PwwG3alge1OLpxZ5HNz9TVsaHql i32xlJ9u0oSMbVVTbxd4YTLG/1AFl5wLePeYSO5x6RqN8=; Received: (qmail 21217 invoked by alias); 14 Feb 2013 14:50:49 -0000 Received: (qmail 21185 invoked by uid 22791); 14 Feb 2013 14:50:46 -0000 X-SWARE-Spam-Status: No, hits=0.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SARE_PROLOSTOCK_SYM3, TBIRD_SPOOF X-Spam-Check-By: sourceware.org Received: from mx01.qsc.de (HELO mx01.qsc.de) (213.148.129.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Feb 2013 14:50:27 +0000 Received: from archimedes.net-b.de (port-92-195-225-65.dynamic.qsc.de [92.195.225.65]) by mx01.qsc.de (Postfix) with ESMTP id 1B8223CE56; Thu, 14 Feb 2013 15:50:22 +0100 (CET) Message-ID: <511CF9AE.2030106@net-b.de> Date: Thu, 14 Feb 2013 15:50:22 +0100 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch, Fortran] PR56318 - Fix MATMUL regression Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch fixes the matmul bug, which was reported this morning. Seemingly, the code never worked correctly. Regarding the result patch: Mikael and I came independently to the same result thus it must be right (or not?); additionally, I tested and found out that matrix-scalar/scalar-matrix was mishandled. Build and regtested on x86-64-gnu-linux. OK for the trunk and the 4.6 and 4.7 branches? (I think we can ignore 4.5, can we?) Tobias PS: There is another bug, which prevents the simplification in some cases (see PR), as it only results in a missed optimization (or reject valid in constant expressions), I defer this to another patch. 2013-02-14 Tobias Burnus Mikael Morin PR fortran/56318 * simplify.c (gfc_simplify_matmul): Fix result shape and matmul result. 2013-02-14 Tobias Burnus PR fortran/56318 * gcc/testsuite/gfortran.dg/matmul_9.f90: New. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index f7401e9..a0909a3 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -3850,7 +3850,7 @@ gfc_simplify_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b) if (matrix_a->rank == 1 && matrix_b->rank == 2) { result_rows = 1; - result_columns = mpz_get_si (matrix_b->shape[0]); + result_columns = mpz_get_si (matrix_b->shape[1]); stride_a = 1; stride_b = mpz_get_si (matrix_b->shape[0]); @@ -3860,7 +3860,7 @@ gfc_simplify_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b) } else if (matrix_a->rank == 2 && matrix_b->rank == 1) { - result_rows = mpz_get_si (matrix_b->shape[0]); + result_rows = mpz_get_si (matrix_a->shape[0]); result_columns = 1; stride_a = mpz_get_si (matrix_a->shape[0]); stride_b = 1; @@ -3873,7 +3873,7 @@ gfc_simplify_matmul (gfc_expr *matrix_a, gfc_expr *matrix_b) { result_rows = mpz_get_si (matrix_a->shape[0]); result_columns = mpz_get_si (matrix_b->shape[1]); - stride_a = mpz_get_si (matrix_a->shape[1]); + stride_a = mpz_get_si (matrix_a->shape[0]); stride_b = mpz_get_si (matrix_b->shape[0]); result->rank = 2; diff --git a/gcc/testsuite/gfortran.dg/matmul_9.f90 b/gcc/testsuite/gfortran.dg/matmul_9.f90 new file mode 100644 index 0000000..bf2a299 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/matmul_9.f90 @@ -0,0 +1,47 @@ +! { dg-do run } +! { dg-options "-fdump-tree-original" } +! +! PR fortran/56318 +! +! Contributed by Alberto Luaces +! +SUBROUTINE mass_matrix + DOUBLE PRECISION,PARAMETER::m1=1.d0 + DOUBLE PRECISION,DIMENSION(3,2),PARAMETER::A1=reshape([1.d0,0.d0, 0.d0, & + 0.d0,1.d0, 0.d0],[3,2]) + DOUBLE PRECISION,DIMENSION(2,2),PARAMETER::Mel=reshape([1.d0/3.d0, 0.d0, & + 0.d0, 1.d0/3.d0],[2,2]) + + DOUBLE PRECISION,DIMENSION(3,3)::MM1 + + MM1=m1*matmul(A1,matmul(Mel,transpose(A1))) + !print '(3f8.3)', MM1 + if (any (abs (MM1 & + - reshape ([1.d0/3.d0, 0.d0, 0.d0, & + 0.d0, 1.d0/3.d0, 0.d0, & + 0.d0, 0.d0, 0.d0], & + [3,3])) > epsilon(1.0d0))) & + call abort () +END SUBROUTINE mass_matrix + +program name + implicit none + integer, parameter :: A(3,2) = reshape([1,2,3,4,5,6],[3,2]) + integer, parameter :: B(2,3) = reshape([3,17,23,31,43,71],[2,3]) + integer, parameter :: C(3) = [-5,-7,-21] + integer, parameter :: m1 = 1 + +! print *, matmul(B,C) + if (any (matmul(B,C) /= [-1079, -1793])) call abort() +! print *, matmul(C,A) + if (any (matmul(C,A) /= [-82, -181])) call abort() +! print '(3i5)', m1*matmul(A,B) + if (any (m1*matmul(A,B) /= reshape([71,91,111, 147,201,255, 327,441,555],& + [3,3]))) & + call abort() + call mass_matrix +end program name + +! { dg-final { scan-tree-dump-times "matmul" 0 "original" } } +! { dg-final { cleanup-tree-dump "original" } } +