From patchwork Thu Mar 17 21:30:02 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: 87433 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 959ECB6FE0 for ; Fri, 18 Mar 2011 08:30:19 +1100 (EST) Received: (qmail 1857 invoked by alias); 17 Mar 2011 21:30:11 -0000 Received: (qmail 1841 invoked by uid 22791); 17 Mar 2011 21:30:10 -0000 X-SWARE-Spam-Status: No, hits=-4.5 required=5.0 tests=AWL, BAYES_00, NO_DNS_FOR_FROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Mar 2011 21:30:04 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 17 Mar 2011 14:30:02 -0700 X-ExtLoop1: 1 Received: from gnu-6.sc.intel.com ([10.3.194.135]) by fmsmga002.fm.intel.com with ESMTP; 17 Mar 2011 14:30:02 -0700 Received: by gnu-6.sc.intel.com (Postfix, from userid 500) id 35666180BD4; Thu, 17 Mar 2011 14:30:02 -0700 (PDT) Date: Thu, 17 Mar 2011 14:30:02 -0700 From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: RFC: PATCH: PR rtl-optimization/48155: Reload doesn't handle subreg properly Message-ID: <20110317213002.GA3755@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, Reload tries to handle plus operation such as: (plus (subreg (plus (reg) (const_int NNN))) (const_int NNN)) and nothing good comes out of it. I am not quite happy with this patch. Any comments? Thanks. H.J. --- commit 17ee20b0bd58b0e5d5bbdd79014eb370ab590001 Author: H.J. Lu Date: Thu Mar 17 13:57:14 2011 -0700 Add and use reload_plus_ok. diff --git a/gcc/ChangeLog.x32 b/gcc/ChangeLog.x32 index 52ff01d..6d5eda6 100644 --- a/gcc/ChangeLog.x32 +++ b/gcc/ChangeLog.x32 @@ -1,5 +1,12 @@ 2011-03-16 H.J. Lu + PR rtl-optimization/48155 + * reload1.c (reload_plus_ok): New. + (gen_reload_chain_without_interm_reg_p): Use it. + (gen_reload): Likewise. + +2011-03-16 H.J. Lu + PR middle-end/48016 * function.c (expand_function_start): Properly store frame pointer for non-local goto. diff --git a/gcc/reload1.c b/gcc/reload1.c index 3d58e58..14537bd 100644 --- a/gcc/reload1.c +++ b/gcc/reload1.c @@ -5516,6 +5516,54 @@ substitute (rtx *where, const_rtx what, rtx repl) } } +/* Return TRUE if IN is a valid plus operation. */ + +static bool +reload_plus_ok (rtx in) +{ + if (GET_CODE (in) == PLUS) + { + rtx op0 = XEXP (in, 0); + rtx op1 = XEXP (in, 1); + if ((REG_P (op0) + || GET_CODE (op0) == SUBREG + || MEM_P (op0)) + && (REG_P (op1) + || GET_CODE (op1) == SUBREG + || CONSTANT_P (op1) + || MEM_P (op1))) + { + rtx subreg, other; + if (GET_CODE (op0) == SUBREG) + { + subreg = SUBREG_REG (op0); + other = op1; + } + else if (GET_CODE (op1) == SUBREG) + { + subreg = SUBREG_REG (op1); + other = op0; + } + else + return true; + + /* Avoid + (plus (subreg (plus (reg) + (const_int NNN))) + (const_int NNN)) + */ + if (GET_CODE (subreg) == PLUS + && (CONSTANT_P (XEXP (subreg, 0)) + || CONSTANT_P (XEXP (subreg, 1))) + && CONSTANT_P (other)) + return false; + + return true; + } + } + return false; +} + /* The function returns TRUE if chain of reload R1 and R2 (in any order) can be evaluated without usage of intermediate register for the reload containing another reload. It is important to see @@ -5572,14 +5620,7 @@ gen_reload_chain_without_interm_reg_p (int r1, int r2) && (tem = gen_lowpart_common (GET_MODE (SUBREG_REG (in)), out)) != 0) in = SUBREG_REG (in), out = tem; - if (GET_CODE (in) == PLUS - && (REG_P (XEXP (in, 0)) - || GET_CODE (XEXP (in, 0)) == SUBREG - || MEM_P (XEXP (in, 0))) - && (REG_P (XEXP (in, 1)) - || GET_CODE (XEXP (in, 1)) == SUBREG - || CONSTANT_P (XEXP (in, 1)) - || MEM_P (XEXP (in, 1)))) + if (reload_plus_ok (in)) { insn = emit_insn (gen_rtx_SET (VOIDmode, out, in)); code = recog_memoized (insn); @@ -8456,14 +8497,7 @@ gen_reload (rtx out, rtx in, int opnum, enum reload_type type) ??? At some point, this whole thing needs to be rethought. */ - if (GET_CODE (in) == PLUS - && (REG_P (XEXP (in, 0)) - || GET_CODE (XEXP (in, 0)) == SUBREG - || MEM_P (XEXP (in, 0))) - && (REG_P (XEXP (in, 1)) - || GET_CODE (XEXP (in, 1)) == SUBREG - || CONSTANT_P (XEXP (in, 1)) - || MEM_P (XEXP (in, 1)))) + if (reload_plus_ok (in)) { /* We need to compute the sum of a register or a MEM and another register, constant, or MEM, and put it into the reload