From patchwork Thu Nov 3 13:01:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Schmidt X-Patchwork-Id: 80651 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp620213qge; Thu, 3 Nov 2016 06:02:18 -0700 (PDT) X-Received: by 10.99.128.198 with SMTP id j189mr13728741pgd.151.1478178138428; Thu, 03 Nov 2016 06:02:18 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a135si9407309pfa.272.2016.11.03.06.02.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2016 06:02:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-440317-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-440317-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-440317-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=DyuvdE4NQPxsMWrwt BVWGi/XI4Hk6xMGb5rl7xqRojroLFlXzxnb3tfreY7dEeiwgiNZmc8nUU0OkP7Pu bj0M5dibwZuaTHXhgisan6KZHeh8AbKiur+oapBORyrTO+ac55e8sCh4w6eyaf25 gQ0d+ZEBqu5/1dvERS05ekK4LU= 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=XN3sAFvCrR4FfmYDUstAnbe R+wY=; b=s9gGuEArc8zQFF4yM/UJF6lnVYOg5BKkVby/5REPU9VXt5Q+A/oE+EX uMWdcOfygxYXq/sk3h2xI02HN6YOJ+e010noRFZt4k9HXgiJlarjWvQmh3/QgA0n brwe6LH2p6wuqvKWqT9cnzV6n9qwPtPyn5iDVE3rMhsf9lBsa1pk= Received: (qmail 7942 invoked by alias); 3 Nov 2016 13:01:32 -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 7878 invoked by uid 89); 3 Nov 2016 13:01:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:4354 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Nov 2016 13:01:28 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A193D61B84; Thu, 3 Nov 2016 13:01:27 +0000 (UTC) Received: from localhost.localdomain (vpn1-5-133.ams2.redhat.com [10.36.5.133]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uA3D1PpN002003; Thu, 3 Nov 2016 09:01:26 -0400 Subject: Re: [Patch, rtl] PR middle-end/78016, keep REG_NOTE order during insn copy To: Eric Botcazou , Jiong Wang References: <1f9dd2ba-6a92-3afc-a6fb-d4be914ab239@foss.arm.com> <2697075.RyE6RnoD4q@polaris> <184815310.0vHTQ9qhu3@polaris> Cc: gcc-patches@gcc.gnu.org From: Bernd Schmidt Message-ID: Date: Thu, 3 Nov 2016 14:01:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <184815310.0vHTQ9qhu3@polaris> X-IsSubscribed: yes On 11/03/2016 01:33 PM, Eric Botcazou wrote: >> Thanks for the feedback, I'll try to work through this. > > Thanks, but since there doesn't seem to be a consensus on the goal, feel free > to disregard it and just implement what you need for your initial work. FWIW here's a more complete version of my patch which I'm currently testing. Let me know if you think it's at least a good enough intermediate step to be installed. I think, the sel-sched example notwithstanding, this is something that normally should not be needed outside of emit_copy_of_insn_after, so having that do the right thing ought to be good enough. Bernd * emit-rtl.c (emit_copy_of_insn_after): Duplicate notes in order. * sel-sched-ir.c (create_copy_of_insn_rtx): Likewise. * rtl.h (duplicate_reg_notes): Declare. * rtlanal.c (duplicate_reg_note): New function. Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c (revision 241233) +++ gcc/emit-rtl.c (working copy) @@ -6169,17 +6169,18 @@ emit_copy_of_insn_after (rtx_insn *insn, 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); + gcc_assert (*ptail == NULL_RTX); + /* 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))); - else - add_shallow_copy_of_reg_note (new_rtx, link); + *ptail = duplicate_reg_note (link); + ptail = &XEXP (*ptail, 1); } INSN_CODE (new_rtx) = INSN_CODE (insn); Index: gcc/rtl.h =================================================================== --- gcc/rtl.h (revision 241233) +++ gcc/rtl.h (working copy) @@ -3008,6 +3008,7 @@ extern rtx alloc_reg_note (enum reg_note extern void add_reg_note (rtx, enum reg_note, rtx); extern void add_int_reg_note (rtx, enum reg_note, int); extern void add_shallow_copy_of_reg_note (rtx_insn *, rtx); +extern rtx duplicate_reg_note (rtx); extern void remove_note (rtx, const_rtx); extern void remove_reg_equal_equiv_notes (rtx_insn *); extern void remove_reg_equal_equiv_notes_for_regno (unsigned int); Index: gcc/rtlanal.c =================================================================== --- gcc/rtlanal.c (revision 241233) +++ gcc/rtlanal.c (working copy) @@ -2304,6 +2304,20 @@ add_shallow_copy_of_reg_note (rtx_insn * add_reg_note (insn, REG_NOTE_KIND (note), XEXP (note, 0)); } +/* Duplicate NOTE and return the copy. */ +rtx +duplicate_reg_note (rtx note) +{ + reg_note kind = REG_NOTE_KIND (note); + + if (GET_CODE (note) == INT_LIST) + return gen_rtx_INT_LIST ((machine_mode) kind, XINT (note, 0), NULL_RTX); + else if (GET_CODE (note) == EXPR_LIST) + return alloc_reg_note (kind, copy_insn_1 (XEXP (note, 0)), NULL_RTX); + else + return alloc_reg_note (kind, XEXP (note, 0), NULL_RTX); +} + /* Remove register note NOTE from the REG_NOTES of INSN. */ void Index: gcc/sel-sched-ir.c =================================================================== --- gcc/sel-sched-ir.c (revision 241233) +++ gcc/sel-sched-ir.c (working copy) @@ -5762,6 +5762,10 @@ 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 NEW_RTX. */ + rtx *ptail = ®_NOTES (res); + gcc_assert (*ptail == NULL_RTX); + /* 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. */ @@ -5770,11 +5774,8 @@ 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)); + *ptail = duplicate_reg_note (link); + ptail = &XEXP (*ptail, 1); } return res;