From patchwork Mon Feb 23 10:53:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georg-Johann Lay X-Patchwork-Id: 442416 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2368A14016B for ; Mon, 23 Feb 2015 21:54:06 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=EdvPa0DOh0XRCA6kW2EQ3KfkGAmqbtwNubzfD+iwqN8 NAZ6l7eh5m5equr+8aRbscAoWrE+crzA3OxLlpWKWnPt0qL0IKppJln6633r0h5b hQNoBku3j8xngrWnWCUOUOdplxOca7M8uFLi/R0lAwaaTh43ghVioqvMblOuictQ = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=cLE3uShHQLSDaIAgjQGQeSQRjJk=; b=guHjr5Rx3PN7mryMS dd1P7XWaqEZHMLmzu/RhArs95V3XYnlSpy+ZwY4eO1p1BbJ1GGEYotd/QBj41qc3 cT2LRDQ4KoIexlf0SpCCPKXr9WalLluHvlHl01XVEH3ACriwyNMra5/m8RNg0Erz u9Vr8xFxA3DcK8NTLp0M6rrEHM= Received: (qmail 14288 invoked by alias); 23 Feb 2015 10:53:59 -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 14251 invoked by uid 89); 23 Feb 2015 10:53:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: mo4-p00-ob.smtp.rzone.de Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.220) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 23 Feb 2015 10:53:56 +0000 X-RZG-AUTH: :LXoWVUeid/7A29J/hMvvT3ol15ykJcYwTPbBBR62PQx1xqvTHw== X-RZG-CLASS-ID: mo00 Received: from [192.168.0.22] (ip5b43a95f.dynamic.kabel-deutschland.de [91.67.169.95]) by smtp.strato.de (RZmta 37.3 DYNA|AUTH) with ESMTPSA id N07f15r1NArroaa (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate); Mon, 23 Feb 2015 11:53:53 +0100 (CET) Message-ID: <54EB06C0.2080503@gjlay.de> Date: Mon, 23 Feb 2015 11:53:52 +0100 From: Georg-Johann Lay User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: GCC Patches CC: Denis Chertykov Subject: [patch, avr] Fix PR64331: insn output and insn length computation rely on REG_DEAD notes. X-IsSubscribed: yes This patch fixes PR64331 which produced wrong code because of outdated (too many) REG_DEAD notes. These notes are not (re)computed per default, hence do the computation by hand each time avr.c:reg_unused_after is called in a different pass. Ok to apply? Johann gcc/ PR target/64331 * config/avr/avr.c (reg_unused_after): Recompute insn notes if the pass changed since the last (re)computation. * config/avr/avr.h (machine_function.dead_notes_pass_number): New component. gcc/testsuite/ PR target/64331 * gcc.target/avr/torture/pr64331.c: New run test. Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 220738) +++ config/avr/avr.c (working copy) @@ -51,6 +51,7 @@ #include "target-def.h" #include "params.h" #include "df.h" +#include "tree-pass.h" /* for current_pass */ /* Maximal allowed offset for an address in the LD command */ #define MAX_LD_OFFSET(MODE) (64 - (signed)GET_MODE_SIZE (MODE)) @@ -7862,8 +7863,22 @@ avr_adjust_insn_length (rtx insn, int le int reg_unused_after (rtx insn, rtx reg) { + if (cfun->machine->dead_notes_pass_number + != current_pass->static_pass_number) + { + /* `dead_or_set_p' needs correct REG_DEAD notes, cf. PR64331. Hence + recompute them each time we find ourselves in a different pass. + `reg_unused_after' is used during final for insn output, and in + some earlier passes it is involved in insn length computations. */ + + df_note_add_problem (); + df_analyze (); + + cfun->machine->dead_notes_pass_number = current_pass->static_pass_number; + } + return (dead_or_set_p (insn, reg) - || (REG_P(reg) && _reg_unused_after (insn, reg))); + || (REG_P (reg) && _reg_unused_after (insn, reg))); } /* Return nonzero if REG is not used after INSN. Index: config/avr/avr.h =================================================================== --- config/avr/avr.h (revision 220738) +++ config/avr/avr.h (working copy) @@ -592,6 +592,10 @@ struct GTY(()) machine_function /* 'true' if the above is_foo predicates are sanity-checked to avoid multiple diagnose for the same function. */ int attributes_checked_p; + + /* The latest static pass number for which REG_DEAD notes have been + computed, cf. PR64331. */ + int dead_notes_pass_number; }; /* AVR does not round pushes, but the existence of this macro is Index: testsuite/gcc.target/avr/torture/pr64331.c =================================================================== --- testsuite/gcc.target/avr/torture/pr64331.c (revision 0) +++ testsuite/gcc.target/avr/torture/pr64331.c (revision 0) @@ -0,0 +1,38 @@ +/* { dg-do run } */ + +typedef struct +{ + unsigned a, b; +} T2; + + +__attribute__((__noinline__, __noclone__)) +void foo2 (T2 *t, int x) +{ + if (x != t->a) + { + t->a = x; + + if (x && x == t->b) + t->a = 20; + } +} + + +T2 t; + +int main (void) +{ + t.a = 1; + t.b = 1234; + + foo2 (&t, 1234); + + if (t.a != 20) + __builtin_abort(); + + __builtin_exit (0); + + return 0; +} +