https://gcc.gnu.org/g:05afa30065b36d3ac7404b571e7f694ac087aa66
commit 05afa30065b36d3ac7404b571e7f694ac087aa66 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Fri Jul 11 16:09:10 2025 +0200 Sauvegarde 3 Diff: --- gcc/fortran/trans-array.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 9bdf60b7aeb5..80765a3b1c63 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -3441,16 +3441,16 @@ typedef struct { tree expr, repl; } -replacement_t; +substitute_t; static tree -replace_expr (tree *tp, int *walk_subtree, void *data) +maybe_substitute_expr (tree *tp, int *walk_subtree, void *data) { - replacement_t *repl = (replacement_t *) data; - if (*tp == repl->expr) + substitute_t *subst = (substitute_t *) data; + if (*tp == subst->expr) { - *tp = repl->repl; + *tp = subst->repl; *walk_subtree = 0; } @@ -3458,21 +3458,22 @@ replace_expr (tree *tp, int *walk_subtree, void *data) } +/* Substitute in CONTEXT any occurence of EXPR with REPLACEMENT. */ + static void -replace_tree_in_expr (tree t, tree expr, tree replacement) +substitute_in_tree (tree expr, tree replacement, tree context) { - replacement_t repl; - repl.expr = t; - repl.repl = replacement; + substitute_t subst; + subst.expr = t; + subst.repl = replacement; - walk_tree (&expr, replace_expr, &repl, nullptr); + walk_tree (&context, maybe_ubstitute_expr, &subst, nullptr); } -/* Save the descriptor reference VALUE to storage pointed by DESC_PTR. As there - may be a lot of code using subreferences of the descriptor, try to factor - them by evaluating the leading part of the data reference to a variable, - adding extra code to BLOCK. +/* Save the descriptor reference VALUE to storage pointed by DESC_PTR. Try to + factor shared subexpressions of VALUE to variables, adding extra code to + BLOCK. The candidate references for factoring are dereferenced pointers because they are cheap to copy and array descriptors because they are often the base of @@ -3489,8 +3490,11 @@ set_factored_descriptor_value (stmtblock_t *block, tree *desc_ptr, tree value) gfc_init_block (&tmp_block); + /* The current candidate to factoring. */ tree saveable_ref = NULL_TREE; + /* The root expressions in which we look for subexpressions to replace with + variables. */ auto_vec<tree> replacement_roots; replacement_roots.safe_push (value); @@ -3500,7 +3504,7 @@ set_factored_descriptor_value (stmtblock_t *block, tree *desc_ptr, tree value) /* If the candidate reference is not followed by a subreference, it can't be saved to a variable as it may be reallocatable, and we have to keep the parent reference to be able to store the new pointer value in case of - reallocation. Otherwise it can be saved to a variable. */ + reallocation. */ bool maybe_reallocatable = true; while (true)