From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31712 invoked by alias); 15 Jul 2012 11:24:59 -0000 Received: (qmail 31695 invoked by uid 22791); 15 Jul 2012 11:24:57 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 15 Jul 2012 11:24:38 +0000 Received: from [192.168.178.22] (port-92-204-53-225.dynamic.qsc.de [92.204.53.225]) by mx02.qsc.de (Postfix) with ESMTP id 4FE6627971; Sun, 15 Jul 2012 13:24:35 +0200 (CEST) Message-ID: <5002A873.5000905@net-b.de> Date: Sun, 15 Jul 2012 11:24:00 -0000 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Fortran-dev][Patch] Some (ubound-lbound+1) -> extent cleanup Content-Type: multipart/mixed; boundary="------------040508020007010702060802" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-07/txt/msg00580.txt.bz2 This is a multi-part message in MIME format. --------------040508020007010702060802 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1153 This patch cleans up the source code and generated code ("dump") by changing (ubound-lbound+1) calculations to directly taking the "extent". Except for a faster -O0 performance and saving some cycles during code generation, the code should be the same. The only real code change I did was to gfc_grow_array. I didn't understand the previous code, I think the current code makes more sense. I believe the old code did: desc->extent = desc.extent + extra; realloc (&desc->data, (desc.extent + 1)*element_size); while I think the latter should be "+ extra" and not "+ 1". From the callee, I couldn't deduce whether extra is always unity in practice, in any case it doesn't look like. For fcncall_realloc_result, I didn't check whether the new code effectively matches the old one, I just followed the comment which states: "Check that the shapes are the same between lhs and expression.". There are some more cases, but there the code wasn't as obvious. For instance "extent = ubound - lbound"; there I was unsure whether that's a bug (missing "+1") or valid. Build and regtested with no new failures. OK for the branch? Tobias --------------040508020007010702060802 Content-Type: text/x-patch; name="extent-cleanup.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="extent-cleanup.diff" Content-length: 10663 2012-07-15 Tobias Burnus * trans-intrinsic.c (gfc_conv_intrinsic_size, gfc_conv_intrinsic_sizeof): Replace (ubound-lbound+1) calculation by "extent". * trans-expr.c (fcncall_realloc_result): Ditto. * trans-io.c (gfc_convert_array_to_string): Ditto. * trans-openmp.c (gfc_omp_clause_default_ctor, gfc_omp_clause_copy_ctor, gfc_omp_clause_assign_op, gfc_trans_omp_array_reduction): Ditto. * trans-array.c (array_parameter_size): Ditto. (gfc_grow_array): Ditto - and fix size calculation for realloc. 2012-07-15 Tobias Burnus * gfortran.dg/array_section_2.f90: Update scan-tree-dump pattern. Index: gcc/fortran/trans-intrinsic.c =================================================================== --- gcc/fortran/trans-intrinsic.c (Revision 189492) +++ gcc/fortran/trans-intrinsic.c (Arbeitskopie) @@ -5145,17 +5145,8 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * e if (se->expr == NULL_TREE) { - tree ubound, lbound; - - arg1 = build_fold_indirect_ref_loc (input_location, - arg1); - ubound = gfc_conv_descriptor_ubound_get (arg1, argse.expr); - lbound = gfc_conv_descriptor_lbound_get (arg1, argse.expr); - se->expr = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, ubound, lbound); - se->expr = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, - se->expr, gfc_index_one_node); + arg1 = build_fold_indirect_ref_loc (input_location, arg1); + se->expr = gfc_conv_descriptor_extent_get (arg1, argse.expr); se->expr = fold_build2_loc (input_location, MAX_EXPR, gfc_array_index_type, se->expr, gfc_index_zero_node); @@ -5194,8 +5185,6 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *e tree source_bytes; tree type; tree tmp; - tree lower; - tree upper; int n; arg = expr->value.function.actual->expr; @@ -5240,12 +5229,7 @@ gfc_conv_intrinsic_sizeof (gfc_se *se, gfc_expr *e { 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 = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, upper, lower); - tmp = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, tmp, gfc_index_one_node); + 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); Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (Revision 189481) +++ gcc/fortran/trans-expr.c (Arbeitskopie) @@ -6476,19 +6481,10 @@ fcncall_realloc_result (gfc_se *se, int rank) for (n = 0 ; n < rank; n++) { tree tmp1; - tmp = gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[n]); - tmp1 = gfc_conv_descriptor_lbound_get (res_desc, gfc_rank_cst[n]); - tmp = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, tmp, tmp1); - tmp1 = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[n]); - tmp = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, tmp, tmp1); - tmp1 = gfc_conv_descriptor_ubound_get (res_desc, gfc_rank_cst[n]); - tmp = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, tmp, tmp1); + tmp = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[n]); + tmp1 = gfc_conv_descriptor_extent_get (res_desc, gfc_rank_cst[n]); tmp = fold_build2_loc (input_location, NE_EXPR, - boolean_type_node, tmp, - gfc_index_zero_node); + boolean_type_node, tmp, tmp1); tmp = gfc_evaluate_now (tmp, &se->post); zero_cond = fold_build2_loc (input_location, TRUTH_OR_EXPR, boolean_type_node, tmp, Index: gcc/fortran/trans-io.c =================================================================== --- gcc/fortran/trans-io.c (Revision 189480) +++ gcc/fortran/trans-io.c (Arbeitskopie) @@ -639,16 +639,10 @@ gfc_convert_array_to_string (gfc_se * se, gfc_expr else { gcc_assert (GFC_DESCRIPTOR_TYPE_P (type)); - size = gfc_conv_array_stride (array, rank); - tmp = fold_build2_loc (input_location, MINUS_EXPR, - gfc_array_index_type, - gfc_conv_array_ubound (array, rank), - gfc_conv_array_lbound (array, rank)); - tmp = fold_build2_loc (input_location, PLUS_EXPR, - gfc_array_index_type, tmp, - gfc_index_one_node); size = fold_build2_loc (input_location, MULT_EXPR, - gfc_array_index_type, tmp, size); + gfc_array_index_type, + gfc_conv_array_stride (array, rank), + gfc_conv_array_extent (array, rank)); } gcc_assert (size); Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (Revision 189481) +++ gcc/fortran/trans-array.c (Arbeitskopie) @@ -1287,27 +1287,25 @@ gfc_grow_array (stmtblock_t * pblock, tree desc, t tree arg0, arg1; tree tmp; tree size; - tree ubound; + tree extent; if (integer_zerop (extra)) return; - ubound = gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[0]); + extent = gfc_conv_descriptor_extent_get (desc, gfc_rank_cst[0]); - /* Add EXTRA to the upper bound. */ - tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - ubound, extra); - gfc_conv_descriptor_ubound_set (pblock, desc, gfc_rank_cst[0], tmp); + /* Add EXTRA to the extent. */ + extent = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, + extent, extra); + gfc_conv_descriptor_extent_set (pblock, desc, gfc_rank_cst[0], extent); /* Get the value of the current data pointer. */ arg0 = gfc_conv_descriptor_data_get (desc); /* Calculate the new array size. */ size = TYPE_SIZE_UNIT (gfc_get_element_type (TREE_TYPE (desc))); - tmp = fold_build2_loc (input_location, PLUS_EXPR, gfc_array_index_type, - ubound, gfc_index_one_node); arg1 = fold_build2_loc (input_location, MULT_EXPR, size_type_node, - fold_convert (size_type_node, tmp), + fold_convert (size_type_node, extent), fold_convert (size_type_node, size)); /* Call the realloc() function. */ @@ -6927,13 +6925,7 @@ array_parameter_size (tree desc, gfc_expr *expr, t gfc_build_addr_expr (NULL, desc)); else { - tree ubound = gfc_conv_descriptor_ubound_get (desc, gfc_index_zero_node); - tree lbound = gfc_conv_descriptor_lbound_get (desc, gfc_index_zero_node); - - *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, gfc_index_zero_node); *size = fold_build2_loc (input_location, MAX_EXPR, gfc_array_index_type, *size, gfc_index_zero_node); } Index: gcc/fortran/trans-openmp.c =================================================================== --- gcc/fortran/trans-openmp.c (Revision 189480) +++ gcc/fortran/trans-openmp.c (Arbeitskopie) @@ -173,11 +173,7 @@ gfc_omp_clause_default_ctor (tree clause, tree dec gfc_add_modify (&cond_block, decl, outer); 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, gfc_conv_descriptor_stride_get (decl, rank)); @@ -230,11 +226,7 @@ gfc_omp_clause_copy_ctor (tree clause, tree dest, gfc_add_modify (&cond_block, dest, src); 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, gfc_conv_descriptor_stride_get (dest, rank)); @@ -287,11 +279,7 @@ gfc_omp_clause_assign_op (tree clause ATTRIBUTE_UN gfc_start_block (&block); 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, gfc_conv_descriptor_stride_get (dest, rank)); @@ -664,12 +652,7 @@ gfc_trans_omp_array_reduction (tree c, gfc_symbol gfc_add_modify (&block, decl, outer_sym.backend_decl); 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, Index: gcc/testsuite/gfortran.dg/array_section_2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/array_section_2.f90 (Revision 189480) +++ gcc/testsuite/gfortran.dg/array_section_2.f90 (Arbeitskopie) @@ -12,5 +12,5 @@ program test allocate(a(n), temp(n)) temp(1:size(a)) = a end program -! { dg-final { scan-tree-dump-times "MAX_EXPR\[^\n\t\]+extent\[^\n\t\]+, 0" 1 "original" } } +! { dg-final { scan-tree-dump-times "MAX_EXPR\[^\n\t\]+extent, 0" 1 "original" } } ! { dg-final { cleanup-tree-dump "original" } } --------------040508020007010702060802--