From patchwork Thu Nov 5 13:22:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 540422 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6AC5C1406AA for ; Fri, 6 Nov 2015 00:22:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=JLSlxF/9; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; q=dns; s=default; b=fHU MGcFbA7Wukvdr2kOaR5BvLw0LVOzXTTld8TI1vs/4opE3D0W+WunXPnWdgC3cgUM MLh/mQjFEc2AvWSxujB+FUP/h8p9IaM9D1PECsRwcBQB/T3yDc7kn+F6p4mjDfgD xLRZRuFq/YJ6NQXEnCLHm+f8mwPDlZHA5SnLmxfc= 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:from :to:cc:subject:date:message-id:in-reply-to:references :content-type:content-transfer-encoding; s=default; bh=2wZP+87oD 8fYol7+WlolPFQJpIc=; b=JLSlxF/9KrbbK+enEtnb9HL28K/Q47ydU2pT1Fvfn YQ5CPf8tir5GOFQfl5jR5fkatEWBQkmNUrXidYZyxYw0LQE8nxK1yK2GhmQcjAtu TRa/KfoUMGiVI1qg5zn6HpkgBApP6gglgCK3INVStMrGF8k0xaK09TYYZ5fX48uM zc= Received: (qmail 12810 invoked by alias); 5 Nov 2015 13:22:47 -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 12720 invoked by uid 89); 5 Nov 2015 13:22:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Nov 2015 13:22:44 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-12-M7CLqrf9TB6TGV0wUKDJZQ-1; Thu, 05 Nov 2015 13:22:38 +0000 Received: from arm.com ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 5 Nov 2015 13:22:38 +0000 From: Alan Lawrence To: gcc-patches@gcc.gnu.org Cc: ebotcazou@adacore.com, richard.guenther@gmail.com Subject: Re: [PATCH 5/6]tree-sra.c: Fix completely_scalarize for negative array indices Date: Thu, 5 Nov 2015 13:22:30 +0000 Message-Id: <1446729750-13142-1-git-send-email-alan.lawrence@arm.com> In-Reply-To: <3023113.g35eVF8oGX@polaris> References: <3023113.g35eVF8oGX@polaris> X-MC-Unique: M7CLqrf9TB6TGV0wUKDJZQ-1 X-IsSubscribed: yes On 30/10/15 10:54, Eric Botcazou wrote: > On 30/10/15 10:44, Richard Biener wrote: >> >> I think you want to use wide-ints here and >> >> wide_int idx = wi::from (minidx, TYPE_PRECISION (TYPE_DOMAIN >> (...)), TYPE_SIGN (TYPE_DOMAIN (..))); >> wide_int maxidx = ... >> >> you can then simply iterate minidx with ++ and do the final compare >> against maxidx >> with while (++idx <= maxidx). For the array ref index we want to use >> TYPE_DOMAIN >> as type as well, not size_int. Thus wide_int_to_tree (TYPE_DOMAIN (...)..idx). [...] > But using offset_int should be OK, see for example get_ref_base_and_extent. > Here's a patch using offset_int. (Not as easy to construct as wide_int::from, the sign-extend is what appeared to be done elsewhere that constructs offset_ints). Tested by bootstrap+check-{gcc,g++,ada,fortran} with the rest of the patchset (which causes an array[-1..1] to be completely scalarized, among others), on x86_64 and ARM. I don't have a test without all that (such would have to be in Ada, and trigger SRA of such an array but not involving the constant pool); is it OK without? gcc/ChangeLog: * tree-sra.c (completely_scalarize): Properly handle negative array indices using offset_int. --- gcc/tree-sra.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index e15df1f..6168a7e 100644 --- a/gcc/tree-sra.c +++ b/gcc/tree-sra.c @@ -1010,18 +1010,25 @@ completely_scalarize (tree base, tree decl_type, HOST_WIDE_INT offset, tree ref) if (maxidx) { gcc_assert (TREE_CODE (maxidx) == INTEGER_CST); - /* MINIDX and MAXIDX are inclusive. Try to avoid overflow. */ - unsigned HOST_WIDE_INT lenp1 = tree_to_shwi (maxidx) - - tree_to_shwi (minidx); - unsigned HOST_WIDE_INT idx = 0; - do + tree domain = TYPE_DOMAIN (decl_type); + /* MINIDX and MAXIDX are inclusive, and must be interpreted in + DOMAIN (e.g. signed int, whereas min/max may be size_int). */ + offset_int idx = wi::to_offset (minidx); + offset_int max = wi::to_offset (maxidx); + if (!TYPE_UNSIGNED (domain)) { - tree nref = build4 (ARRAY_REF, elemtype, ref, size_int (idx), + idx = wi::sext (idx, TYPE_PRECISION (domain)); + max = wi::sext (max, TYPE_PRECISION (domain)); + } + for (int el_off = offset; wi::les_p (idx, max); ++idx) + { + tree nref = build4 (ARRAY_REF, elemtype, + ref, + wide_int_to_tree (domain, idx), NULL_TREE, NULL_TREE); - int el_off = offset + idx * el_size; scalarize_elem (base, el_off, el_size, nref, elemtype); + el_off += el_size; } - while (++idx <= lenp1); } } break;