http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56318
Tobias Burnus <burnus at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization --- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2013-02-14 11:29:55 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