From patchwork Tue Nov 2 20:27:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 69923 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 74BC9B6EED for ; Wed, 3 Nov 2010 07:28:56 +1100 (EST) Received: (qmail 440 invoked by alias); 2 Nov 2010 20:28:40 -0000 Received: (qmail 350 invoked by uid 22791); 2 Nov 2010 20:28:24 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 02 Nov 2010 20:28:19 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id C9817CB0247; Tue, 2 Nov 2010 21:28:14 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vBPtnbMYopdo; Tue, 2 Nov 2010 21:28:14 +0100 (CET) Received: from [192.168.1.2] (bon31-9-83-155-120-49.fbx.proxad.net [83.155.120.49]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id 7D46ECB0202; Tue, 2 Nov 2010 21:28:14 +0100 (CET) From: Eric Botcazou To: Jakub Jelinek Subject: Re: [PATCH] Fix combiner (PRs rtl-optimization/46034, rtl-optimization/46212, rtl-optimization/46248) Date: Tue, 2 Nov 2010 21:27:29 +0100 User-Agent: KMail/1.9.9 References: <20101101210903.GD29412@tyan-ft48-01.lab.bos.redhat.com> In-Reply-To: <20101101210903.GD29412@tyan-ft48-01.lab.bos.redhat.com> Cc: gcc-patches@gcc.gnu.org MIME-Version: 1.0 Message-Id: <201011022127.29192.ebotcazou@adacore.com> 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 > There are two issues, one is that the earlier > newpat = subst (newpat, i0dest, i0src, ...); > might have (but not necessarily) have changed i1src and so when i1dest > is first replaced with i1src that way modified and then i0dest is replaced > with i0src, the replacements are already wrong and as testcases show > self-referential. FWIW I also debugged this (and spotted a pasto in the 4-insn combiner patch that I'll fix after your fixes, patch attached). I also roughly came up with: + /* Following subst may modify i1src, make a copy of it + before it is for added_sets_2 handling if needed. */ + if (added_sets_2 + && i0dest_in_i0src + && i0_feeds_i1_n + && (i1_feeds_i2_n || i0_feeds_i2_n)) + i1src_copy = copy_rtx (i1src); but why not just if (i0_feeds_i1_n && added_sets_2 && i1_feeds_i2_n) i.e. make a copy if substituting I0 will clobber I1SRC and I1SRC will be re- substituted in I2PAT? > The other issue is that if we are to apply more than > one substitution on i2pat and i0dest_in_i0src, then we need to pass > 1 as last argument to the first subst in order to avoid unwanted > rtl sharing (which again can lead to self-referential rtl). > Another issue is that if all of i0_feeds_i2_n, i0_feeds_i1_n and > i1_feeds_i2_n is true, then we'd be substituting i0dest with i0src > in i2pat twice. This part looks OK to me. * combine.c (try_combine): Fix formatting issues and a pasto. Index: combine.c =================================================================== --- combine.c (revision 166059) +++ combine.c (working copy) @@ -3071,23 +3071,23 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx } n_occurrences = 0; /* `subst' counts here */ - - /* If I1 feeds into I2 and I1DEST is in I1SRC, we need to make a - unique copy of I2SRC each time we substitute it to avoid - self-referential rtl. */ - subst_low_luid = DF_INSN_LUID (i2); + + /* If I1 feeds into I2 and I1DEST is in I1SRC, we need to make a unique + copy of I2SRC each time we substitute it, in order to avoid creating + self-referential RTL when we will be substituting I1SRC for I1DEST + later. Likewise if I0 feeds into I2 and I0DEST is in I0SRC. */ newpat = subst (PATTERN (i3), i2dest, i2src, 0, - ((i1_feeds_i2_n && i1dest_in_i1src) - || (i0_feeds_i2_n && i0dest_in_i0src))); + (i1_feeds_i2_n && i1dest_in_i1src) + || (i0_feeds_i2_n && i0dest_in_i0src)); substed_i2 = 1; - /* Record whether i2's body now appears within i3's body. */ + /* Record whether I2's body now appears within I3's body. */ i2_is_used = n_occurrences; } - /* If we already got a failure, don't try to do more. Otherwise, - try to substitute in I1 if we have it. */ + /* If we already got a failure, don't try to do more. Otherwise, try to + substitute I1 if we have it. */ if (i1 && GET_CODE (newpat) != CLOBBER) { @@ -3098,10 +3098,10 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx && i1_feeds_i2_n && dead_or_set_p (i2, i1dest) && !reg_overlap_mentioned_p (i1dest, newpat)) - /* Before we can do this substitution, we must redo the test done - above (see detailed comments there) that ensures that I1DEST - isn't mentioned in any SETs in NEWPAT that are field assignments. */ - || !combinable_i3pat (NULL_RTX, &newpat, i1dest, NULL_RTX, NULL_RTX, + /* Before we can do this substitution, we must redo the test done + above (see detailed comments there) that ensures I1DEST isn't + mentioned in any SETs in NEWPAT that are field assignments. */ + || !combinable_i3pat (NULL_RTX, &newpat, i1dest, NULL_RTX, NULL_RTX, 0, 0, 0)) { undo_all (); @@ -3110,18 +3110,28 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx n_occurrences = 0; subst_low_luid = DF_INSN_LUID (i1); + + /* If I0 feeds into I1 and I0DEST is in I0SRC, we need to make a unique + copy of I1SRC each time we substitute it, in order to avoid creating + self-referential RTL when we will be substituting I0SRC for I0DEST + later. */ newpat = subst (newpat, i1dest, i1src, 0, i0_feeds_i1_n && i0dest_in_i0src); substed_i1 = 1; + + /* Record whether I1's body now appears within I3's body. */ i1_is_used = n_occurrences; } + + /* Likewise for I0 if we have it. */ + if (i0 && GET_CODE (newpat) != CLOBBER) { if ((FIND_REG_INC_NOTE (i0, NULL_RTX) != 0 && ((i0_feeds_i2_n && dead_or_set_p (i2, i0dest)) || (i0_feeds_i1_n && dead_or_set_p (i1, i0dest))) && !reg_overlap_mentioned_p (i0dest, newpat)) - || !combinable_i3pat (NULL_RTX, &newpat, i0dest, NULL_RTX, NULL_RTX, + || !combinable_i3pat (NULL_RTX, &newpat, i0dest, NULL_RTX, NULL_RTX, 0, 0, 0)) { undo_all (); @@ -3130,8 +3140,7 @@ try_combine (rtx i3, rtx i2, rtx i1, rtx n_occurrences = 0; subst_low_luid = DF_INSN_LUID (i0); - newpat = subst (newpat, i0dest, i0src, 0, - i0_feeds_i1_n && i0dest_in_i0src); + newpat = subst (newpat, i0dest, i0src, 0, 0); substed_i0 = 1; }