From patchwork Fri Oct 21 12:04:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiong Wang X-Patchwork-Id: 78651 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1261322qge; Fri, 21 Oct 2016 05:05:00 -0700 (PDT) X-Received: by 10.99.213.21 with SMTP id c21mr856127pgg.176.1477051500348; Fri, 21 Oct 2016 05:05:00 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id t129si2448493pgc.171.2016.10.21.05.05.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 05:05:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439224-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439224-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439224-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=UttlhOR9gL7EMnKXK MmoyOcMnqw0uzNrIBgaqwlhZ/v77gO04Gg8Dh3ixV0zPKOIWGby82XS24Y49woc3 D69YgqrKLYmI21+chsxGa4o9aHBc8eJUcDQQdMtxOS+7ucA05sHaTGm1g0m0X39J gahZvh8mFEOCE1uM6QiMn2PBsE= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=HZtPR72pJs06Z7RUVe4L7r2 9tuw=; b=Gfjgnc+5ej4e5lqWDPNphboJsyxLs2ea46cnS60tLCs/PB1pJiHuqIj Sxt55DAIWGeeD+dhNcuuP5IaangC9OfTbMrrumZkk3gauODo+/x7iVs23MGas6mi ir6oMvP+NlnWG8mXHLKebrRE7cbnFwBPd4hTP6wYAFYfAhhAcDA8= Received: (qmail 109324 invoked by alias); 21 Oct 2016 12:04:47 -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 109311 invoked by uid 89); 21 Oct 2016 12:04:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=XINT, xint, bschmidt@redhat.com, bschmidtredhatcom X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Oct 2016 12:04:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E8D512B; Fri, 21 Oct 2016 05:04:34 -0700 (PDT) Received: from [10.2.206.198] (e104437-lin.cambridge.arm.com [10.2.206.198]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 56D673F218; Fri, 21 Oct 2016 05:04:34 -0700 (PDT) Subject: Re: [Patch, rtl] PR middle-end/78016, keep REG_NOTE order during insn copy To: Bernd Schmidt , Eric Botcazou References: <1f9dd2ba-6a92-3afc-a6fb-d4be914ab239@foss.arm.com> <884b9f0d-ff3f-d214-369f-5d5631695c87@redhat.com> <70337315.mGifSNztka@polaris> Cc: gcc-patches@gcc.gnu.org From: Jiong Wang Message-ID: <136c0e15-0545-1190-f76a-7e2865d269a5@foss.arm.com> Date: Fri, 21 Oct 2016 13:04:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 21/10/16 11:13, Bernd Schmidt wrote: > On 10/21/2016 09:43 AM, Eric Botcazou wrote: >> I disagree: there are currently n ways of copying NOTEs in the RTL >> middle-end, >> with different properties each time. We need only one primitive in >> rtlanal.c. > > I feel the fact that they have different properties means we shouldn't > try to unify them: we'll just end up with a long list of boolean > parameters, with no way of quickly telling what a given function call > is doing. A copy loop is short enough that it can be implemented > in-place and people can quickly tell what is going on by looking at it. > > Maybe the inner if statement could be a small helper function > (append_copy_of_reg_note). > > > Bernd Hi Bernd, Eric, How does the attached patch looks to you? x86_64 bootstrap & regression OK. I borrowed Bernd' code to write the tail pointer directly. 2016-10-21 Bernd Schmidt Jiong Wang gcc/ PR middle-end/78016 * emit-rtl.c (emit_copy_of_insn_after): Copy REG_NOTES in order instead of in reverse order. * sel-sched-ir.c (create_copy_of_insn_rtx): Likewise. diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c index 2d6d1eb6c1311871f15dbed13d7c084ed3845a86..4d849ca6e64273bedc5bf8b9a62a5cc5d4606129 100644 --- a/gcc/emit-rtl.c +++ b/gcc/emit-rtl.c @@ -6168,17 +6168,31 @@ emit_copy_of_insn_after (rtx_insn *insn, rtx_insn *after) which may be duplicated by the basic block reordering code. */ RTX_FRAME_RELATED_P (new_rtx) = RTX_FRAME_RELATED_P (insn); + /* Locate the end of existing REG_NOTES in NEW_RTX. */ + rtx *ptail = ®_NOTES (new_rtx); + while (*ptail != NULL_RTX) + ptail = &XEXP (*ptail, 1); + /* Copy all REG_NOTES except REG_LABEL_OPERAND since mark_jump_label will make them. REG_LABEL_TARGETs are created there too, but are supposed to be sticky, so we copy them. */ for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) if (REG_NOTE_KIND (link) != REG_LABEL_OPERAND) { - if (GET_CODE (link) == EXPR_LIST) - add_reg_note (new_rtx, REG_NOTE_KIND (link), - copy_insn_1 (XEXP (link, 0))); + rtx new_node; + + if (GET_CODE (link) == INT_LIST) + new_node = gen_rtx_INT_LIST ((machine_mode) REG_NOTE_KIND (link), + XINT (link, 0), NULL_RTX); else - add_shallow_copy_of_reg_note (new_rtx, link); + new_node = alloc_reg_note (REG_NOTE_KIND (link), + (GET_CODE (link) == EXPR_LIST + ? copy_insn_1 (XEXP (link, 0)) + : XEXP (link ,0)), + NULL_RTX); + + *ptail = new_node; + ptail = &XEXP (new_node, 1); } INSN_CODE (new_rtx) = INSN_CODE (insn); diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c index 210b1e4edfb359a161cda4826704005ae9ab5a24..324ae8cf05209757a3a3f3dee97c9274876c7ed7 100644 --- a/gcc/sel-sched-ir.c +++ b/gcc/sel-sched-ir.c @@ -5761,6 +5761,11 @@ create_copy_of_insn_rtx (rtx insn_rtx) res = create_insn_rtx_from_pattern (copy_rtx (PATTERN (insn_rtx)), NULL_RTX); + /* Locate the end of existing REG_NOTES in RES. */ + rtx *ptail = ®_NOTES (res); + while (*ptail != NULL_RTX) + ptail = &XEXP (*ptail, 1); + /* Copy all REG_NOTES except REG_EQUAL/REG_EQUIV and REG_LABEL_OPERAND since mark_jump_label will make them. REG_LABEL_TARGETs are created there too, but are supposed to be sticky, so we copy them. */ @@ -5769,11 +5774,12 @@ create_copy_of_insn_rtx (rtx insn_rtx) && REG_NOTE_KIND (link) != REG_EQUAL && REG_NOTE_KIND (link) != REG_EQUIV) { - if (GET_CODE (link) == EXPR_LIST) - add_reg_note (res, REG_NOTE_KIND (link), - copy_insn_1 (XEXP (link, 0))); - else - add_reg_note (res, REG_NOTE_KIND (link), XEXP (link, 0)); + rtx new_node = alloc_reg_note (REG_NOTE_KIND (link), + (GET_CODE (link) == EXPR_LIST + ? copy_insn_1 (XEXP (link, 0)) + : XEXP (link ,0)), NULL_RTX); + *ptail = new_node; + ptail = &XEXP (new_node, 1); } return res;