Summary: | [4.6/4.7/4.8 Regression] Wrong result with MATMUL of PARAMETER | ||
---|---|---|---|
Product: | gcc | Reporter: | Tobias Burnus <burnus> |
Component: | fortran | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | burnus, jakub, mikael |
Priority: | P4 | Keywords: | missed-optimization, wrong-code |
Version: | 4.8.0 | ||
Target Milestone: | 4.6.4 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2013-02-14 00:00:00 | |
Bug Depends on: | |||
Bug Blocks: | 56342 |
Description
Tobias Burnus
2013-02-14 10:19:54 UTC
Simplified test case: !------------------------------------ integer, parameter :: A(3,2) = reshape([1,2,3,4,5,6],[3,2]) integer, parameter :: B(2,3) = reshape([1,1,1,1,1,1],[2,3]) integer, parameter :: m1 = 1 print '(3i3)', m1*matmul(A,B) end !------------------------------------ Expected: 5 7 9 5 7 9 5 7 9 Actual result: 9 12 8 9 12 8 4 6 8 a) BUG 1: The matrix is not always simplified The "m1*" is crucial. When gfc_simplify_matmul is called initially, it returns NULL as "is_constant_array_expr (matrix_a)" is false. The "m1*" causes a re-evaluation of the RHS expression, namely in gfc_simplify_expr: for (ap = p->value.function.actual; ap; ap = ap->next) if (gfc_simplify_expr (ap->expr, type) == FAILURE) That converts an EXPR_VARIABLE with flavor FL_PARAMETER into an EXPR_ARRAY, which can then be processed by calling gfc_simplify_matmul b) BUG 2: matmul gives the wrong result (In reply to comment #2) > b) BUG 2: matmul gives the wrong result: Here is a fix for that. It gives the expected results of comment #0 and comment #2. Untested otherwise. diff --git a/simplify.c b/simplify.c index f7401e9..dcf3e89 100644 --- a/simplify.c +++ b/simplify.c @@ -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; Author: burnus Date: Fri Feb 15 11:17:15 2013 New Revision: 196075 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196075 Log: 2013-02-14 Tobias Burnus <burnus@net-b.de> Mikael Morin <mikael@gcc.gnu.org> PR fortran/56318 * simplify.c (gfc_simplify_matmul): Fix result shape and matmul result. 2013-02-14 Tobias Burnus <burnus@net-b.de> PR fortran/56318 * gcc/testsuite/gfortran.dg/matmul_9.f90: New. Added: trunk/gcc/testsuite/gfortran.dg/matmul_9.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog Author: burnus Date: Fri Feb 15 14:20:22 2013 New Revision: 196078 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196078 Log: 2013-02-15 Tobias Burnus <burnus@net-b.de> Mikael Morin <mikael@gcc.gnu.org> PR fortran/56318 * simplify.c (gfc_simplify_matmul): Fix result shape and matmul result. 2013-02-15 Tobias Burnus <burnus@net-b.de> PR fortran/56318 * gcc/testsuite/gfortran.dg/matmul_9.f90: New. Added: branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/matmul_9.f90 Modified: branches/gcc-4_7-branch/gcc/fortran/ChangeLog branches/gcc-4_7-branch/gcc/fortran/simplify.c branches/gcc-4_7-branch/gcc/testsuite/ChangeLog Author: burnus Date: Fri Feb 15 14:20:49 2013 New Revision: 196079 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196079 Log: 2013-02-15 Tobias Burnus <burnus@net-b.de> Mikael Morin <mikael@gcc.gnu.org> PR fortran/56318 * simplify.c (gfc_simplify_matmul): Fix result shape and matmul result. 2013-02-15 Tobias Burnus <burnus@net-b.de> PR fortran/56318 * gcc/testsuite/gfortran.dg/matmul_9.f90: New. Added: branches/gcc-4_6-branch/gcc/testsuite/gfortran.dg/matmul_9.f90 Modified: branches/gcc-4_6-branch/gcc/fortran/ChangeLog branches/gcc-4_6-branch/gcc/fortran/simplify.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog |