From patchwork Sat Oct 6 02:52:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 189661 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 5B77A2C0088 for ; Sat, 6 Oct 2012 12:52:39 +1000 (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=1350096759; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=2tNRURm CFp5NAiVP8MWPGQXFpB8=; b=xotwzlG2VeRki2rfxt24p0aTgHXOX2PyOHMMF0E bTptjjPAaxW/hju2Igml3AVnKZ64Kjm3KlPYS0Qgp4Q+Jz0R6qIbaZp3afXa5/VS LOzkmFkKFc5FOmIi2MQnu6J1f+gEGzWDWKy80QdZCb1+2f49hybW1SINom+QEM7l Lq9k= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=y5+8M2aWffwQwSMCbi9LhRuckQcvs73FAsZxvFUbwXtpxbPwF5SaWWayiG8Wen nzJLZscXzh9WCUpdUbcl5yWvN2OddLCFQO2F4O2VsFF7cWSCFZMKG2jFKarXD8a6 OpX4cd6aWUImPMtUZsN2+j0AgGFtpk4XBQM6eSsFgHfGk=; Received: (qmail 24500 invoked by alias); 6 Oct 2012 02:52:35 -0000 Received: (qmail 24492 invoked by uid 22791); 6 Oct 2012 02:52:34 -0000 X-SWARE-Spam-Status: No, hits=-7.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 06 Oct 2012 02:52:26 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q962qQYL009297 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 5 Oct 2012 22:52:26 -0400 Received: from Mair.local (vpn-8-90.rdu.redhat.com [10.11.8.90]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q962qO5Y026700 for ; Fri, 5 Oct 2012 22:52:25 -0400 Message-ID: <506F9CE9.4090108@redhat.com> Date: Fri, 05 Oct 2012 22:52:25 -0400 From: Vladimir Makarov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: GCC Patches Subject: [lra] patch to fix a bug X-IsSubscribed: yes 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 The following patch fixes a bug found on x86-64 in a big program with some options combination. The patch was successfully bootstrapped on x86/x86-64. The patch changes the code for about 30% of SPEC2000 tests. But these changes are quite small (in code size and performance point of view). The patch is committed as rev. 192153. 2012-10-05 Vladimir Makarov * lra-constraints.c (multi_block_pseudo_p, dead_pseudo_p): New functions. (insn_rhs_dead_pseudo_p, init_insn_rhs_dead_pseudo_p): Ditto. (lra_constraints): Use them. Index: lra-constraints.c =================================================================== --- lra-constraints.c (revision 192048) +++ lra-constraints.c (working copy) @@ -3590,6 +3590,83 @@ int lra_constraint_iter_after_spill; pseudo. */ bool lra_risky_transformations_p; +/* Return true if REGNO is referenced in more than one block. */ +static bool +multi_block_pseudo_p (int regno) +{ + basic_block bb = NULL; + unsigned int uid; + bitmap_iterator bi; + + if (regno < FIRST_PSEUDO_REGISTER) + return false; + + EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi) + if (bb == NULL) + bb = BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn); + else if (BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn) != bb) + return true; + return false; +} + +/* Return true if X contains a pseudo dying in INSN. */ +static bool +dead_pseudo_p (rtx x, rtx insn) +{ + int i, j; + const char *fmt; + enum rtx_code code; + + if (REG_P (x)) + return (insn != NULL_RTX + && find_regno_note (insn, REG_DEAD, REGNO (x)) != NULL_RTX); + code = GET_CODE (x); + fmt = GET_RTX_FORMAT (code); + for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) + { + if (fmt[i] == 'e') + { + if (dead_pseudo_p (XEXP (x, i), insn)) + return true; + } + else if (fmt[i] == 'E') + { + for (j = XVECLEN (x, i) - 1; j >= 0; j--) + if (dead_pseudo_p (XVECEXP (x, i, j), insn)) + return true; + } + } + return false; +} + +/* Return true if INSN contains a dying pseudo in INSN right hand + side. */ +static bool +insn_rhs_dead_pseudo_p (rtx insn) +{ + rtx set = single_set (insn); + + gcc_assert (set != NULL); + return dead_pseudo_p (SET_SRC (set), insn); +} + +/* Return true if any init insn of REGNO contains a dying pseudo in + insn right hand side. */ +static bool +init_insn_rhs_dead_pseudo_p (int regno) +{ + rtx insns = ira_reg_equiv[regno].init_insns; + + if (insns == NULL) + return false; + if (INSN_P (insns)) + return insn_rhs_dead_pseudo_p (insns); + for (; insns != NULL_RTX; insns = XEXP (insns, 1)) + if (insn_rhs_dead_pseudo_p (XEXP (insns, 0))) + return true; + return false; +} + /* Entry function of LRA constraint pass. Return true if the constraint pass did change the code. */ bool @@ -3628,7 +3705,22 @@ lra_constraints (bool first_p) } else if ((x = get_equiv_substitution (regno_reg_rtx[i])) != NULL_RTX) { - if (! first_p && contains_reg_p (x, false, false)) + bool pseudo_p = contains_reg_p (x, false, false); + + /* We don't use DF for compilation speed sake. So it is + problematic to update live info when we use an + equivalence containing pseudos in more than one BB. */ + if ((pseudo_p && multi_block_pseudo_p (i)) + /* We check that a pseudo in rhs of the init insn is + not dying in the insn. Otherwise, the live info + at the beginning of the corresponding BB might be + wrong after we removed the insn. When the equiv can + be a constant, the right hand side of the init insn + can be a pseudo. */ + || (ira_reg_equiv[i].memory == NULL_RTX + && init_insn_rhs_dead_pseudo_p (i))) + ira_reg_equiv[i].defined_p = false; + else if (! first_p && pseudo_p) /* After RTL transformation, we can not guarantee that pseudo in the substitution was not reloaded which might make equivalence invalid. For example, in