https://gcc.gnu.org/g:26b1165b01ae50757befe541c1873561d1f4ded8
commit 26b1165b01ae50757befe541c1873561d1f4ded8 Author: Mikael Morin <mik...@gcc.gnu.org> Date: Sat Mar 29 15:26:26 2025 +0100 Réduction usages gfc_conv_descriptor_ubound_get Correction régression PR96727.f90 Diff: --- gcc/fortran/trans-array.cc | 52 ++++++++++++------------------------------ gcc/fortran/trans-decl.cc | 6 +---- gcc/fortran/trans-expr.cc | 3 +-- gcc/fortran/trans-intrinsic.cc | 44 ++++++++++------------------------- gcc/fortran/trans-openmp.cc | 38 +++++------------------------- gcc/fortran/trans-stmt.cc | 10 ++++---- 6 files changed, 38 insertions(+), 115 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 0cda02d7cefc..7ace0f73b818 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -6523,8 +6523,7 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc, tree stmtInit, stmtCleanup; tree lbound; tree ubound; - tree dubound; - tree dlbound; + tree dextent; tree dumdesc; tree tmp; tree stride, stride2; @@ -6658,16 +6657,10 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc, for (n = 0; n < as->rank; n++) { if (checkparm || !as->upper[n]) - { - /* Get the bounds of the actual parameter. */ - dubound = gfc_conv_descriptor_ubound_get (dumdesc, gfc_rank_cst[n]); - dlbound = gfc_conv_descriptor_lbound_get (dumdesc, gfc_rank_cst[n]); - } + /* Get the bounds of the actual parameter. */ + dextent = gfc_conv_descriptor_extent_get (dumdesc, gfc_rank_cst[n]); else - { - dubound = NULL_TREE; - dlbound = NULL_TREE; - } + dextent = NULL_TREE; lbound = GFC_TYPE_ARRAY_LBOUND (type, n); if (!INTEGER_CST_P (lbound)) @@ -6707,12 +6700,7 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc, temp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, gfc_index_one_node, temp); - stride2 = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, dubound, - dlbound); - stride2 = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, - gfc_index_one_node, stride2); + stride2 = dextent; tmp = fold_build2_loc (input_location, NE_EXPR, gfc_array_index_type, temp, stride2); msg = xasprintf ("Dimension %d of array '%s' has extent " @@ -6730,7 +6718,8 @@ gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc, /* For assumed shape arrays move the upper bound by the same amount as the lower bound. */ tmp = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, dubound, dlbound); + gfc_array_index_type, dextent, + gfc_index_one_node); tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, tmp, lbound); gfc_add_modify (&init, ubound, tmp); @@ -7794,13 +7783,7 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, gfc_expr *expr, tree dim) { if (!dim) dim = gfc_index_zero_node; - tree ubound = gfc_conv_descriptor_ubound_get (desc, dim); - tree lbound = gfc_conv_descriptor_lbound_get (desc, dim); - - size = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, ubound, lbound); - size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - size, gfc_index_one_node); + size = gfc_conv_descriptor_extent_get (desc, dim); /* if (!allocatable && !pointer && assumed rank) size = (idx == rank && ubound[rank-1] == -1 ? -1 : size; else @@ -7816,7 +7799,7 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, gfc_expr *expr, tree dim) fold_convert (signed_char_type_node, dim), tmp); tmp = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, - gfc_conv_descriptor_ubound_get (desc, dim), + gfc_conv_descriptor_extent_get (desc, dim), build_int_cst (gfc_array_index_type, -1)); cond = fold_build2_loc (input_location, TRUTH_AND_EXPR, boolean_type_node, cond, tmp); @@ -7856,16 +7839,12 @@ gfc_tree_array_size (stmtblock_t *block, tree desc, gfc_expr *expr, tree dim) cond = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, idx, tmp); tmp = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, - gfc_conv_descriptor_ubound_get (desc, idx), + gfc_conv_descriptor_extent_get (desc, idx), build_int_cst (gfc_array_index_type, -1)); cond = fold_build2_loc (input_location, TRUTH_AND_EXPR, boolean_type_node, cond, tmp); } - tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - gfc_conv_descriptor_ubound_get (desc, idx), - gfc_conv_descriptor_lbound_get (desc, idx)); - tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - tmp, gfc_index_one_node); + tmp = gfc_conv_descriptor_extent_get (desc, idx); gfc_add_modify (&cond_block, extent, tmp); tmp = fold_build2_loc (input_location, LT_EXPR, boolean_type_node, extent, gfc_index_zero_node); @@ -10244,8 +10223,6 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop, tree cond_null; tree cond; tree tmp; - tree lbound; - tree ubound; tree desc; tree desc2; tree old_desc; @@ -10445,17 +10422,16 @@ gfc_alloc_allocatable_for_assignment (gfc_loopinfo *loop, for (n = 0; n < expr1->rank; n++) { /* Check the shape. */ - lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[n]); - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[n]); + tree extent = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[n]); tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, loop->to[n], loop->from[n]); tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - tmp, lbound); + tmp, gfc_index_one_node); tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - tmp, ubound); + tmp, extent); cond = fold_build2_loc (input_location, NE_EXPR, logical_type_node, tmp, gfc_index_zero_node); diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index e08a2c1bebd4..0c48f7a062d1 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -7594,11 +7594,7 @@ done: gfc_add_modify (&loop_body, gfc_get_cfi_dim_lbound (cfi, idx), gfc_conv_descriptor_lbound_get (gfc_desc, idx)); /* cfi->dim[i].extent = gfc->dim[i].ubound - gfc->dim[i].lbound + 1. */ - tmp = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - gfc_conv_descriptor_ubound_get (gfc_desc, idx), - gfc_conv_descriptor_lbound_get (gfc_desc, idx)); - tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, tmp, - gfc_index_one_node); + tmp = gfc_conv_descriptor_extent_get (gfc_desc, idx); gfc_add_modify (&loop_body, gfc_get_cfi_dim_extent (cfi, idx), tmp); /* d->dim[n].sm = gfc->dim[i].stride * gfc->span); */ tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index 171fbd78fe6c..78e5907fe44e 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -2593,8 +2593,7 @@ gfc_caf_get_image_index (stmtblock_t *block, gfc_expr *e, tree desc) TREE_TYPE (tmp), img_idx, tmp); if (i < ref->u.ar.dimen + ref->u.ar.codimen - 1) { - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); - tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL); + tmp = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[i]); extent = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp), extent, tmp); } diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index cd047aca8149..f226f1b5f038 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -1821,7 +1821,7 @@ trans_this_image (gfc_se * se, gfc_expr *expr) { stmtblock_t loop; tree type, desc, dim_arg, cond, tmp, m, loop_var, exit_label, min_var, - lbound, ubound, extent, ml; + lbound, extent, ml; gfc_se argse; int rank, corank; gfc_expr *distance = expr->value.function.actual->next->next->expr; @@ -1990,9 +1990,7 @@ trans_this_image (gfc_se * se, gfc_expr *expr) gfc_add_modify (&loop, ml, m); /* extent = ... */ - lbound = gfc_conv_descriptor_lbound_get (desc, loop_var); - ubound = gfc_conv_descriptor_ubound_get (desc, loop_var); - extent = gfc_conv_array_extent_dim (lbound, ubound, NULL); + extent = gfc_conv_descriptor_extent_get (desc, loop_var); extent = fold_convert (type, extent); /* m = m/extent. */ @@ -2193,12 +2191,10 @@ trans_image_index (gfc_se * se, gfc_expr *expr) for (codim = corank + rank - 2; codim >= rank; codim--) { - tree extent, ubound; + tree extent; /* coindex = coindex*extent(codim) + sub(codim) - lcobound(codim). */ - lbound = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[codim]); - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[codim]); - extent = gfc_conv_array_extent_dim (lbound, ubound, NULL); + extent = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[codim]); /* coindex *= extent. */ coindex = fold_build2_loc (input_location, MULT_EXPR, @@ -2357,9 +2353,7 @@ gfc_conv_is_contiguous_expr (gfc_se *se, gfc_expr *arg) for (i = 0; i < arg->rank - 1; i++) { - tmp = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[i]); - extent = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); - extent = gfc_conv_array_extent_dim (tmp, extent, nullptr); + extent = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[i]); tmp = gfc_conv_descriptor_stride_get (desc, gfc_rank_cst[i]); tmp = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp), tmp, extent); @@ -2479,7 +2473,7 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, enum gfc_isym_id op) ubound = gfc_conv_descriptor_ubound_get (desc, bound); lbound = gfc_conv_descriptor_lbound_get (desc, bound); - size = gfc_conv_array_extent_dim (lbound, ubound, nullptr); + size = gfc_conv_descriptor_extent_get (desc, bound); /* 13.14.53: Result value for LBOUND @@ -8150,8 +8144,6 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr) gfc_se argse; tree source_bytes; tree tmp; - tree lower; - tree upper; tree byte_size; int n; @@ -8262,9 +8254,7 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr) cond, tmp, build_empty_stmt (input_location)); gfc_add_expr_to_block (&body, tmp); - lower = gfc_conv_descriptor_lbound_get (argse.expr, loop_var); - upper = gfc_conv_descriptor_ubound_get (argse.expr, loop_var); - tmp = gfc_conv_array_extent_dim (lower, upper, NULL); + tmp = gfc_conv_descriptor_extent_get (argse.expr, loop_var); tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, tmp, source_bytes); gfc_add_modify (&body, source_bytes, tmp); @@ -8290,9 +8280,7 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *expr) { tree idx; idx = gfc_rank_cst[n]; - lower = gfc_conv_descriptor_lbound_get (argse.expr, idx); - upper = gfc_conv_descriptor_ubound_get (argse.expr, idx); - tmp = gfc_conv_array_extent_dim (lower, upper, NULL); + tmp = gfc_conv_descriptor_extent_get (argse.expr, idx); tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, tmp, source_bytes); gfc_add_modify (&argse.pre, source_bytes, tmp); @@ -8449,7 +8437,6 @@ gfc_conv_intrinsic_transfer (gfc_se * se, gfc_expr * expr) tree size_words; tree size_bytes; tree upper; - tree lower; tree stmt; tree class_ref = NULL_TREE; gfc_actual_arglist *arg; @@ -8603,16 +8590,10 @@ gfc_conv_intrinsic_transfer (gfc_se * se, gfc_expr * expr) tree idx; idx = gfc_rank_cst[n]; gfc_add_modify (&argse.pre, source_bytes, tmp); - lower = gfc_conv_descriptor_lbound_get (argse.expr, idx); - upper = gfc_conv_descriptor_ubound_get (argse.expr, idx); - tmp = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, upper, lower); + tmp = gfc_conv_descriptor_extent_get (argse.expr, idx); gfc_add_modify (&argse.pre, extent, tmp); - tmp = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, extent, - gfc_index_one_node); tmp = fold_build2_loc (input_location, MULT_EXPR, - gfc_array_index_type, tmp, source_bytes); + gfc_array_index_type, extent, source_bytes); } } @@ -12640,7 +12621,7 @@ conv_intrinsic_event_query (gfc_code *code) /* For arrays, obtain the array index. */ if (gfc_expr_attr (event_expr).dimension) { - tree desc, tmp, extent, lbound, ubound; + tree desc, tmp, extent, lbound; gfc_array_ref *ar, ar2; int i; @@ -12673,8 +12654,7 @@ conv_intrinsic_event_query (gfc_code *code) TREE_TYPE (tmp), index, tmp); if (i < ar->dimen - 1) { - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); - tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL); + tmp = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[i]); extent = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp), extent, tmp); } diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index a5645efa31a0..f1b50ea00b6b 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -778,12 +778,7 @@ gfc_omp_clause_default_ctor (tree clause, tree decl, tree outer) { gfc_add_modify (&cond_block, decl, outer); tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1]; - size = gfc_conv_descriptor_ubound_get (decl, rank); - size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - size, - gfc_conv_descriptor_lbound_get (decl, rank)); - size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - size, gfc_index_one_node); + size = gfc_conv_descriptor_extent_get (decl, rank); if (GFC_TYPE_ARRAY_RANK (type) > 1) size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, @@ -969,12 +964,7 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, tree src) if (GFC_DESCRIPTOR_TYPE_P (type)) { tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1]; - size = gfc_conv_descriptor_ubound_get (dest, rank); - size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - size, - gfc_conv_descriptor_lbound_get (dest, rank)); - size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - size, gfc_index_one_node); + size = gfc_conv_descriptor_extent_get (dest, rank); if (GFC_TYPE_ARRAY_RANK (type) > 1) size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, @@ -1092,12 +1082,7 @@ gfc_omp_clause_assign_op (tree clause, tree dest, tree src) if (GFC_DESCRIPTOR_TYPE_P (type)) { tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1]; - size = gfc_conv_descriptor_ubound_get (src, rank); - size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - size, - gfc_conv_descriptor_lbound_get (src, rank)); - size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - size, gfc_index_one_node); + size = gfc_conv_descriptor_extent_get (src, rank); if (GFC_TYPE_ARRAY_RANK (type) > 1) size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, @@ -1129,15 +1114,9 @@ gfc_omp_clause_assign_op (tree clause, tree dest, tree src) for (i = 0; i < GFC_TYPE_ARRAY_RANK (type); i++) { tree rank = gfc_rank_cst[i]; - tree tem = gfc_conv_descriptor_ubound_get (src, rank); - tem = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, tem, - gfc_conv_descriptor_lbound_get (src, rank)); - tem = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, tem, - gfc_conv_descriptor_lbound_get (dest, rank)); + tree tem = gfc_conv_descriptor_extent_get (src, rank); tem = fold_build2_loc (input_location, NE_EXPR, logical_type_node, - tem, gfc_conv_descriptor_ubound_get (dest, + tem, gfc_conv_descriptor_extent_get (dest, rank)); cond = fold_build2_loc (input_location, TRUTH_ORIF_EXPR, logical_type_node, cond, tem); @@ -1323,12 +1302,7 @@ gfc_omp_clause_linear_ctor (tree clause, tree dest, tree src, tree add) if (GFC_DESCRIPTOR_TYPE_P (type)) { tree rank = gfc_rank_cst[GFC_TYPE_ARRAY_RANK (type) - 1]; - size = gfc_conv_descriptor_ubound_get (dest, rank); - size = fold_build2_loc (input_location, MINUS_EXPR, gfc_array_index_type, - size, - gfc_conv_descriptor_lbound_get (dest, rank)); - size = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - size, gfc_index_one_node); + size = gfc_conv_descriptor_extent_get (dest, rank); if (GFC_TYPE_ARRAY_RANK (type) > 1) size = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, size, diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index f61a1b08599f..bb8b3443d7ea 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -922,7 +922,7 @@ gfc_trans_lock_unlock (gfc_code *code, gfc_exec_op op) /* For arrays, obtain the array index. */ if (gfc_expr_attr (code->expr1).dimension) { - tree desc, tmp, extent, lbound, ubound; + tree desc, tmp, extent, lbound; gfc_array_ref *ar, ar2; int i, rank; @@ -958,8 +958,7 @@ gfc_trans_lock_unlock (gfc_code *code, gfc_exec_op op) TREE_TYPE (tmp), index, tmp); if (i < ar->dimen - 1) { - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); - tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL); + tmp = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[i]); extent = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp), extent, tmp); } @@ -1123,7 +1122,7 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op) /* For arrays, obtain the array index. */ if (gfc_expr_attr (code->expr1).dimension) { - tree desc, tmp, extent, lbound, ubound; + tree desc, tmp, extent, lbound; gfc_array_ref *ar, ar2; int i; @@ -1156,8 +1155,7 @@ gfc_trans_event_post_wait (gfc_code *code, gfc_exec_op op) TREE_TYPE (tmp), index, tmp); if (i < ar->dimen - 1) { - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[i]); - tmp = gfc_conv_array_extent_dim (lbound, ubound, NULL); + tmp = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[i]); extent = fold_build2_loc (input_location, MULT_EXPR, TREE_TYPE (tmp), extent, tmp); }