From patchwork Fri Jul 1 13:20:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 55635 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B1AC385E013 for ; Fri, 1 Jul 2022 13:21:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B1AC385E013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1656681682; bh=PlmrUwlG1By32SZokDk6YkHj4Jl9AWyihGHkE5Et/sc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=JNMg9gac5s/nuNLSBsWiWf5Uj5wig+B5nX6uHw2K2Nukln2J1C4Dd33HhSNamVu/r H+ZLLTHtql3dAPTn1hKQdPIw0SFV83TFO4YRRu1+YL6grs1yEovwMql0MvPFdq3hQU Tke2jDLTH7yIAp7o+Hna6K94WhjGmB4FtvEZgwAw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 628063858D28 for ; Fri, 1 Jul 2022 13:20:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 628063858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 328F31FED2; Fri, 1 Jul 2022 13:20:50 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1C0B713484; Fri, 1 Jul 2022 13:20:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mc7bBbL0vmIeRQAAMHmgww (envelope-from ); Fri, 01 Jul 2022 13:20:50 +0000 Date: Fri, 1 Jul 2022 15:20:49 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] target/105459 - allow delayed target option node fixup MIME-Version: 1.0 Message-Id: <20220701132050.1C0B713484@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following avoids the need to massage the target optimization node at WPA time when we fixup the optimization node, copying FP related flags from callee to caller. The target is already set up to fixup, but that only works when not switching between functions. After fixing that the fixup is then done at LTRANS time when materializing the function. Bootstrapped and tested on x86_64-unknown-linux-gnu, ok? Thanks, Richard. 2022-07-01 Richard Biener PR target/105459 * config/i386/i386-options.cc (ix86_set_current_function): Rebuild the target optimization node whenever necessary, not only when the optimization node didn't change. * gcc.dg/lto/pr105459_0.c: New testcase. --- gcc/config/i386/i386-options.cc | 32 ++++++++++-------------- gcc/testsuite/gcc.dg/lto/pr105459_0.c | 35 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/lto/pr105459_0.c diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index e11f68186f5..acb2291e70f 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3232,28 +3232,22 @@ ix86_set_current_function (tree fndecl) if (new_tree == NULL_TREE) new_tree = target_option_default_node; - if (old_tree != new_tree) + bool fp_flag_change + = (flag_unsafe_math_optimizations + != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations + || (flag_excess_precision + != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision)); + if (old_tree != new_tree || fp_flag_change) { cl_target_option_restore (&global_options, &global_options_set, TREE_TARGET_OPTION (new_tree)); - if (TREE_TARGET_GLOBALS (new_tree)) - restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); - else if (new_tree == target_option_default_node) - restore_target_globals (&default_target_globals); - else - TREE_TARGET_GLOBALS (new_tree) = save_target_globals_default_opts (); - } - else if (flag_unsafe_math_optimizations - != TREE_TARGET_OPTION (new_tree)->x_ix86_unsafe_math_optimizations - || (flag_excess_precision - != TREE_TARGET_OPTION (new_tree)->x_ix86_excess_precision)) - { - cl_target_option_restore (&global_options, &global_options_set, - TREE_TARGET_OPTION (new_tree)); - ix86_excess_precision = flag_excess_precision; - ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations; - DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree - = build_target_option_node (&global_options, &global_options_set); + if (fp_flag_change) + { + ix86_excess_precision = flag_excess_precision; + ix86_unsafe_math_optimizations = flag_unsafe_math_optimizations; + DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_tree + = build_target_option_node (&global_options, &global_options_set); + } if (TREE_TARGET_GLOBALS (new_tree)) restore_target_globals (TREE_TARGET_GLOBALS (new_tree)); else if (new_tree == target_option_default_node) diff --git a/gcc/testsuite/gcc.dg/lto/pr105459_0.c b/gcc/testsuite/gcc.dg/lto/pr105459_0.c new file mode 100644 index 00000000000..c799e6ef23d --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr105459_0.c @@ -0,0 +1,35 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { { -flto -O1 } } } */ + +double m; +int n; + +__attribute__ ((optimize ("-funsafe-math-optimizations"))) +void +bar (int x) +{ + n = x; + m = n; +} + +__attribute__ ((flatten)) +void +foo (int x) +{ + bar (x); +} + +void +quux (void) +{ + ++n; +} + +int +main (void) +{ + foo (0); + quux (); + + return 0; +}