From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 1A37D38207FB for ; Thu, 23 Jun 2022 02:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1A37D38207FB Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25N1MK1H023006; Thu, 23 Jun 2022 02:03:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gvef1rtym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Jun 2022 02:03:11 +0000 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25N1rRj8007349; Thu, 23 Jun 2022 02:03:11 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gvef1rtx3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Jun 2022 02:03:11 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25N1ZCCi023100; Thu, 23 Jun 2022 02:03:08 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma01fra.de.ibm.com with ESMTP id 3gv3j68km9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 23 Jun 2022 02:03:08 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25N236RC14615022 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 23 Jun 2022 02:03:06 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57FDCA404D; Thu, 23 Jun 2022 02:03:06 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87730A4040; Thu, 23 Jun 2022 02:03:04 +0000 (GMT) Received: from [9.197.246.188] (unknown [9.197.246.188]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 23 Jun 2022 02:03:04 +0000 (GMT) Message-ID: <05835d48-50e9-be2c-2b60-1b42e9c6e5d6@linux.ibm.com> Date: Thu, 23 Jun 2022 10:03:03 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: PING^1 [PATCH] inline: Rebuild target option node for caller [PR105459] Content-Language: en-US To: GCC Patches Cc: Jakub Jelinek , Jan Hubicka , Richard Biener , =?UTF-8?Q?Martin_Li=c5=a1ka?= References: <75d4b8f9-5ed2-de4c-d606-510a66714c9a@linux.ibm.com> From: "Kewen.Lin" In-Reply-To: <75d4b8f9-5ed2-de4c-d606-510a66714c9a@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: FaaG9Hqe_WXvluENXhXsbQ4gJlVbFuug X-Proofpoint-ORIG-GUID: 991BJwfRlDr7S_IwMEW_nJ5h1_wb-Qop Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-22_10,2022-06-22_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 adultscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 phishscore=0 clxscore=1015 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206230005 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, 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-List-Received-Date: Thu, 23 Jun 2022 02:03:17 -0000 Hi, Gentle ping https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596212.html BR, Kewen on 2022/6/6 14:20, Kewen.Lin via Gcc-patches wrote: > Hi, > > PR105459 exposes one issue in inline_call handling that when it > decides to copy FP flags from callee to caller and rebuild the > optimization node for caller fndecl, it's possible that the target > option node is also necessary to be rebuilt. Without updating > target option node early, it can make nodes share the same target > option node wrongly, later when we want to unshare it somewhere > (like in target hook) it can get unexpected results, like ICE on > uninitialized secondary member of target globals exposed in this PR. > > Commit r12-3721 makes it get exact fp_expression info and causes > more optimization chances then exposes this issue. Commit r11-5855 > introduces two target options to shadow flag_excess_precision and > flag_unsafe_math_optimizations and shows the need to rebuild target > node in inline_call when optimization node changes. > > As commented in PR105459, I tried to postpone init_function_start > in cgraph_node::expand, but abandoned it since I thought it just > concealed the issue. And I also tried to adjust the target node > when current function switching, but failed since we get the NULL > cfun and fndecl in WPA phase. > > Bootstrapped and regtested on x86_64-redhat-linux, powerpc64-linux-gnu > P8 and powerpc64le-linux-gnu P9. > > Any thoughts? Is it OK for trunk? > > BR, > Kewen > ----- > > PR tree-optimization/105459 > > gcc/ChangeLog: > > * ipa-inline-transform.cc (inline_call): Rebuild target option node > once optimization node gets rebuilt. > > gcc/testsuite/ChangeLog: > > * gcc.dg/lto/pr105459_0.c: New test. > --- > gcc/ipa-inline-transform.cc | 50 +++++++++++++++++++++++++-- > gcc/testsuite/gcc.dg/lto/pr105459_0.c | 35 +++++++++++++++++++ > 2 files changed, 83 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/lto/pr105459_0.c > > diff --git a/gcc/ipa-inline-transform.cc b/gcc/ipa-inline-transform.cc > index 07288e57c73..edba58377f4 100644 > --- a/gcc/ipa-inline-transform.cc > +++ b/gcc/ipa-inline-transform.cc > @@ -52,6 +52,7 @@ along with GCC; see the file COPYING3. If not see > #include "ipa-modref.h" > #include "symtab-thunks.h" > #include "symtab-clones.h" > +#include "target.h" > > int ncalls_inlined; > int nfunctions_inlined; > @@ -469,8 +470,53 @@ inline_call (struct cgraph_edge *e, bool update_original, > } > > /* Reload global optimization flags. */ > - if (reload_optimization_node && DECL_STRUCT_FUNCTION (to->decl) == cfun) > - set_cfun (cfun, true); > + if (reload_optimization_node) > + { > + /* Only need to check and update target option node > + when target_option_default_node is not NULL. */ > + if (target_option_default_node) > + { > + /* Save the current context for optimization and target option > + node. */ > + tree old_optimize > + = build_optimization_node (&global_options, &global_options_set); > + tree old_target_opt > + = build_target_option_node (&global_options, &global_options_set); > + > + /* Restore optimization with new optimizatin node. */ > + tree new_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (to->decl); > + if (old_optimize != new_optimize) > + cl_optimization_restore (&global_options, &global_options_set, > + TREE_OPTIMIZATION (new_optimize)); > + > + /* Restore target option with the one from caller fndecl. */ > + tree cur_target_opt = DECL_FUNCTION_SPECIFIC_TARGET (to->decl); > + if (!cur_target_opt) > + cur_target_opt = target_option_default_node; > + cl_target_option_restore (&global_options, &global_options_set, > + TREE_TARGET_OPTION (cur_target_opt)); > + > + /* Update target option as optimization changes. */ > + targetm.target_option.override (); > + > + /* Rebuild target option node for caller fndecl and replace > + with it if the node changes. */ > + tree new_target_opt > + = build_target_option_node (&global_options, &global_options_set); > + if (cur_target_opt != new_target_opt) > + DECL_FUNCTION_SPECIFIC_TARGET (to->decl) = new_target_opt; > + > + /* Restore the context with previous saved nodes. */ > + if (old_optimize != new_optimize) > + cl_optimization_restore (&global_options, &global_options_set, > + TREE_OPTIMIZATION (old_optimize)); > + cl_target_option_restore (&global_options, &global_options_set, > + TREE_TARGET_OPTION (old_target_opt)); > + } > + > + if (DECL_STRUCT_FUNCTION (to->decl) == cfun) > + set_cfun (cfun, true); > + } > > /* If aliases are involved, redirect edge to the actual destination and > possibly remove the aliases. */ > 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; > +} > -- > 2.27.0