https://gcc.gnu.org/g:837ca25939afce7f6ea5db691994b16afe4ea2a6
commit 837ca25939afce7f6ea5db691994b16afe4ea2a6 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Thu Jan 16 15:28:38 2025 +0100 Refactor conv_shift_descriptor Diff: --- gcc/fortran/trans-array.cc | 23 ++++++++++++++--------- gcc/fortran/trans-array.h | 1 - 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index ecdaad3f9575..0446cc97d4d6 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -1165,16 +1165,15 @@ gfc_build_null_descriptor (tree type) /* Modify a descriptor such that the lbound of a given dimension is the value specified. This also updates ubound and offset accordingly. */ -void -gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc, - int dim, tree new_lbound) +static void +conv_shift_descriptor_lbound (stmtblock_t* block, tree desc, int dim, + tree new_lbound, tree offset) { - tree offs, ubound, lbound, stride; + tree ubound, lbound, stride; tree diff, offs_diff; new_lbound = fold_convert (gfc_array_index_type, new_lbound); - offs = gfc_conv_descriptor_offset_get (desc); lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim]); ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[dim]); stride = gfc_conv_descriptor_stride_get (desc, gfc_rank_cst[dim]); @@ -1190,9 +1189,9 @@ gfc_conv_shift_descriptor_lbound (stmtblock_t* block, tree desc, gfc_conv_descriptor_ubound_set (block, desc, gfc_rank_cst[dim], ubound); offs_diff = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, diff, stride); - offs = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - offs, offs_diff); - gfc_conv_descriptor_offset_set (block, desc, offs); + tree tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, + offset, offs_diff); + gfc_add_modify (block, offset, tmp); /* Finally set lbound to value we want. */ gfc_conv_descriptor_lbound_set (block, desc, gfc_rank_cst[dim], new_lbound); @@ -1229,6 +1228,10 @@ static void conv_shift_descriptor (stmtblock_t *block, tree desc, int rank, const lb_info &info) { + tree tmp = gfc_conv_descriptor_offset_get (desc); + tree offset_var = gfc_create_var (TREE_TYPE (tmp), "offset"); + gfc_add_modify (block, offset_var, tmp); + /* Apply a shift of the lbound when supplied. */ for (int dim = 0; dim < rank; ++dim) { @@ -1252,8 +1255,10 @@ conv_shift_descriptor (stmtblock_t *block, tree desc, int rank, lower_bound = lb_var; } - gfc_conv_shift_descriptor_lbound (block, desc, dim, lower_bound); + conv_shift_descriptor_lbound (block, desc, dim, lower_bound, offset_var); } + + gfc_conv_descriptor_offset_set (block, desc, offset_var); } diff --git a/gcc/fortran/trans-array.h b/gcc/fortran/trans-array.h index 378afb9617a3..3f39845c898f 100644 --- a/gcc/fortran/trans-array.h +++ b/gcc/fortran/trans-array.h @@ -214,7 +214,6 @@ tree gfc_get_cfi_dim_sm (tree, tree); /* Shift lower bound of descriptor, updating ubound and offset. */ -void gfc_conv_shift_descriptor_lbound (stmtblock_t*, tree, int, tree); void gfc_conv_shift_descriptor (stmtblock_t*, tree, const gfc_array_ref &); void gfc_conv_shift_descriptor (stmtblock_t*, tree, int); void gfc_conv_shift_descriptor (stmtblock_t*, tree, tree, int, tree);