From patchwork Mon Sep 30 05:39:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 278919 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9A9392C00C3 for ; Mon, 30 Sep 2013 15:39:28 +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:from :to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type; q=dns; s=default; b=Mm++hVDBe4wgpzDr igZL+TMEo1AIiChnjngUVaBzNitdroH4W2BK+vYSjxAXhwmb4+J+0Y8li5KjokAe 4i9IcUVaC3FozeZvf7ZyDczzdSm97QDW0c1AVD/xqD1KA7z/EM4QisyiiOfiX05k Npa70H1DQTOQo5myYjEHB2tHzBE= 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:references:in-reply-to:subject:date:message-id :mime-version:content-type; s=default; bh=b8eFtxbrMzK7Hy0/SLTRbu p+yGE=; b=ezRUWC7MbdhEC9C19tF6EsCdYggMHpiNnpNrlg9x3zCQex9e8QXVja dYP0CXGZXogE4FdF4yl+7MwWfsALKBYrkRjdjEGFflGybioUHwmdqHuUfTBiyK0C 0dgNgTyzB298idT/9+4/zKWlQE9knen2/hBWU4v/UzRod3h+S2SgE= Received: (qmail 2550 invoked by alias); 30 Sep 2013 05:39:21 -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 2532 invoked by uid 89); 30 Sep 2013 05:39:21 -0000 Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Sep 2013 05:39:21 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_05, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 30 Sep 2013 06:39:17 +0100 Received: from SHAWIN162 ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 30 Sep 2013 06:39:15 +0100 From: "bin.cheng" To: "'Richard Biener'" Cc: "GCC Patches" References: <001501ceb906$56da1c00$048e5400$@arm.com> <002701cebb3f$6fcd6ab0$4f684010$@arm.com> In-Reply-To: Subject: RE: [PATCH]Fix computation of offset in ivopt Date: Mon, 30 Sep 2013 13:39:02 +0800 Message-ID: <002901cebd9f$5f7cb0a0$1e7611e0$@arm.com> MIME-Version: 1.0 X-MC-Unique: 113093006391700201 X-IsSubscribed: yes > -----Original Message----- > From: Richard Biener [mailto:richard.guenther@gmail.com] > Sent: Friday, September 27, 2013 4:30 PM > To: Bin Cheng > Cc: GCC Patches > Subject: Re: [PATCH]Fix computation of offset in ivopt > > On Fri, Sep 27, 2013 at 7:07 AM, bin.cheng wrote: > > > > > > case INTEGER_CST: > > //....... > > *offset = int_cst_value (expr); > > change to > > case INTEGER_CST: > > //....... > > *offset = sext_hwi (int_cst_value (expr), type); > > > > and > > case MULT_EXPR: > > //....... > > *offset = sext_hwi (int_cst_value (expr), type); to > > case MULT_EXPR: > > //....... > > HOST_WIDE_INT xxx = (HOST_WIDE_INT)off0 * int_cst_value (op1); > > *offset = sext_hwi (xxx, type); > > > > Any comments? > > The issue is of course that we end up converting offsets to sizetype at some > point which makes them all appear unsigned. The fix for this is to simply > interpret them as signed ... but it's really a mess ;) > Hi, this is updated patch which calculates signed offset in strip_offset_1 then sign extend it in strip_offset. Bootstrap and test on x86_64/x86/arm. Is it OK? Thanks. bin 2013-09-30 Bin Cheng * tree-ssa-loop-ivopts.c (strip_offset_1): Change parameter type. Count DECL_FIELD_BIT_OFFSET when computing offset for COMPONENT_REF. (strip_offset): Sign extend before return. Index: gcc/tree-ssa-loop-ivopts.c =================================================================== --- gcc/tree-ssa-loop-ivopts.c (revision 202599) +++ gcc/tree-ssa-loop-ivopts.c (working copy) @@ -2037,12 +2037,12 @@ find_interesting_uses (struct ivopts_data *data) static tree strip_offset_1 (tree expr, bool inside_addr, bool top_compref, - unsigned HOST_WIDE_INT *offset) + HOST_WIDE_INT *offset) { tree op0 = NULL_TREE, op1 = NULL_TREE, tmp, step; enum tree_code code; tree type, orig_type = TREE_TYPE (expr); - unsigned HOST_WIDE_INT off0, off1, st; + HOST_WIDE_INT off0, off1, st; tree orig_expr = expr; STRIP_NOPS (expr); @@ -2133,19 +2133,26 @@ strip_offset_1 (tree expr, bool inside_addr, bool break; case COMPONENT_REF: - if (!inside_addr) - return orig_expr; + { + tree field; + HOST_WIDE_INT boffset = 0; + if (!inside_addr) + return orig_expr; - tmp = component_ref_field_offset (expr); - if (top_compref - && cst_and_fits_in_hwi (tmp)) - { - /* Strip the component reference completely. */ - op0 = TREE_OPERAND (expr, 0); - op0 = strip_offset_1 (op0, inside_addr, top_compref, &off0); - *offset = off0 + int_cst_value (tmp); - return op0; - } + tmp = component_ref_field_offset (expr); + field = TREE_OPERAND (expr, 1); + if (top_compref + && cst_and_fits_in_hwi (tmp) + && cst_and_fits_in_hwi (DECL_FIELD_BIT_OFFSET (field))) + { + /* Strip the component reference completely. */ + op0 = TREE_OPERAND (expr, 0); + op0 = strip_offset_1 (op0, inside_addr, top_compref, &off0); + boffset = int_cst_value (DECL_FIELD_BIT_OFFSET (field)); + *offset = off0 + int_cst_value (tmp) + boffset / BITS_PER_UNIT; + return op0; + } + } break; case ADDR_EXPR: @@ -2196,7 +2203,16 @@ strip_offset_1 (tree expr, bool inside_addr, bool static tree strip_offset (tree expr, unsigned HOST_WIDE_INT *offset) { - return strip_offset_1 (expr, false, false, offset); + HOST_WIDE_INT off; + tree core = strip_offset_1 (expr, false, false, &off); + + /* Sign extend off if expr is in type which has lower precision + than HOST_WIDE_INT. */ + if (TYPE_PRECISION (TREE_TYPE (expr)) <= HOST_BITS_PER_WIDE_INT) + off = sext_hwi (off, TYPE_PRECISION (TREE_TYPE (expr))); + + *offset = off; + return core; } /* Returns variant of TYPE that can be used as base for different uses.