From patchwork Thu Oct 29 19:18:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Lawrence X-Patchwork-Id: 537985 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 D2F6D1402DD for ; Fri, 30 Oct 2015 06:21:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LDcogM6V; 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:subject:date:message-id:in-reply-to:references:content-type :content-transfer-encoding; q=dns; s=default; b=llLviWDeFdyY4768 0Ut+bi9cWzYrulT2Lv5NTbJLsAMgUrD9ICHOSvXJCVyFHLQ8xLAqlxajz3EYRaT7 LP1fsco7yCB1vkeUDbGWELlZa/iSzlyj8TCH4kHSRAg+C8BRVtEedrslVCcACP5C MvmjAt4PC+IM8OMobUUe10u1I+k= 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:subject:date:message-id:in-reply-to:references:content-type :content-transfer-encoding; s=default; bh=gypSyD7G0ThhSz+F/ZFrYJ eOokM=; b=LDcogM6VolBSjSh9TR47l5iXd9rjL2Xtswlja0xcOPygEp2J/GcW/r 7ALeLY8OPTd677ZF/wauXRsE0AfN+aHkosSISWcKk5r58iqxKoeJOkCKCRoCDttZ b8yGBYBXz7hKE+Y4/wqFDrnd4+mv9zd12ctJi+kuNPWuktUYUbVjM= Received: (qmail 104987 invoked by alias); 29 Oct 2015 19:20:50 -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 104898 invoked by uid 89); 29 Oct 2015 19:20:49 -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) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Oct 2015 19:20:48 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-7-Pm-HUXAhQvqvCgwXS07R4g-9; Thu, 29 Oct 2015 19:20:43 +0000 Received: from arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 29 Oct 2015 19:20:41 +0000 From: Alan Lawrence To: gcc-patches@gcc.gnu.org Subject: [PATCH 5/6]tree-sra.c: Fix completely_scalarize for negative array indices Date: Thu, 29 Oct 2015 19:18:21 +0000 Message-Id: <1446146302-17002-6-git-send-email-alan.lawrence@arm.com> In-Reply-To: <1446146302-17002-1-git-send-email-alan.lawrence@arm.com> References: <1446146302-17002-1-git-send-email-alan.lawrence@arm.com> X-MC-Unique: Pm-HUXAhQvqvCgwXS07R4g-9 X-IsSubscribed: yes The code I added to completely_scalarize for arrays isn't right in some cases of negative array indices (e.g. arrays with indices from -1 to 1 in the Ada testsuite). On ARM, this prevents a failure bootstrapping Ada with the next patch, as well as a few ACATS tests (e.g. c64106a). Some discussion here: https://gcc.gnu.org/ml/gcc/2015-10/msg00096.html . gcc/ChangeLog: * tree-sra.c (completely_scalarize): Deal properly with negative array indices. --- gcc/tree-sra.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/tree-sra.c b/gcc/tree-sra.c index e15df1f..358db79 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); + /* MINIDX and MAXIDX are inclusive, and must be interpreted in the + TYPE_DOMAIN (e.g. signed int, whereas min/max may be size_int). + Try also to avoid overflow. */ + minidx = build_int_cst (TYPE_DOMAIN (decl_type), + tree_to_shwi (minidx)); + maxidx = build_int_cst (TYPE_DOMAIN (decl_type), + tree_to_shwi (maxidx)); + HOST_WIDE_INT min = tree_to_shwi (minidx); + unsigned HOST_WIDE_INT lenlessone = tree_to_shwi (maxidx) - min; unsigned HOST_WIDE_INT idx = 0; do { - tree nref = build4 (ARRAY_REF, elemtype, ref, size_int (idx), + tree nref = build4 (ARRAY_REF, elemtype, + ref, size_int (idx + min), NULL_TREE, NULL_TREE); int el_off = offset + idx * el_size; scalarize_elem (base, el_off, el_size, nref, elemtype); } - while (++idx <= lenp1); + while (++idx <= lenlessone); } } break;