From 022e30c0b67a70587b22fc67f7a7e11e0600005f Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Sat, 10 Jul 2010 14:57:25 +0000 Subject: [PATCH] re PR fortran/44773 (Unnecessary temporaries increase the runtime for channel.f90 by ~70%) 2010-07-10 Paul Thomas PR fortran/44773 * trans-expr.c (arrayfunc_assign_needs_temporary): No temporary if the lhs has never been host associated, as well as not being use associated, a pointer or a target. * resolve.c (resolve_variable): Mark variables that are host associated. * gfortran.h: Add the host_assoc bit to the symbol_attribute structure. From-SVN: r162038 --- gcc/fortran/ChangeLog | 11 +++++++++++ gcc/fortran/gfortran.h | 3 ++- gcc/fortran/resolve.c | 9 +++++++++ gcc/fortran/trans-expr.c | 5 +++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f43a33b30ed..e4837b45300 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2010-07-10 Paul Thomas + + PR fortran/44773 + * trans-expr.c (arrayfunc_assign_needs_temporary): No temporary + if the lhs has never been host associated, as well as not being + use associated, a pointer or a target. + * resolve.c (resolve_variable): Mark variables that are host + associated. + * gfortran.h: Add the host_assoc bit to the symbol_attribute + structure. + 2010-07-09 Janus Weil * intrinsic.texi: Add documentation for SAME_TYPE_AS, EXTENDS_TYPE_OF, diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 37979268c65..60864807db6 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -682,7 +682,8 @@ typedef struct use_assoc:1, /* Symbol has been use-associated. */ use_only:1, /* Symbol has been use-associated, with ONLY. */ use_rename:1, /* Symbol has been use-associated and renamed. */ - imported:1; /* Symbol has been associated by IMPORT. */ + imported:1, /* Symbol has been associated by IMPORT. */ + host_assoc:1; /* Symbol has been host associated. */ unsigned in_namelist:1, in_common:1, in_equivalence:1; unsigned function:1, subroutine:1, procedure:1; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index a8ed5440655..98d1e079e50 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -4772,6 +4772,15 @@ resolve_variable (gfc_expr *e) sym->entry_id = current_entry_id + 1; } + /* If a symbol has been host_associated mark it. This is used latter, + to identify if aliasing is possible via host association. */ + if (sym->attr.flavor == FL_VARIABLE + && gfc_current_ns->parent + && (gfc_current_ns->parent == sym->ns + || (gfc_current_ns->parent->parent + && gfc_current_ns->parent->parent == sym->ns))) + sym->attr.host_assoc = 1; + resolve_procedure: if (t == SUCCESS && resolve_procedure_expression (e) == FAILURE) t = FAILURE; diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index ea8b8920279..5f2eda29693 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -4978,6 +4978,11 @@ arrayfunc_assign_needs_temporary (gfc_expr * expr1, gfc_expr * expr2) if (!expr2->value.function.esym->attr.contained) return false; + /* A temporary is not needed if the lhs has never been host + associated and the procedure is contained. */ + else if (!sym->attr.host_assoc) + return false; + /* A temporary is not needed if the variable is local and not a pointer, a target or a result. */ if (sym->ns->parent