https://gcc.gnu.org/g:83cd350c24699b011ba8240639fe6073031a862d

commit 83cd350c24699b011ba8240639fe6073031a862d
Author: Mikael Morin <mik...@gcc.gnu.org>
Date:   Wed Jul 9 21:18:18 2025 +0200

    fortran: Factor array descriptor references
    
    Regression tested on x86_64-pc-linux-gnu.
    OK for master?
    
    -- >8 --
    
    Save subexpressions of array descriptor references to variables, so that
    all the expressions using the descriptor as base object benefit from a
    simplified reference using the variables.
    
    This limits the size of the expressions generated in the original tree
    dump, easing analysis of the code involving those expressions.
    This is especially helpful with chains of array references where each
    array in the chain uses a descriptor.
    
    After optimizations, the effect of the change shouldn't be visible in
    the vast majority of cases.  In rare cases it seems to permit a couple
    more jump threadings.
    
    gcc/fortran/ChangeLog:
    
            * trans-array.cc (gfc_conv_ss_descriptor): Move the descriptor
            expression initialisation...
            (set_factored_descriptor_value): ... to this new function.
            Before initialisation, walk the reference expression passed as
            argument and save some of its subexpressions to a variable.
            (substitute_t): New struct.
            (maybe_substitute_expr): New function.
            (substitute_subexpr_in_expr): New function.

Diff:
---
 gcc/fortran/trans-array.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 73958d12653b..16c4e6ee6090 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3622,7 +3622,7 @@ gfc_conv_ss_descriptor (stmtblock_t * block, gfc_ss * ss, 
int base)
       /* Also the data pointer.  */
       tmp = gfc_conv_array_data (se.expr);
       /* If this is a variable or address or a class array, use it directly.
-         Otherwise we must evaluate it now to avoid breaking dependency
+        Otherwise we must evaluate it now to avoid breaking dependency
         analysis by pulling the expressions for elemental array indices
         inside the loop.  */
       if (save_descriptor_data (se.expr, tmp) && !ss->is_alloc_lhs)

Reply via email to