From d6de944394df3fdcba3272c4ae0626d0f328d06e Mon Sep 17 00:00:00 2001 From: sayle Date: Thu, 18 Jan 2007 18:17:08 +0000 Subject: [PATCH] * trans-stmt.c (compute_overall_iter_number): Enhance to precompute the number of interations in unconditional FORALL nests with constant bounds. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120905 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-stmt.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 55c5ecedf92a..4c1a3c528e74 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2007-01-18 Roger Sayle + + * trans-stmt.c (compute_overall_iter_number): Enhance to precompute + the number of interations in unconditional FORALL nests with constant + bounds. + 2007-01-18 Francois-Xavier Coudert Tobias Burnus diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 437aa3642484..c36d6faf0e9e 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -2034,9 +2034,33 @@ compute_overall_iter_number (forall_info *nested_forall_info, tree inner_size, tree tmp, number; stmtblock_t body; - /* Optimize the case for an outer-most loop with constant bounds. */ - if (INTEGER_CST_P (inner_size) && !nested_forall_info) - return inner_size; + /* Optimize the case of unconditional FORALL nests with constant bounds. */ + if (INTEGER_CST_P (inner_size)) + { + bool all_const_p = true; + forall_info *forall_tmp; + + /* First check whether all the bounds are constant. */ + for (forall_tmp = nested_forall_info; + forall_tmp; + forall_tmp = forall_tmp->next_nest) + if (forall_tmp->mask || !INTEGER_CST_P (forall_tmp->size)) + { + all_const_p = false; + break; + } + + if (all_const_p) + { + tree tmp = inner_size; + for (forall_tmp = nested_forall_info; + forall_tmp; + forall_tmp = forall_tmp->next_nest) + tmp = fold_build2 (MULT_EXPR, gfc_array_index_type, + tmp, forall->size); + return tmp; + } + } /* TODO: optimizing the computing process. */ number = gfc_create_var (gfc_array_index_type, "num"); -- 2.47.3