From patchwork Tue May 7 09:58:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 242172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 422032C00AB for ; Tue, 7 May 2013 20:58:54 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Gf8T+FkdpL6BNnDWxvlMDjjsBCh4OoBIc+ZlDexRXs4nzY gJVKVYIURp2qQk2021sMAY+PHp89g47ZOTBktKbL98NSgudFEPEkAYesZKtH/TQI giYJM8TszUtUeH8b5xmzjB5UBtvjhQiqqBzsF77ChYxdxDAzjJ2NVF14oIi0Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=+YES73OfHiTWk0Ngk3G2/krngM0=; b=h1N4KROgLbCDdzfLFzYl JdUY+UMmLV6fCkn7IXLjT+Ih+m1+caugooD6kCqey0cFvGbTyUIzjenOFDZR2bP4 0sMrWhbyRamMNuetIoIli70aaqsL8giCg+UdYOHz7XRh9qOfn42oXfi+NChkzYJs PofyovfYVo7q7654fD+fuRc= Received: (qmail 12591 invoked by alias); 7 May 2013 09:58:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 12574 invoked by uid 89); 7 May 2013 09:58:52 -0000 X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 07 May 2013 09:58:50 +0000 Received: from archimedes.net-b.de (port-92-195-76-58.dynamic.qsc.de [92.195.76.58]) by mx02.qsc.de (Postfix) with ESMTP id 5AD7E27720; Tue, 7 May 2013 11:58:47 +0200 (CEST) Message-ID: <5188D056.7090006@net-b.de> Date: Tue, 07 May 2013 11:58:46 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Fortran-Dev, committed] Set elem_len and use proper element size for stride handling X-Virus-Found: No This patch properly sets the elem_len in gfc_array_init_size; it probably could restricted to do so only for BT_CLASS and for deferred-length BT_CHARACTER as otherwise the correct elem_len is set. Additionally, the stride handling now uses elem_len to convert from/to the stride multiplier instead of the declared TYPE_UNIT_SIZE. The latter doesn't properly work for strings (at least not in all cases) and (never) for polymorphic variables. The code keeps using the declared size for nonstrings/record types. The reason is that the declared size is a compile-time constant. Using elem_len would otherwise cause problems, e.g., with vectorization as the vectorizer cannot see that the memory access is contiguous. (The other patch removes some code which used to be: new_ubound = old_ubound + (old_lbound-new_lbound); with the change of the array descriptor to extents, the code was now effectively "new_extent = old_extent", which is pointless.) This patch brings down the regression-test failures from 15 to 6. Still failing are: gfortran.dg/auto_char_len_3.f90 gfortran.dg/mvbits_7.f90 gfortran.dg/mvbits_8.f90 gfortran.dg/proc_decl_23.f90 gfortran.dg/subref_array_pointer_2.f90 gfortran.dg/transfer_intrinsic_3.f90 gfortran.dg/unlimited_polymorphic_1.f03 Besides solving those regressions, the main task is still outstanding: Removal of "offset". Additional tasks are lower_bound == 0 for actuals to nonpointer/nonallocatables dummies and the proper handling of subpointers (i.e. sm != n*elem_len). Committed as Rev. 198669 after building and regtesting on x86-64-gnu-linux. Additionally, I have updated the branch to the trunk, Rev. 198670. Tobias 2013-05-07 Tobias Burnus * trans-array.c (gfc_conv_descriptor_stride_get, gfc_conv_descriptor_stride_set): Use elem_len, unless it is a nonstring intrinsic type for which size_in_bytes is used. (gfc_array_init_size): Set elem_len before handling the strides. * trans-expr.c (gfc_conv_subref_array_arg): Remove no-op extent shifting code. diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 08f12aa..db8de69 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -422,7 +422,11 @@ gfc_conv_descriptor_stride_get (tree desc, tree dim) return gfc_index_one_node; tmp = gfc_get_element_type (type); - size = size_in_bytes (tmp); + if (TREE_CODE (tmp) != RECORD_TYPE && !TYPE_STRING_FLAG (tmp)) + size = size_in_bytes (tmp); + else + size = gfc_conv_descriptor_elem_len_get (desc); + size = fold_convert (gfc_array_index_type, size); tmp = fold_build2_loc (input_location, FLOOR_DIV_EXPR, gfc_array_index_type, gfc_conv_descriptor_sm_get (desc, dim), size); @@ -440,7 +444,11 @@ gfc_conv_descriptor_stride_set (stmtblock_t *block, tree desc, { tree tmp; tmp = gfc_get_element_type (TREE_TYPE (desc)); - tmp = size_in_bytes (tmp); + if (TREE_CODE (tmp) != RECORD_TYPE && !TYPE_STRING_FLAG (tmp)) + tmp = size_in_bytes (tmp); + else + tmp = gfc_conv_descriptor_elem_len_get (desc); + tmp = fold_build2_loc (input_location, MULT_EXPR, gfc_array_index_type, fold_convert (gfc_array_index_type, value), fold_convert (gfc_array_index_type, tmp)); @@ -5117,6 +5125,34 @@ gfc_array_init_size (tree descriptor, gfc_typespec *ts, tmp = gfc_conv_descriptor_dtype (descriptor); gfc_add_modify (descriptor_block, tmp, gfc_get_dtype (ts)); + if (expr3_elem_size != NULL_TREE) + tmp = expr3_elem_size; + else if (expr3 != NULL) + { + if (expr3->ts.type == BT_CLASS) + { + gfc_se se_sz; + gfc_expr *sz = gfc_copy_expr (expr3); + gfc_add_vptr_component (sz); + gfc_add_size_component (sz); + gfc_init_se (&se_sz, NULL); + gfc_conv_expr (&se_sz, sz); + gfc_free_expr (sz); + tmp = se_sz.expr; + } + else + { + tmp = gfc_typenode_for_spec (&expr3->ts); + tmp = TYPE_SIZE_UNIT (tmp); + } + } + else + tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type)); + + /* Convert to size_t. */ + element_size = fold_convert (size_type_node, tmp); + gfc_conv_descriptor_elem_len_set (descriptor_block, descriptor, element_size); + or_expr = boolean_false_node; for (n = 0; n < rank; n++) @@ -5249,36 +5285,6 @@ gfc_array_init_size (tree descriptor, gfc_typespec *ts, } } - /* The stride is the number of elements in the array, so multiply by the - size of an element to get the total size. Obviously, if there is a - SOURCE expression (expr3) we must use its element size. */ - if (expr3_elem_size != NULL_TREE) - tmp = expr3_elem_size; - else if (expr3 != NULL) - { - if (expr3->ts.type == BT_CLASS) - { - gfc_se se_sz; - gfc_expr *sz = gfc_copy_expr (expr3); - gfc_add_vptr_component (sz); - gfc_add_size_component (sz); - gfc_init_se (&se_sz, NULL); - gfc_conv_expr (&se_sz, sz); - gfc_free_expr (sz); - tmp = se_sz.expr; - } - else - { - tmp = gfc_typenode_for_spec (&expr3->ts); - tmp = TYPE_SIZE_UNIT (tmp); - } - } - else - tmp = TYPE_SIZE_UNIT (gfc_get_element_type (type)); - - /* Convert to size_t. */ - element_size = fold_convert (size_type_node, tmp); - if (rank == 0) return element_size; diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 2370f44..07f3ead 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -3772,12 +3772,6 @@ gfc_conv_subref_array_arg (gfc_se * parmse, gfc_expr * expr, int g77, offset = gfc_index_zero_node; for (n = 0; n < dimen; n++) { - tmp = gfc_conv_descriptor_extent_get (parmse->expr, - gfc_rank_cst[n]); - gfc_conv_descriptor_ubound_set (&parmse->pre, - parmse->expr, - gfc_rank_cst[n], - tmp); gfc_conv_descriptor_lbound_set (&parmse->pre, parmse->expr, gfc_rank_cst[n],