From patchwork Tue Nov 27 23:29:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Bosscher X-Patchwork-Id: 202321 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 1FCF82C0086 for ; Wed, 28 Nov 2012 10:29:56 +1100 (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=1354663797; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: MIME-Version:Received:In-Reply-To:References:From:Date: Message-ID:Subject:To:Cc:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=74QhTuLx9Pk9o8/0jMAig4mTvSw=; b=aYm78/9mNMWH20z Hx93xwLLwWb0lVvuM6QACmMJXiBewMjdmgbm9qsGc8cakqYSW2FHhQLcli93tCyH obfOPbP9+2PQeUwGwzw9BcvCQUSzGNylZFeb8FsgJBuzo9c5wGiPUMwpwNZPZcm5 sIHmiM/+qZur2UJh7Pw8VIauC25U= 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:MIME-Version:Received:In-Reply-To:References:From:Date:Message-ID:Subject:To:Cc:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=YnxwNVe22AlprTIStyL0nDw7MXvQ4QpWdrLlkgfeQbQO3zzgGC9pod/+CZGjwx lUJ/I7/ZkVuZl6UWqWzz2jznBmJzTYUo+sUtFJvpPuxgn1jOs597AaszqAqgOlHr ZcQ8whNA3Z17iYwXDJB/Qphw/UAC5LWjtP0Hkf/QXh3gc=; Received: (qmail 16105 invoked by alias); 27 Nov 2012 23:29:52 -0000 Received: (qmail 16093 invoked by uid 22791); 27 Nov 2012 23:29:52 -0000 X-SWARE-Spam-Status: No, hits=-5.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_EQ X-Spam-Check-By: sourceware.org Received: from mail-lb0-f175.google.com (HELO mail-lb0-f175.google.com) (209.85.217.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 27 Nov 2012 23:29:47 +0000 Received: by mail-lb0-f175.google.com with SMTP id gg13so7346586lbb.20 for ; Tue, 27 Nov 2012 15:29:44 -0800 (PST) Received: by 10.112.98.131 with SMTP id ei3mr7475045lbb.63.1354058984755; Tue, 27 Nov 2012 15:29:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.88.99 with HTTP; Tue, 27 Nov 2012 15:29:03 -0800 (PST) In-Reply-To: <34723155.BbVgJcJOVM@polaris> References: <20121118231540.726263BABA@mailhost.lps.ens.fr> <50B4CF15.5070809@gnu.org> <34723155.BbVgJcJOVM@polaris> From: Steven Bosscher Date: Wed, 28 Nov 2012 00:29:03 +0100 Message-ID: Subject: Re: Fix twolf -funroll-loops -O3 miscompilation (a semi-latent web.c bug) To: Eric Botcazou Cc: Paolo Bonzini , gcc-patches@gcc.gnu.org, Dominique Dhumieres , hubicka@ucw.cz, Richard Henderson , Jeff Law 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 On Tue, Nov 27, 2012 at 5:57 PM, Eric Botcazou wrote: >> This note seems very very weird. For one thing, it becomes invalid on >> the very instruction where it is created. I would say that it should >> not be there. > > Agreed. Count me in, too. So let's avoid it: * gcse.c (struct reg_use): Remove unused struct. (gcse_emit_move_after): Do not create REG_EQUAL notes that reference the SET_DEST of the instruction the note would be attached to. Index: gcse.c =================================================================== --- gcse.c (revision 193394) +++ gcse.c (working copy) @@ -258,8 +258,6 @@ int flag_rerun_cse_after_global_opts; /* An obstack for our working variables. */ static struct obstack gcse_obstack; -struct reg_use {rtx reg_rtx; }; - /* Hash table of expressions. */ struct expr @@ -2482,23 +2480,27 @@ gcse_emit_move_after (rtx dest, rtx src, rtx new_rtx; rtx set = single_set (insn), set2; rtx note; - rtx eqv; + rtx eqv = NULL_RTX; /* This should never fail since we're creating a reg->reg copy we've verified to be valid. */ new_rtx = emit_insn_after (gen_move_insn (dest, src), insn); - /* Note the equivalence for local CSE pass. */ + /* Note the equivalence for local CSE pass. Take the note from the old + set if there was one. Otherwise record the SET_SRC from the old set + unless DEST is also an operand of the SET_SRC. */ set2 = single_set (new_rtx); if (!set2 || !rtx_equal_p (SET_DEST (set2), dest)) return new_rtx; if ((note = find_reg_equal_equiv_note (insn))) eqv = XEXP (note, 0); - else + else if (! REG_P (dest) + || ! reg_mentioned_p (dest, SET_SRC (set))) eqv = SET_SRC (set); - set_unique_reg_note (new_rtx, REG_EQUAL, copy_insn_1 (eqv)); + if (eqv != NULL_RTX) + set_unique_reg_note (new_rtx, REG_EQUAL, copy_insn_1 (eqv)); return new_rtx; } And perhaps a bit in emit-rtl.c for good measure? I'll see if/where this causes breakage... Index: emit-rtl.c =================================================================== --- emit-rtl.c (revision 193394) +++ emit-rtl.c (working copy) @@ -4932,6 +4932,19 @@ gen_use (rtx x) return seq; } +/* Return true if DATUM has a USE of the SET_DEST of INSN. */ +static bool +self_ref_note_p (rtx insn, rtx datum) +{ + rtx set = single_set (insn); + if (! set) + return false; + rtx dest = SET_DEST (set); + if (! REG_P (dest)) + return false; + return reg_mentioned_p (dest, datum); +} + /* Place a note of KIND on insn INSN with DATUM as the datum. If a note of this type already exists, remove it first. */ @@ -4961,6 +4974,8 @@ set_unique_reg_note (rtx insn, enum reg_ if (note) { + if (self_ref_note_p (insn, datum)) + internal_error ("self-reference in REG_EQUAL or REG_EQUIV note!\n"); XEXP (note, 0) = datum; df_notes_rescan (insn); return note; @@ -4982,6 +4997,8 @@ set_unique_reg_note (rtx insn, enum reg_ { case REG_EQUAL: case REG_EQUIV: + if (self_ref_note_p (insn, datum)) + internal_error ("self-reference in REG_EQUAL or REG_EQUIV note!\n"); df_notes_rescan (insn); break; default: