From 6c6bde30706c29ffe41415f95ef3f48b6712cbe7 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Fri, 27 Oct 2017 17:11:42 +0000 Subject: [PATCH] re PR fortran/56342 (MATMUL with PARAMETER: Simplification usually doesn't work) 2017-10-27 Thomas Koenig 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 PR fortran/56342 * gfortran.dg/matmul_const.f90: New test. From-SVN: r254157 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/simplify.c | 7 ++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/matmul_const.f90 | 10 ++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/matmul_const.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9e3415220c21..295704adc6eb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-10-27 Thomas Koenig + + PR fortran/56342 + * simplify.c (is_constant_array_expr): If the expression is + a parameter array, call gfc_simplify_expr. + 2017-10-25 Bernhard Reutner-Fischer * match.c (gfc_match_type_is): Fix typo in error message. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 169aef1d8923..ba010a0aebff 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -227,7 +227,8 @@ convert_boz (gfc_expr *x, int kind) } -/* Test that the expression is an constant array. */ +/* Test that the expression is an constant array, simplifying if + we are dealing with a parameter array. */ static bool is_constant_array_expr (gfc_expr *e) @@ -237,6 +238,10 @@ is_constant_array_expr (gfc_expr *e) if (e == NULL) return true; + if (e->expr_type == EXPR_VARIABLE && e->rank > 0 + && e->symtree->n.sym->attr.flavor == FL_PARAMETER) + gfc_simplify_expr (e, 1); + if (e->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (e)) return false; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f841fca41fb7..2fb6daaf2143 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-10-27 Thomas Koenig + + PR fortran/56342 + * gfortran.dg/matmul_const.f90: New test. + 2017-10-25 Jan Hubicka * gcc.target/i386/pr70021.c: Add -mtune=skylake. diff --git a/gcc/testsuite/gfortran.dg/matmul_const.f90 b/gcc/testsuite/gfortran.dg/matmul_const.f90 new file mode 100644 index 000000000000..35dce3227748 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/matmul_const.f90 @@ -0,0 +1,10 @@ +! { dg-do run } +! { dg-additional-options "-fno-frontend-optimize -fdump-tree-original" } +program main + 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]) + character (len=30) :: line + write (unit=line,fmt='(9i3)') matmul(A,B) + if (line /= ' 5 7 9 5 7 9 5 7 9') call abort +end program main +! dg-final { scan-tree-dump-times "matmul_i4" 0 "original" } } -- 2.47.2