https://gcc.gnu.org/g:e4b734b096732b9a2264ea1a9869e0b73f7ce654
commit e4b734b096732b9a2264ea1a9869e0b73f7ce654 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Fri Feb 7 12:07:36 2025 +0100 Factorisation set_descriptor_dimension Diff: --- gcc/fortran/trans-array.cc | 82 +++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index d5c7b1344697..298fbc8d8bfd 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -1472,6 +1472,41 @@ gfc_build_null_descriptor (tree type) } +static tree +set_descriptor_dimension (stmtblock_t *block, tree desc, int dim, + tree lbound, tree ubound, tree stride, tree *offset) +{ + /* Set bounds in descriptor. */ + lbound = fold_convert (gfc_array_index_type, lbound); + lbound = gfc_evaluate_now (lbound, block); + gfc_conv_descriptor_lbound_set (block, desc, + gfc_rank_cst[dim], lbound); + + ubound = fold_convert (gfc_array_index_type, upper); + ubound = gfc_evaluate_now (ubound, block); + gfc_conv_descriptor_ubound_set (block, desc, + gfc_rank_cst[dim], ubound); + + /* Set stride. */ + stride = fold_convert (gfc_array_index_type, stride); + stride = gfc_evaluate_now (stride, block); + gfc_conv_descriptor_stride_set (block, desc, + gfc_rank_cst[dim], stride); + + /* Update offset. */ + tree tmp = fold_build2_loc (input_location, MULT_EXPR, + gfc_array_index_type, lbound, stride); + *offset = fold_build2_loc (input_location, MINUS_EXPR, + gfc_array_index_type, *offset, tmp); + + /* Update stride. */ + tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL); + stride = fold_build2_loc (input_location, MULT_EXPR, + gfc_array_index_type, stride, tmp); + return stride; +} + + /* Modify a descriptor such that the lbound of a given dimension is the value specified. This also updates ubound and offset accordingly. */ @@ -1821,9 +1856,9 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src, /* Copy offset but adjust it such that it would correspond to a lbound of zero. */ + tree offset; if (src_rank == -1) - gfc_conv_descriptor_offset_set (block, dest, - gfc_index_zero_node); + offset = gfc_index_zero_node; else { tree offs = gfc_conv_descriptor_offset_get (src); @@ -1839,7 +1874,7 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src, offs = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, offs, tmp); } - gfc_conv_descriptor_offset_set (block, dest, offs); + offset = offs; } /* Set the bounds as declared for the LHS and calculate strides as well as another offset update accordingly. */ @@ -1855,46 +1890,17 @@ gfc_conv_remap_descriptor (stmtblock_t *block, tree dest, tree src, /* Convert declared bounds. */ gfc_init_se (&lower_se, NULL); gfc_init_se (&upper_se, NULL); - gfc_conv_expr (&lower_se, as.lower[dim]); - gfc_conv_expr (&upper_se, as.upper[dim]); + gfc_conv_expr_val (&lower_se, as.lower[dim]); + gfc_conv_expr_val (&upper_se, as.upper[dim]); gfc_add_block_to_block (block, &lower_se.pre); gfc_add_block_to_block (block, &upper_se.pre); - tree lbound = fold_convert (gfc_array_index_type, lower_se.expr); - tree ubound = fold_convert (gfc_array_index_type, upper_se.expr); - - lbound = gfc_evaluate_now (lbound, block); - ubound = gfc_evaluate_now (ubound, block); - - gfc_add_block_to_block (block, &lower_se.post); - gfc_add_block_to_block (block, &upper_se.post); - - /* Set bounds in descriptor. */ - gfc_conv_descriptor_lbound_set (block, dest, - gfc_rank_cst[dim], lbound); - gfc_conv_descriptor_ubound_set (block, dest, - gfc_rank_cst[dim], ubound); - - /* Set stride. */ - stride = gfc_evaluate_now (stride, block); - gfc_conv_descriptor_stride_set (block, dest, - gfc_rank_cst[dim], stride); - - /* Update offset. */ - tree offs = gfc_conv_descriptor_offset_get (dest); - tmp = fold_build2_loc (input_location, MULT_EXPR, - gfc_array_index_type, lbound, stride); - offs = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, offs, tmp); - offs = gfc_evaluate_now (offs, block); - gfc_conv_descriptor_offset_set (block, dest, offs); - - /* Update stride. */ - tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL); - stride = fold_build2_loc (input_location, MULT_EXPR, - gfc_array_index_type, stride, tmp); + stride = set_descriptor_dimension (block, dest, dim, + lower_se.expr, upper_se.expr, stride, + &offset); } + gfc_conv_descriptor_offset_set (block, dest, offset); }