From patchwork Wed Oct 12 22:34:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 119317 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 19F06B6F77 for ; Thu, 13 Oct 2011 09:35:13 +1100 (EST) Received: (qmail 12231 invoked by alias); 12 Oct 2011 22:35:08 -0000 Received: (qmail 12197 invoked by uid 22791); 12 Oct 2011 22:35:07 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Oct 2011 22:34:51 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 12 Oct 2011 15:34:51 -0700 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by fmsmga001.fm.intel.com with ESMTP; 12 Oct 2011 15:34:50 -0700 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id D0E92C2098; Wed, 12 Oct 2011 15:34:50 -0700 (PDT) Date: Wed, 12 Oct 2011 15:34:50 -0700 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: PATCH: PR rtl-optimization/50696: [x32] Unnecessary lea Message-ID: <20111012223450.GA11516@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 Hi, When combine tries to combine: (insn 37 35 39 3 (set (reg:SI 90) (plus:SI (mult:SI (reg/v:SI 84 [ i ]) (const_int 4 [0x4])) (reg:SI 106))) x.i:11 247 {*leasi_2} (nil)) (insn 39 37 41 3 (set (mem:SI (zero_extend:DI (reg:SI 90)) [3 MEM[symbol: x, index: D.2741_12, step: 4, offset: 4294967292B]+0 S4 A32]) (reg/v:SI 84 [ i ])) x.i:11 64 {*movsi_internal} (expr_list:REG_DEAD (reg:SI 90) (nil))) it optimizes (zero_extend:DI (plus:SI (mult:SI (reg/v:SI 84 [ i ]) (const_int 4 [0x4])) (reg:SI 106))) into (and:DI (plus:DI (subreg:DI (mult:SI (reg/v:SI 85 [ i ]) (const_int 4 [0x4])) 0) (subreg:DI (reg:SI 106) 0)) (const_int 4294967292 [0xfffffffc])) in make_compound_operation. X86 backend doesn't accept the new expression as valid address while (zero_extend:DI) works just fine. This patches keeps ZERO_EXTEND when zero-extending address to Pmode. It reduces number of lea from 24173 to 21428 in x32 libgfortran.so. Does it make any senses? Thanks. H.J. --- 2011-10-12 H.J. Lu PR rtl-optimization/50696 * combine.c (subst): If an address is zero-extended to Pmode, replace FROM with while keeping ZERO_EXTEND. diff --git a/gcc/combine.c b/gcc/combine.c index 6c3b17c..45180e5 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -5078,6 +5078,23 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) } } } +#ifdef POINTERS_EXTEND_UNSIGNED + else if (POINTERS_EXTEND_UNSIGNED > 0 + && code == MEM + && GET_CODE (XEXP (x, 0)) == ZERO_EXTEND + && GET_MODE (XEXP (x, 0)) == Pmode) + { + /* If an address is zero-extended to Pmode, replace FROM with + TO while keeping ZERO_EXTEND. */ + new_rtx = subst (XEXP (XEXP (x, 0), 0), from, to, 0, 0, + unique_copy); + /* Drop ZERO_EXTEND on constant. */ + if (CONST_INT_P (new_rtx)) + SUBST (XEXP (x, 0), new_rtx); + else + SUBST (XEXP (XEXP (x, 0), 0), new_rtx); + } +#endif else { len = GET_RTX_LENGTH (code);