From patchwork Thu Feb 26 19:35:45 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: 444046 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 3638714008F for ; Fri, 27 Feb 2015 06:36:06 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=rOuNC540; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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:references :in-reply-to:content-type; q=dns; s=default; b=wq2PlZaAtMwDKUgLR S8aTeBFAPYVgC1JIi50ZpP+GBlkenqOgezjBYZUgoir8QFecBCeBtO/5flaVaXuj x8UDsqJtloDLmPJRnFRGJiKn/032cdgX0syYMbp3hNdZkzxj5wBWtYvTGKf0db+c tCcjblenIOrlkLAJhgGmxDbp9g= 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:references :in-reply-to:content-type; s=default; bh=jfz97/wlbnZPW8pSklqJJ0D gS2E=; b=rOuNC540fblFQeqSYyw1hAnncB37HJLkthApHXsQV9KPgS/tafqPgfS hdDvvV+Fe1b9sZ9iEh1ZGmAWw2yW0iptq7FBfF5qG7Mr6bk8iDda1v10woo3Hj4R fqS22+gtBQ1eRgKvqCHkrOszRkc0K8Ca+OgG3MiL1Y55eSE7Uj/c= Received: (qmail 59191 invoked by alias); 26 Feb 2015 19:35:55 -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 59178 invoked by uid 89); 26 Feb 2015 19:35:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 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.161) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 26 Feb 2015 19:35:49 +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 N00ffbr1QJZj7rC (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate); Thu, 26 Feb 2015 20:35:45 +0100 (CET) Message-ID: <54EF7591.3030900@gjlay.de> Date: Thu, 26 Feb 2015 20:35:45 +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: Re: [patch, avr] Take 2: Fix PR64331: insn output and insn length computation rely on REG_DEAD notes. References: <54EB06C0.2080503@gjlay.de> In-Reply-To: <54EB06C0.2080503@gjlay.de> X-IsSubscribed: yes Am 02/23/2015 um 11:53 AM schrieb Georg-Johann Lay: > 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. Let me drop that... Problem was that df relies on cfg which is down after a specific point (after pass .*free_cfg). Take #2 introduces a new, avr-specific rtl pass whose sole purpose is to rectify notes. The pass is scheduled right before cfg does down (right before .*free_cfg) so that cfg and hence df machinery is available. Regression tests look fine and for the test case the patches produce correct code and correct insn length. Ok for trunk and 4.9? Johann gcc/ PR target/64331 * config/avr/avr.c (context.h, tree-pass.h): Include them. (avr_pass_data_recompute_notes): New static variable. (avr_pass_recompute_notes): New class. (avr_register_passes): New static function. (avr_option_override): Call it. gcc/testsuite/ PR target/64331 * gcc.target/avr/torture/pr64331.c: New test. Index: config/avr/avr.c =================================================================== --- config/avr/avr.c (revision 220963) +++ config/avr/avr.c (working copy) @@ -51,6 +51,8 @@ #include "target-def.h" #include "params.h" #include "df.h" +#include "context.h" +#include "tree-pass.h" /* Maximal allowed offset for an address in the LD command */ #define MAX_LD_OFFSET(MODE) (64 - (signed)GET_MODE_SIZE (MODE)) @@ -285,6 +287,58 @@ avr_to_int_mode (rtx x) } +static const pass_data avr_pass_data_recompute_notes = +{ + RTL_PASS, // type + "", // name (will be patched) + OPTGROUP_NONE, // optinfo_flags + false, // has_gate + true, // has_execute + TV_DF_SCAN, // tv_id + 0, // properties_required + 0, // properties_provided + 0, // properties_destroyed + 0, // todo_flags_start + // todo_flags_finish + TODO_df_finish | TODO_verify_rtl_sharing | TODO_verify_flow +}; + + +class avr_pass_recompute_notes : public rtl_opt_pass +{ +public: + avr_pass_recompute_notes (gcc::context *ctxt, const char *name) + : rtl_opt_pass (avr_pass_data_recompute_notes, ctxt) + { + this->name = name; + } + + unsigned int execute (void) + { + df_note_add_problem (); + df_analyze (); + + return 0; + } +}; // avr_pass_recompute_notes + + +static void +avr_register_passes (void) +{ + /* This avr-specific pass (re)computes insn notes, in particular REG_DEAD + notes which are used by `avr.c::reg_unused_after' and branch offset + computations. These notes must be correct, i.e. there must be no + dangling REG_DEAD notes; otherwise wrong code might result, cf. PR64331. + + DF needs (correct) CFG, hence right before free_cfg is the last + opportunity to rectify notes. */ + + register_pass (new avr_pass_recompute_notes (g, "avr-notes-free-cfg"), + PASS_POS_INSERT_BEFORE, "*free_cfg", 1); +} + + /* Implement `TARGET_OPTION_OVERRIDE'. */ static void @@ -346,6 +400,11 @@ avr_option_override (void) init_machine_status = avr_init_machine_status; avr_log_set_avr_log(); + + /* Register some avr-specific pass(es). There is no canonical place for + pass registration. This function is convenient. */ + + avr_register_passes (); } /* Function to set up the backend function structure. */ 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,37 @@ +/* { 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; +}