This is a follow up to PR 56318, reported by Alberto Luaces at http://gcc.gnu.org/ml/fortran/2013-02/msg00074.html The wrong-code issue has been fixed, however, it was noted there that MATMUL with parameters is not get optimized. 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)', matmul(A,B) ! Does not get optimized print '(3i3)', m1*matmul(A,B) ! Is optimized end !------------------------------------ (See the other PR for the original test case - and gfortran.dg/matmul_9.f90; they all use the multiplication - which lead to simplification and hit a now fixed wrong-code bug.) 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. It seems as if one has to run "gfc_simplify_expr" – the question is whether that shouldn't then also be done for other intrinsics?
Another example: http://gcc.gnu.org/ml/fortran/2013-07/msg00005.html - Here, the SUM is not simplified.
Still true at r206385.
Yes, simplification is the key.
Author: tkoenig Date: Fri Oct 27 17:11:42 2017 New Revision: 254157 URL: https://gcc.gnu.org/viewcvs?rev=254157&root=gcc&view=rev Log: 2017-10-27 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/56342 * simplify.c (is_constant_array_expr): If the expression is a parameter array, call gfc_simplify_expr. 2017-10-27 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/56342 * gfortran.dg/matmul_const.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/matmul_const.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/simplify.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk, closing.