From patchwork Tue Feb 12 17:28:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 219918 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 4156C2C0085 for ; Wed, 13 Feb 2013 04:28:53 +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=1361294934; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=A6zdck+MVQT6tyaw7/jc/dXgLTk=; b=WVe1OK/SB9LCkT8 iyX9BtlOTHoOpLiZ+Oi1Vvnuvwtg/TvRFR6amRDxlrt6U6mHMAVffAriZVLrh0iA iJ/IR04RlUuwT1jh7Crxyd8Gc7wqp+uYUfqWFztKaxpbpdjW26nr++hj6hviv7nB cBolYmLMs8HaWfAyaG8juTgASPEQ= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=B029JhBVcKlK7CszD6IbfQpkYXg+W5dChNqG+rMY5W0cJw3GiIkcGe6vr5FDxH 06GTO0XJH+yR7D1xrtbc0KJihhupPZB6zZCjzQO/Y41Qv+1p1Zh+2buz4cVHtK7s D6eR3RKjVsuKXkB15ux3Kqpq3tbKh8gH1aKGRcCfQBF0Y=; Received: (qmail 23524 invoked by alias); 12 Feb 2013 17:28:47 -0000 Received: (qmail 23514 invoked by uid 22791); 12 Feb 2013 17:28:46 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Feb 2013 17:28:33 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1CHSXQT009332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 12 Feb 2013 12:28:33 -0500 Received: from houston.quesejoda.com (vpn-50-124.rdu2.redhat.com [10.10.50.124]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1CHSWZF002705; Tue, 12 Feb 2013 12:28:32 -0500 Message-ID: <511A7BBF.1030401@redhat.com> Date: Tue, 12 Feb 2013 11:28:31 -0600 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: Jakub Jelinek , gcc-patches , rdsandiford@googlemail.com Subject: Re: PR target/52555: attribute optimize is overriding command line options References: <51198989.7090803@redhat.com> <20130212140503.GD4385@tucnak.redhat.com> <878v6twl42.fsf@talisman.default> In-Reply-To: <878v6twl42.fsf@talisman.default> 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 > Rather than: > > /* Change optabs if needed. */ > if (TREE_OPTIMIZATION_OPTABS (opts)) > this_target_optabs > = (struct target_optabs *) TREE_OPTIMIZATION_OPTABS (opts); > else > this_target_optabs = &default_target_optabs; > > I think it'd be better to have: > > /* Change optabs if needed. */ > if (TREE_OPTIMIZATION_OPTABS (opts)) > this_fn_optabs > = (struct target_optabs *) TREE_OPTIMIZATION_OPTABS (opts); > else > this_fn_optabs = this_target_optabs; > > with genopinit.c updated to use this_fn_optabs instead of this_target_optabs. Hmmm, ok. I also added a default case setting this_fn_optabs = &default_target_optabs when the optimizations haven't changed. I can remove this if redundant. Jakub also recommended bailing if TREE_OPTIMIZATION_OPTABS already set, thus avoiding recomputing init_all_optabs() in save_optabs_if_changed: + if (TREE_OPTIMIZATION_OPTABS (optnode)) + return; Is this still part of the plan? How is this revision? commit 48c1f4d243f81ca975b2aae34773b91ef6cbd8ca Author: Aldy Hernandez Date: Mon Feb 11 15:51:24 2013 -0600 PR target/52555 * genopinit.c (main): Use this_fn_optabs in generated init_all_optabs. * tree.h (struct tree_optimization_option): New field target_optabs. (TREE_OPTIMIZATION_OPTABS): New. (save_optabs_if_changed): Protoize. * optabs.h: Always declare this_target_optabs. Declare this_fn_optabs. * optabs.c (save_optabs_if_changed): New. Always declare this_target_optabs. Declare this_fn_optabs. * function.c (invoke_set_current_function_hook): Set this_fn_optabs if there is one in the optimization node. c-family/ * c-common.c (handle_optimize_attribute): Call save_optabs_if_changed. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 1e6afaa..3711e69 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -8925,6 +8925,8 @@ handle_optimize_attribute (tree *node, tree name, tree args, DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = build_optimization_node (); + save_optabs_if_changed (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node)); + /* Restore current options. */ cl_optimization_restore (&global_options, &cur_opts); } diff --git a/gcc/function.c b/gcc/function.c index 4ce2259..b177a98 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -4397,7 +4397,16 @@ invoke_set_current_function_hook (tree fndecl) { optimization_current_node = opts; cl_optimization_restore (&global_options, TREE_OPTIMIZATION (opts)); + + /* Change optabs if needed. */ + if (TREE_OPTIMIZATION_OPTABS (opts)) + this_fn_optabs + = (struct target_optabs *) TREE_OPTIMIZATION_OPTABS (opts); + else + this_fn_optabs = this_target_optabs; } + else + this_fn_optabs = &default_target_optabs; targetm.set_current_function (fndecl); } diff --git a/gcc/genopinit.c b/gcc/genopinit.c index 1bb2f77..2a4b3e2 100644 --- a/gcc/genopinit.c +++ b/gcc/genopinit.c @@ -423,7 +423,7 @@ main (int argc, char **argv) fprintf (s_file, "};\n\n"); fprintf (s_file, "void\ninit_all_optabs (void)\n{\n"); - fprintf (s_file, " bool *ena = this_target_optabs->pat_enable;\n"); + fprintf (s_file, " bool *ena = this_fn_optabs->pat_enable;\n"); for (i = 0; patterns.iterate (i, &p); ++i) fprintf (s_file, " ena[%u] = HAVE_%s;\n", i, p->name); fprintf (s_file, "}\n\n"); diff --git a/gcc/optabs.c b/gcc/optabs.c index c1dacf4..e40bb5f 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -44,8 +44,9 @@ along with GCC; see the file COPYING3. If not see struct target_optabs default_target_optabs; struct target_libfuncs default_target_libfuncs; -#if SWITCHABLE_TARGET struct target_optabs *this_target_optabs = &default_target_optabs; +struct target_optabs *this_fn_optabs = &default_target_optabs; +#if SWITCHABLE_TARGET struct target_libfuncs *this_target_libfuncs = &default_target_libfuncs; #endif @@ -6207,6 +6208,40 @@ init_optabs (void) targetm.init_libfuncs (); } +/* Recompute the optabs. If they have changed, save the new set of + optabs in the optimization node OPTNODE. */ + +void +save_optabs_if_changed (tree optnode) +{ + struct target_optabs *save_target_optabs = this_target_optabs; + struct target_optabs *tmp_target_optabs = XCNEW (struct target_optabs); + + /* Generate a new set of optabs into tmp_target_optabs. */ + this_target_optabs = tmp_target_optabs; + init_all_optabs (); + this_target_optabs = save_target_optabs; + + /* If the optabs changed, record it in the node. */ + if (memcmp (tmp_target_optabs, &default_target_optabs, + sizeof (struct target_optabs))) + { + /* ?? An existing entry in TREE_OPTIMIZATION_OPTABS indicates + multiple ((optimize)) attributes for the same function. Is + this even valid? For now, just clobber the existing entry + with the new optabs. */ + if (TREE_OPTIMIZATION_OPTABS (optnode)) + XDELETE (TREE_OPTIMIZATION_OPTABS (optnode)); + + TREE_OPTIMIZATION_OPTABS (optnode) = tmp_target_optabs; + } + else + { + TREE_OPTIMIZATION_OPTABS (optnode) = NULL; + XDELETE (tmp_target_optabs); + } +} + /* A helper function for init_sync_libfuncs. Using the basename BASE, install libfuncs into TAB for BASE_N for 1 <= N <= MAX. */ diff --git a/gcc/optabs.h b/gcc/optabs.h index c08adcf..49908d4 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -76,11 +76,8 @@ struct target_optabs { }; extern struct target_optabs default_target_optabs; -#if SWITCHABLE_TARGET extern struct target_optabs *this_target_optabs; -#else -#define this_target_optabs (&default_target_optabs) -#endif +extern struct target_optabs *this_fn_optabs; /* Define functions given in optabs.c. */ diff --git a/gcc/testsuite/gcc.c-torture/compile/pr52555.c b/gcc/testsuite/gcc.c-torture/compile/pr52555.c new file mode 100644 index 0000000..7016834 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr52555.c @@ -0,0 +1,10 @@ +/* { dg-options "-ffast-math" } */ + +float farg; +unsigned val; + +void __attribute__((optimize("O"))) +test() +{ + val = __builtin_ceilf(farg); +} diff --git a/gcc/tree.h b/gcc/tree.h index c3c814c..eddbca8 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -3586,14 +3586,25 @@ struct GTY(()) tree_optimization_option { /* The optimization options used by the user. */ struct cl_optimization opts; + + /* Target optabs for this set of optimization options. This is of + type `struct target_optabs *'. */ + void *GTY ((skip)) target_optabs; }; #define TREE_OPTIMIZATION(NODE) \ (&OPTIMIZATION_NODE_CHECK (NODE)->optimization.opts) +#define TREE_OPTIMIZATION_OPTABS(NODE) \ + (OPTIMIZATION_NODE_CHECK (NODE)->optimization.target_optabs) + /* Return a tree node that encapsulates the current optimization options. */ extern tree build_optimization_node (void); +/* Save a new set of target_optabs in a TREE_OPTIMIZATION node if the + current set of optabs has changed. */ +extern void save_optabs_if_changed (tree); + /* Target options used by a function. */ struct GTY(()) tree_target_option {