From patchwork Sun Nov 11 15:01:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 198285 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]) by ozlabs.org (Postfix) with SMTP id 675842C008C for ; Mon, 12 Nov 2012 02:05:58 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1353251161; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Cc:Subject:Date:Message-ID:User-Agent: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=vVntEr11141FGuN27EwL165Bg38=; b=hr7stJt/DdWGkzD eSE7oRSUO1vrLvuEtKbzBvW1GUb9ZGLM/k/NUspnLrKvZ5QYc40qNyVVgNECf7Wh YSEZ6j3LcjpdQNawsDSTmPXMc7on7ivcw3b89acCde0BkReQ9P2EJNK/NaqriU3m EjTzr/3E+JfRWnxc4aRLeFWvE7GM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:From:To:Cc:Subject:Date:Message-ID:User-Agent:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=iScgVGOZ7xM3Y9RpfbN6EjxIILg7YHvOIAj6Rw6oyfcucTWyY+sZ1+KSpE8orT jKkyuOnWU54HbgCVVU4XvLci1dR1luHF7dSueHaorR7V8sa+tfM4vYFx4a9n1qr1 2Jm6QF687wJ/+eji60fRD+Io1fg7NI5yNtc4ZoK3H0K9s=; Received: (qmail 19762 invoked by alias); 11 Nov 2012 15:05:51 -0000 Received: (qmail 19751 invoked by uid 22791); 11 Nov 2012 15:05:50 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 11 Nov 2012 15:05:42 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id BA374CB0C01; Sun, 11 Nov 2012 16:05:43 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YQzA393hQnNH; Sun, 11 Nov 2012 16:05:43 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 86E37CB02B3; Sun, 11 Nov 2012 16:05:42 +0100 (CET) From: Eric Botcazou To: "H.J. Lu" Cc: gcc-patches@gcc.gnu.org, Paolo Bonzini Subject: Re: PATCH: Handle ZERO_EXTEND offsettable address Date: Sun, 11 Nov 2012 16:01:48 +0100 Message-ID: <6538840.4Rt7JtybtJ@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.16-desktop; KDE/4.7.2; x86_64; ; ) In-Reply-To: <20121110230457.GA1106@gmail.com> References: <20121110064405.GA22641@gmail.com> <20121110230457.GA1106@gmail.com> MIME-Version: 1.0 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 > This patch also handles SIGN_EXTEND. Tested on Linux/x32. OK to > install? I'd cautious here, that's uncharted territory and the SIGN_EXTEND case isn't covered by your testing. > 2012-11-10 H.J. Lu > > PR middle-end/55247 > PR middle-end/55259 > * emit-rtl.c (adjust_address_1): Handle ZERO_EXTEND and > SIGN_EXTEND. The new transformation is: (zero_extend ADDR) + CONST_INT -> (zero_extend (ADDR + CONST_INT)) but in convert_memory_address_addr_space we do the opposite: (zero_extend (ADDR + CONST_INT)) -> (zero_extend ADDR) + CONST_INT Which one is the canonical form in the end? > @@ -2109,6 +2111,20 @@ adjust_address_1 (rtx memref, enum machine_mode mode, > HOST_WIDE_INT offset, addr = gen_rtx_LO_SUM (address_mode, XEXP (addr, 0), > plus_constant (address_mode, > XEXP (addr, 1), offset)); > + /* We permute zero/sign-extension and addition operation only if > + converting the constant does not change it. */ > + else if ((GET_CODE (addr) == ZERO_EXTEND > + || GET_CODE (addr) == SIGN_EXTEND) > + && (x = GEN_INT (offset), > + x == convert_memory_address_addr_space (address_mode, > + x, > + attrs.addrspace))) > + { > + enum rtx_code code = GET_CODE (addr); > + addr = XEXP (addr, 0); > + addr = plus_constant (GET_MODE (addr), addr, offset); > + addr = gen_rtx_fmt_e (code, address_mode, addr); > + } You need to test the truncation here, not the extension. Moreover, the transformation is valid only under a no-overflow assumption, so I think we need to explicitly request pointer_mode (or else restrict the transformation to small offsets). > diff --git a/gcc/recog.c b/gcc/recog.c > index ee68e30..a916ef6 100644 > --- a/gcc/recog.c > +++ b/gcc/recog.c > @@ -1934,15 +1934,22 @@ int > offsettable_address_addr_space_p (int strictp, enum machine_mode mode, rtx > y, addr_space_t as) > { > - enum rtx_code ycode = GET_CODE (y); > + enum rtx_code ycode; > rtx z; > - rtx y1 = y; > + rtx y1; > rtx *y2; > int (*addressp) (enum machine_mode, rtx, addr_space_t) = > (strictp ? strict_memory_address_addr_space_p > > : memory_address_addr_space_p); > > unsigned int mode_sz = GET_MODE_SIZE (mode); > > + /* Allow zero-extended or sign-extended address. */ > + if (GET_CODE (y) == ZERO_EXTEND || GET_CODE (y) == SIGN_EXTEND) > + y = XEXP (y, 0); > + > + ycode = GET_CODE (y); > + y1 = y; > + > if (CONSTANT_ADDRESS_P (y)) > return 1; That's not fully correct since you don't test the final form of the address. You instead need to duplicate the adjust_address_1 change here: /* The offset added here is chosen as the maximum offset that any instruction could need to add when operating on something of the specified mode. We assume that if Y and Y+c are valid addresses then so is Y+d for all 0 0 + && GET_CODE (addr) == ZERO_EXTEND + && GET_MODE (XEXP (addr, 0)) == pointer_mode + && trunc_int_for_mode (offset, pointer_mode) == offset) + addr = gen_rtx_ZERO_EXTEND (address_mode, + plus_constant (pointer_mode, + XEXP (addr, 0), offset)); +#endif else addr = plus_constant (address_mode, addr, offset); } Index: recog.c =================================================================== --- recog.c (revision 193322) +++ recog.c (working copy) @@ -1943,6 +1943,9 @@ offsettable_address_addr_space_p (int st (strictp ? strict_memory_address_addr_space_p : memory_address_addr_space_p); unsigned int mode_sz = GET_MODE_SIZE (mode); +#ifdef POINTERS_EXTEND_UNSIGNED + enum machine_mode pointer_mode = targetm.addr_space.pointer_mode (as); +#endif if (CONSTANT_ADDRESS_P (y)) return 1; @@ -1992,6 +1995,15 @@ offsettable_address_addr_space_p (int st z = gen_rtx_LO_SUM (GET_MODE (y), XEXP (y, 0), plus_constant (GET_MODE (y), XEXP (y, 1), mode_sz - 1)); +#ifdef POINTERS_EXTEND_UNSIGNED + /* Likewise for a ZERO_EXTEND from pointer_mode. */ + else if (POINTERS_EXTEND_UNSIGNED > 0 + && GET_CODE (y) == ZERO_EXTEND + && GET_MODE (XEXP (y, 0)) == pointer_mode) + z = gen_rtx_ZERO_EXTEND (GET_MODE (y), + plus_constant (pointer_mode, XEXP (y, 0), + mode_sz - 1)); +#endif else z = plus_constant (GET_MODE (y), y, mode_sz - 1);